ansible安装wordpress

1.回顾

yum安装wordpress

查看别名
[root@localhost ~]# type ll
ll 是 `ls -l --color=auto' 的别名

设置别名
alias

yum install -y 

alias ym='yum install -y'

# 使用别名
ym nginx

# 取消别名
unalias ym


# 基于LNMP做一个wordpress

nginx
mysql 5.7
PHP 7.4+

#1、初始化过程
修改主机名
hostnamectl set-hostname $name

关闭防火墙及selinux
systemctl stop firewalld 
systemctl disable firewalld
setenforce 0

配置本地yum源
curl -o yum-server.sh http://10.36.178.78/yum-server.sh

sh yum-server.sh

安装工具
yum install -y vim wget unzip

#2、安装Nginx服务
yum install -y nginx

启动nginx服务
systemctl start nginx

#3、安装数据库
yum install -y mysql-server

启动数据库
systemctl start mysqld

获取数据库初始化密码
grep "password" /var/log/mysqld.log

修改数据库密码
mysqladmin -uroot -p'$获取的初始化密码' password '$new_password'

创建数据库:wordpress
mysql -uroot -p'$new_password' -e 'create database wordpress'

#4、安装php
yum install php80-php-xsl php80-php php80-php-cli php80-php-devel php80-php-gd php80-php-pdo php80-php-mysql php80-php-fpm -y

启动php
systemctl start php80-php-fpm

#5、修改nginx配置文件
/etc/nginx/nginx.conf

#6、重启nginx
systemctl restart nginx

#7、上传wordpress包到服务器

#8、解压上传的wordpress压缩包
unzip wordpress-6.5.2-zh_CN.zip

#9、清理nginx网站发布目录下的所有资源
rm -rf /usr/share/nginx/html/*

#10、拷贝wordpree目录中的所有资源到/usr/share/nginx/html/
cp wordpress/* /usr/share/nginx/html/

#11、修改html目录权限
chmod -R 777 /usr/share/nginx/html/

#12、浏览器访问服务器ip,在浏览器中进行部署

2.ansible安装wordpress

剧本分析

image-20240612204736404

代码麻一麻

---
- name: Doply wordpress
  remote_user: root
  gather_facts: no
  hosts: databases,webserver
  vars:
    MYSQL_DB_NAME: wordpress
    MYSQL_USER: wordpress
    MYSQL_PASSWORD: "Qwertyuiop@123"
    MYSQL_HOST: "%"
    NGINX_PORT: 80
    BASE_DIR: /usr/share/nginx/
    PACKAGE: php80-php-xsl,php80-php,php80-php-cli,php80-php-devel,php80-php-gd,php80-php-pdo,php80-php-mysql,php80-php-fpm,nginx
  tasks:
  - name: Install MySQL
    yum:
      name:  mysql-server
      state: present
    when: inventory_hostname in groups.databases
  
  - name: Start and enable MySQL
    service: 
      name: mysqld
      state: started
      enabled: yes
    when: inventory_hostname in groups.databases
  
  - name: INIT MySQL passwd  
    shell: mysqladmin -p"`awk '/temporary password /{print $NF}' /var/log/mysqld.log`" password "Qq111111."
    when: inventory_hostname in groups.databases
    
  - name: Create MySQL database
    shell: mysql -p'Qq111111.' -e "CREATE DATABASE if not exists {{ MYSQL_DB_NAME }};create user '{{ MYSQL_USER }}'@'{{ MYSQL_HOST }}' identified by '{{ MYSQL_PASSWORD }}';grant all privileges on {{ MYSQL_DB_NAME }}.* to '{{ MYSQL_USER }}'@'{{ MYSQL_HOST }}';flush privileges;"
    tags: create
    when: inventory_hostname in groups.databases
    #- name: Install PHP packages and epel-release
    ##yum: name={{ item }} state=present disable_gpg_check=yes
    ##with_items:
    ##- epel-release
    ##- http://rpms.remirepo.net/enterprise/remi-release-9.rpm
    ##when: name == "web"
  - name: Install PHP and nginx
    yum:
      name: "{{ PACKAGE }}"
      state: present
    when: inventory_hostname in groups.webserver

  - name: Config Nginx
    template: 
      src: ./nginx.conf 
      dest: /etc/nginx/nginx.conf
    when: inventory_hostname in groups.webserver
  
  - name: Start php and nginx
    service:
      name: "{{ item }}"
      state: started
      enabled: yes
    with_items:
      - nginx
      - php80-php-fpm
    when: inventory_hostname in groups.webserver
    tags: startnp

  
  - name: Config PHP
    file:
      path: /var/opt/remi/php80/run/php-fpm/www.sock
      mode: "777"
    tags: cfp 
    when: inventory_hostname in groups.webserver
#  - name: Restart php nginx
#    service:
#      name: "{{ item }}"
#      state: restarted
#    with_items:
#      - nginx
#      - php80-php-fpm
#    tags: rnp
#    when: inventory_hostname in groups.webserver
#
  - name: Cp Wordpress to web
    unarchive: 
      src: /opt/latest-zh_CN.zip
      dest: "{{ BASE_DIR }}"
      mode: "777"
    when: inventory_hostname in groups.webserver
    tags: cpwp

准备nginx配置文件

    server {
        listen       {{ NGINX_PORT | default(80) }};
        listen       [::]:{{ NGINX_PORT | default(80) }};
        server_name  _;
        root    {{ BASE_DIR }}/wordpress;   # /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
# server里面需要添加的内容
        location / {
            root   {{ BASE_DIR }}/wordpress;
            index index.php;
        }
        location ~ \.php$ {
        			# /usr/share/nginx/html; 指定网站目录
            root     {{ BASE_DIR }}/wordpress;
            	·	      # 指定访问地址(旧版为:127.0.0.1:9000)
            fastcgi_pass  unix:///var/opt/remi/php80/run/php-fpm/www.sock; 
            			  # 指定默认访问的文件
            fastcgi_index  index.php;
            							# 站点根目录,取决于root配置项
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
            include        fastcgi_params;  #包含nginx常量定义
                }
        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }

小问题

mysql80为root用户和普通用户设置密码,必须是强密码,关闭密码强度策略后才能设置弱密码。

image-20240612203627628

unarchive模块:解压文件并复制到指定目录,要求被控主机上安装相应的解压工具

365589bea38f7150efa4b188bc7fddf

wordpress点点点安装

image-20240612204005705

image-20240612204033185

image-20240612204212189

image-20240612204319076

image-20240612204340418

image-20240612204406702

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值