1.回顾
yum安装wordpress
查看别名
[root@localhost ~]# type ll
ll 是 `ls -l --color=auto' 的别名设置别名
aliasyum install -y alias ym='yum install -y'# 使用别名
ym nginx# 取消别名
unalias ym# 基于LNMP做一个wordpressnginx
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.shsh 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
剧本分析
代码麻一麻
---
- name: Doply wordpressremote_user: rootgather_facts: nohosts: databases,webservervars:MYSQL_DB_NAME: wordpressMYSQL_USER: wordpressMYSQL_PASSWORD: "Qwertyuiop@123"MYSQL_HOST: "%"NGINX_PORT: 80BASE_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,nginxtasks:- name: Install MySQLyum:name: mysql-serverstate: presentwhen: inventory_hostname in groups.databases- name: Start and enable MySQLservice: name: mysqldstate: startedenabled: yeswhen: 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 databaseshell: 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: createwhen: 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 nginxyum:name: "{{ PACKAGE }}"state: presentwhen: inventory_hostname in groups.webserver- name: Config Nginxtemplate: src: ./nginx.conf dest: /etc/nginx/nginx.confwhen: inventory_hostname in groups.webserver- name: Start php and nginxservice:name: "{{ item }}"state: startedenabled: yeswith_items:- nginx- php80-php-fpmwhen: inventory_hostname in groups.webservertags: startnp- name: Config PHPfile:path: /var/opt/remi/php80/run/php-fpm/www.sockmode: "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 webunarchive: src: /opt/latest-zh_CN.zipdest: "{{ BASE_DIR }}"mode: "777"when: inventory_hostname in groups.webservertags: 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用户和普通用户设置密码,必须是强密码,关闭密码强度策略后才能设置弱密码。
unarchive模块:解压文件并复制到指定目录,要求被控主机上安装相应的解压工具