小结
部署web01,web02,nfs,db01,backup,搭建wordpress,WeCenter,实现共享,热备,实时备份
1)在web01和web02上安装nginx和php
2)创建www用户
[root@web01 php]# groupadd www -g 666
[root@web01 php]# useradd www -u 666 -g 666 -s /sbin/nologin -M
[root@web02 php]# groupadd www -g 666
[root@web02 php]# useradd www -u 666 -g 666 -s /sbin/nologin -M
[root@nfs ~]# groupadd www -g 666
[root@nfs ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M
[root@db01 ~]# groupadd www -g 666
[root@db01 ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M
[root@backup ~]# groupadd www -g 666
[root@backup ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M
3)修改nginx和PHP启动用户
[root@web01 php]# vim /etc/nginx/nginx.conf
user www;
[root@web01 php]# vim /etc/php-fpm.d/www.conf
user = www
group = www
[root@web02 php]# vim /etc/nginx/nginx.conf
user www;
[root@web02 php]# vim /etc/php-fpm.d/www.conf
user = www
group = www
4)编辑nginx配置文件
[root@web01 php]# vim /etc/nginx/conf.d/blog.drz.com.conf
server {
listen 80;
server_name blog.drz.com;
root /code/wordpress;
index index.php index.html;
access_log /var/log/nginx/blog.drz.com_access.log main;
location ~\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
[root@web01 php]# vim /etc/nginx/conf.d/zh.drz.com.conf
server {
listen 80;
server_name zh.drz.com;
root /code/zh;
index index.php index.html;
access_log /var/log/nginx/zh.drz.com_access.log main;
location ~\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
5)创建站点目录并授权
[root@web01 php]# mkdir -p /code/{wordpress,zh}
6)代码上线
[root@web01 code]# tar xf wordpress-5.0.3-zh_CN.tar.gz
[root@web01 code]# unzip WeCenter_3-3-3.zip
7)创建出用户上传目录
[root@web01 code]# mkdir /code/wordpress/wp-content/uploads
[root@web01 php]# chown -R www.www /code/
8)启动nginx和php并加入开机自启
[root@web01 code]# systemctl start nginx php-fpm
[root@web01 code]# systemctl enable nginx php-fpm
db01下操作
9)安装数据库
[root@db01 ~]# yum install -y mariadb-server
10)启动数据库
[root@db01 ~]# systemctl start mariadb
11)设置数据库root用户的密码
[root@db01 ~]# mysqladmin -uroot password '123'
12)免交互创建数据库
#创建数据库
[root@db01 ~]# mysqladmin -uroot -p123 create wordpress
[root@db01 ~]# mysql -uroot -p123 -e 'create database zh'
#查看数据库
[root@db01 ~]# mysql -uroot -p123 -e 'show databases'
13)免交互创建程序连接MySQL用户
[root@db01 ~]# mysql -uroot -p123 -e "grant all on wordpress.* to wp@'172.16.1.%' identified by '1'"
[root@db01 ~]# mysql -uroot -p123 -e "grant all on zh.* to zh@'172.16.1.%' identified by '1'"
14)部署第二台web
#推送代码
[root@web01 code]# scp -r /code 172.16.1.8:/
#推送配置文件
[root@web01 ~]# scp /etc/nginx/conf.d/* 172.16.1.8:/etc/nginx/conf.d/
#授权
[root@web02 php]# chown -R www.www /code/
#删除默认虚拟主机配置文件
[root@web01 ~]# rm -f /etc/nginx/conf.d/default.conf
[root@web02 php]# rm -f /etc/nginx/conf.d/default.conf
#启动nginx和php并加入开机自启
[root@web02 php]# systemctl start nginx php-fpm
[root@web02 php]# systemctl enable nginx php-fpm
15)共享静态资源
- 安装nfs服务端
[root@nfs ~]# yum install -y nfs-utils
[root@backup ~]# yum install -y nfs-utils
- 修改配置文件
[root@nfs ~]# vim /etc/exports
/data/wordpress 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
/data/zh 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
[root@backup ~]# vim /etc/exports
/data/wordpress 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
/data/zh 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
- 创建共享目录
[root@nfs ~]# mkdir -p /data/{wordpress,zh}
[root@nfs ~]# chown -R www.www /data
[root@backup ~]# mkdir -p /data/{wordpress,zh}
[root@backup ~]# chown -R www.www /data
- 启动nfs和rpcbind
[root@nfs ~]# systemctl start nfs-server
[root@nfs ~]# systemctl enable nfs-server
[root@backup ~]# systemctl start nfs-server
[root@backup ~]# systemctl enable nfs-server
- 安装nfs客户端
[root@web01 code]# yum install -y nfs-utils
[root@web02 php]# yum install -y nfs-utils
- 查看挂载点
[root@web01 code]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data/zh 172.16.1.0/24
/data/wordpress 172.16.1.0/24
[root@web01 code]# showmount -e 172.16.1.41
Export list for 172.16.1.41:
/data/zh 172.16.1.0/24
/data/wordpress 172.16.1.0/24
[root@web02 php]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data/zh 172.16.1.0/24
/data/wordpress 172.16.1.0/24
[root@web02 php]# showmount -e 172.16.1.41
Export list for 172.16.1.41:
/data/zh 172.16.1.0/24
/data/wordpress 172.16.1.0/24
- 挂载
mkdir /code/wordpress/wp-content/uploads/
mkdir /code/zh/uploads/ 没传图片之前的自己创建目录
[root@web01 code]# mount -t nfs 172.16.1.31:/data/wordpress /code/wordpress/wp-content/uploads/
[root@web01 code]# mount -t nfs 172.16.1.31:/data/zh /code/zh/uploads/
[root@web02 php]# mount -t nfs 172.16.1.31:/data/wordpress /code/wordpress/wp-content/uploads/
[root@web02 php]# mount -t nfs 172.16.1.31:/data/zh /code/zh/uploads/
16)部署rsync和sersync
- 安装rsync服务端
[root@backup ~]# yum install -y rsync
- 修改配置文件
[root@backup ~]# vim /etc/rsyncd.conf
uid = www
gid = www
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
ignore errors
read only = false
list = false
auth users = rc
secrets file = /etc/rsync.passwd
log file = /var/log/rsyncd.log
#####################################
[nfs]
comment = welcome to oldboyedu backup!
path = /data
- 创建密码文件并授权
[root@backup ~]# echo 'rc:123' > /etc/rsync.passwd
[root@backup ~]# chmod 600 /etc/rsync.passwd
- 启动rsyncd
[root@backup ~]# systemctl start rsyncd
17)客户端部署sersync
- 安装rsync和inotify-tools
[root@nfs ~]# yum install -y rsync inotify-tools
- 安装sersync
[root@nfs ~]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs ~]# mv GNU-Linux-x86/ /usr/local/sersync
- 修改配置文件
[root@nfs ~]# vim /usr/local/sersync/confxml.xml
- 创建密码文件并授权
[root@nfs ~]# echo 123 > /etc/rsync.pass
[root@nfs ~]# chmod 600 /etc/rsync.pass
- 启动sersync
[root@nfs ~]# /usr/local/sersync/sersync2 -rdo /usr/local/sersync/confxml.xml