LB | 192.168.200.120 |
web-01 | 192.168.200.121 |
web-02 | 192.168.200.122 |
mysql | 192.168.200.127 |
nfs | 192.168.200.150 |
web-01安装nginx、php、wordpress
- 准备官方源
[root@nginx ~]# cat > /etc/yum.repos.d/nginx.repo << OK
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=0
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
OK
[root@nginx ~]# cat > /etc/yum.repos.d/php.repo << OK
[webtatic-php]
name = php Repository
baseurl = http://us-east.repo.webtatic.com/yum/el7/x86_64/
gpgcheck = 0
OK
- 安装nginx、php
[root@nginx ~]# yum -y install nginx
[root@nginx ~]# yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
[root@nginx ~]# systemctl enable nginx php-fpm.service
- 安装wordpress
[root@nginx code]# mkdir /code
[root@nginx code]# cd /code/
[root@nginx code]# tar xf wordpress-4.7.4-zh_CN.tar.gz
[root@nginx code]# ls
wordpress wordpress-4.7.4-zh_CN.tar.gz
- 修改nginx的配置文件
[root@nginx code]# cd /etc/nginx/conf.d/
[root@nginx conf.d]# mv default.conf{,.bak}
[root@nginx conf.d]# vim wordpress.conf
server {
listen 80;
server_name www.proxy-wordpress.org;
root /code/wordpress;
client_max_body_size 100m;
set_real_ip_from 192.168.200.120;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
location / {
index index.php;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
[root@nginx conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
- 修改目录权限
[root@nginx conf.d]# groupadd -g666 www
[root@nginx conf.d]# useradd -u666 -g666 www
[root@nginx conf.d]# id www
uid=666(www) gid=666(www) groups=666(www)
[root@nginx conf.d]# chown -R www.www /code/
- 修改nginx、php用户
[root@nginx conf.d]# sed -i '/^user/c user www;' /etc/nginx/nginx.conf
[root@nginx conf.d]# sed -i '/^user/c user = www' /etc/php-fpm.d/www.conf
[root@nginx conf.d]# sed -i '/^group/c group = www' /etc/php-fpm.d/www.conf
- 查看配置是否有错
[root@nginx conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@nginx conf.d]# php-fpm -t
[09-Jun-2023 15:06:04] NOTICE: configuration file /etc/php-fpm.conf test is successful
- 启动nginx、php
[root@nginx conf.d]# systemctl start nginx
[root@nginx conf.d]# systemctl start php-fpm.service
[root@nginx conf.d]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2463/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1389/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2017/master
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2488/php-fpm: maste
tcp6 0 0 :::22 :::* LISTEN 1389/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2017/master
- 查看服务用户是否为www
[root@nginx conf.d]# ps -ef | grep nginx
root 2463 1 0 15:07 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
www 2464 2463 0 15:07 ? 00:00:00 nginx: worker process
root 2496 2092 0 15:08 pts/0 00:00:00 grep --color=auto nginx
[root@nginx conf.d]# ps -ef | grep php
root 2488 1 0 15:07 ? 00:00:00 php-fpm: master process (/etc/php-fpm.conf)
www 2489 2488 0 15:07 ? 00:00:00 php-fpm: pool www
www 2490 2488 0 15:07 ? 00:00:00 php-fpm: pool www
www 2491 2488 0 15:07 ? 00:00:00 php-fpm: pool www
www 2492 2488 0 15:07 ? 00:00:00 php-fpm: pool www
www 2493 2488 0 15:07 ? 00:00:00 php-fpm: pool www
root 2498 2092 0 15:08 pts/0 00:00:00 grep --color=auto php
web-02安装nginx、php、wordpress(跟web-01过程相同)
[root@nginx session]# scp -rp /etc/nginx/nginx.conf root@192.168.200.122:/etc/nginx/nginx.conf
root@192.168.200.122's password:
nginx.conf 100% 645 0.6KB/s 00:00
[root@nginx session]# scp -rp /etc/nginx/conf.d/wordpress.conf root@192.168.200.122:/etc/nginx/conf.d/wordpress.conf
root@192.168.200.122's password:
wordpress.conf 100% 452 0.4KB/s 00:00
[root@nginx session]# scp -rp /etc/php-fpm.d/www.conf root@192.168.200.122:/etc/php-fpm.d/www.conf
root@192.168.200.122's password:
www.conf
[root@nginx session]# scp -rp /code/wordpress root@192.168.200.122:/code
[root@nginx conf.d]# groupadd -g666 www
[root@nginx conf.d]# useradd -u666 -g666 www
[root@nginx conf.d]# id www
uid=666(www) gid=666(www) groups=666(www)
[root@nginx conf.d]# chown -R www.www /code/
安装mysql(192.168.200.127)
[root@mysql-master ~]# yum -y install mariadb-server.x86_64 mariadb
[root@mysql-master ~]# systemctl start mariadb.service
[root@mysql-master ~]# systemctl enable mariadb.service
- 设置数据库登录密码、创建远程登陆用户、创建wordpress库
MariaDB [(none)]> grant all on *.* to word@'192.168.200.%' identified by '111111';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| wordpress |
+--------------------+
5 rows in set (0.00 sec)
安装配置LB(192.168.200.120)
[root@nginx conf.d]# vim wordpress.conf
upstream word {
server 192.168.200.121:80;
server 192.168.200.122:80;
}
server {
listen 80;
server_name www.proxy-wordpress.org;
location / {
proxy_pass http://word;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
[root@nginx conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@nginx conf.d]# systemctl start nginx
- 访问测试
- 查看nginx日志是否负载成功(web-01)
- 查看nginx日志是否负载成功(web-02)
安装nfs共享存储(192.168.200.150)
[root@localhost ~]# yum -y install nfs-utils.x86_64
[root@localhost ~]# groupadd -g666 www
[root@localhost ~]# useradd -u666 -g666 www
[root@localhost ~]# mkdir -p /code/wordpress
[root@localhost ~]# chown -R www.www /code/
[root@localhost ~]# vim /etc/exports
/code/wordpress 192.168.200.0/24(rw,async,all_squash,anonuid=666,anongid=666)
[root@localhost ~]# systemctl start nfs
web服务测试nfs共享目录是否成功(挂载、加入开机自动挂载)
[root@nginx conf.d]# showmount -e 192.168.200.150
Export list for 192.168.200.150:
/code/wordpress 192.168.200.0/24
[root@nginx wp-content]# mkdir /code/wordpress/wp-content/uploads
[root@nginx wp-content]# chown -R www.www uploads/
[root@nginx wp-content]# mount -t nfs 192.168.200.150:/code/wordpress /code/wordpress/wp-content/uploads/
[root@nginx wp-content]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 17G 2.1G 15G 13% /
devtmpfs 902M 0 902M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 8.5M 904M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 1014M 139M 876M 14% /boot
tmpfs 183M 0 183M 0% /run/user/0
192.168.200.150:/code/wordpress 17G 1.6G 16G 10% /code/wordpress/wp-content/uploads
[root@nginx wp-content]# vim /etc/fstab
192.168.200.150:/code/wordpress /code/wordpress/wp-content/uploads nfs defaults 0 0
浏览器测试访问
测试图片上传
[root@localhost ~]# ls /code/wordpress/2023/06/
remi-jacquaint-0uoz5nC-guM-unsplash-100x100.jpg remi-jacquaint-0uoz5nC-guM-unsplash-300x200.jpg
remi-jacquaint-0uoz5nC-guM-unsplash-1024x683.jpg remi-jacquaint-0uoz5nC-guM-unsplash-768x512.jpg
remi-jacquaint-0uoz5nC-guM-unsplash-150x150.jpg remi-jacquaint-0uoz5nC-guM-unsplash.jpg
remi-jacquaint-0uoz5nC-guM-unsplash-2000x1200.jpg
[root@nginx wordpress]# ls /code/wordpress/wp-content/uploads/2023/06/
remi-jacquaint-0uoz5nC-guM-unsplash-100x100.jpg remi-jacquaint-0uoz5nC-guM-unsplash-300x200.jpg
remi-jacquaint-0uoz5nC-guM-unsplash-1024x683.jpg remi-jacquaint-0uoz5nC-guM-unsplash-768x512.jpg
remi-jacquaint-0uoz5nC-guM-unsplash-150x150.jpg remi-jacquaint-0uoz5nC-guM-unsplash.jpg
remi-jacquaint-0uoz5nC-guM-unsplash-2000x1200.jpg