安装环境介绍
主机名 | 操作系统 | IP地址 | 环境介绍 |
---|---|---|---|
LB1 | Centos 7.9 | 192.168.8.10 | 负载均衡服务器 |
LB2 | Centos 7.9 | 192.168.8.20 | 负载均衡服务器 |
web1 | Centos 7.9 | 192.168.8.30 | nginx网站服务器 |
web2 | Centos 7.9 | 192.168.8.40 | nginx网站服务器 |
PHP | Centos 7.9 | 192.168.8.50 | php服务器 |
Mysql | Centos 7.9 | 192.168.8.60 | 数据库服务器 |
NFS | Centos 7.9 | 192.168.8.70 | 共享存储服务器 |
分布式部署wordpress的特点
分布式部署LNMP WordPress是将LNMP(Linux、Nginx、MySQL、PHP)环境与WordPress应用程序结合,通过分布式部署的方式在多个节点上运行。
版本介绍
版本介绍 | 版本号 | 发布时间 |
---|---|---|
nginx | 1.24.0 | 2023年4月 |
PHP | 5.4.16 | 2013年5月9日 |
Mysql | 8.0.35 | 2023年10月25日 |
NFS | ||
rpcbind |
安装前准备
关闭防火墙和selinux
备注:所有服务器都需要
[root@localhost ~]#systemctl stop firewalld ; systemctl disable firewalld [root@localhost ~]#setenforce 0 [root@localhost ~]#sed –i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
配置主机名
LB1:
[root@localhost ~]# hostnamectl set-hostname LB1 [root@localhost ~]# bash
LB2:
[root@localhost ~]# hostnamectl set-hostname LB2 [root@localhost ~]# bash
web1:
[root@localhost ~]# hostnamectl set-hostname web1 [root@localhost ~]# bash
web2:
[root@localhost ~]# hostnamectl set-hostname web2 [root@localhost ~]# bash
PHP:
[root@localhost ~]# hostnamectl set-hostname PHP [root@localhost ~]# bash
Mysql:
[root@localhost ~]# hostnamectl set-hostname Mysql [root@localhost ~]# bash
NFS:
[root@localhost ~]# hostnamectl set-hostname NFS [root@localhost ~]# bash
配置yum源
Centos 7.9
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
Centos 9
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
开始安装
安装nginx负载均衡:
LB1:
[root@lb1 ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm [root@lb1 ~]# yum -y install nginx [root@lb1 ~]# systemctl start nginx [root@lb1 ~]# systemctl enable nginx
LB2:
[root@lb2 ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm [root@lb2 ~]# yum -y install nginx [root@lb2 ~]# systemctl start nginx [root@lb2 ~]# systemctl enable nginx
安装web网站:
web1
[root@web1 ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm [root@web1 ~]# yum -y install nginx [root@web1 ~]# systemctl start nginx [root@web1 ~]# systemctl enable nginx
web2:
[root@web2 ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm [root@web2 ~]# yum -y install nginx [root@web2 ~]# systemctl start nginx [root@web2 ~]# systemctl enable nginx
安装PHP
备注:如果访问不了php网站就拖包
PHP:
[root@php ~]# yum -y install epel-release [root@php ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm [root@php ~]# yum install -y php72w php72w-opcache php72w-xml php72w-mcrypt php72w-gd php72w-devel \ php72w-mysql php72w-intl php72w-mbstring [root@php ~]# systemctl start php73-php-fpm
安装NFS:
NFS:
[root@nfs ~]# yum -y install nfs-utils rpcbind [root@nfs ~]# systemctl start nfs rpcbind
搭建wordpress
解压wordpress压缩包到根下
web1:
[root@web1 /]# unzip wordpress-4.9.4-zh_CN.zip [root@web1 /]# chmod -R 777 wordpress [root@web1 /]# vi /etc/nginx/conf.d/wordpress.conf #添加 server { listen 80; server_name blog.benet.com; root /wordpress; index index.php index.html; location ~ \.php$ { root /wordpress; fastcgi_pass 192.168.8.30:9000; #这里IP指向PHP服务器 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } #保存退出 [root@web1 /]# systemctl restart nginx [root@web1 /]# scp -rp /wordpress root@192.168.8.22:/ [root@web1 /]# scp -rp /etc/nginx/conf.d/wordpress.conf root@192.168.8.22:/etc/nginx/conf.d/
web2:
[root@web2 ~]# systemctl restart nginx
连接数据库
备注:如果8.0版本以上不用加密码
mysql:
[root@mysql ~]# grep "password" /var/log/mysqld.log #查看root用户密码 [root@mysql ~]# mysql -uroot -p123123.Com #登录mysql #create database blog; #grant all on blog.* to lisi@‘%’ identified by '123.com';
负载均衡服务器
LB1:
[root@lb1 /]# rm -rf /etc/nginx/conf.d/default.conf [root@lb1 /]# vi /etc/nginx/conf.d/lb1.conf #添加: upstream web_cluster { #定义一个web网站域 server 192.168.8.22:80; server 192.168.8.11:80; } server { listen 80; server_name blog.benet.com; location / { proxy_pass http://web_cluster; #指向web网站域 include nginx_params; #这里指向优化文件 } } [root@lb1 ~]# vi /etc/nginx/nginx_params #添加: proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 30; proxy_send_timeout 60; proxy_read_timeout 60; proxy_buffering on; proxy_buffer_size 32k; proxy_buffers 4 128k; [root@lb1 /]# systemctl restart nginx
LB2:
[root@lb2 /]# rm -rf /etc/nginx/conf.d/default.conf [root@lb2 /]# vi /etc/nginx/conf.d/lb1.conf #添加: upstream web_cluster { #定义一个web网站域 server 192.168.8.22:80; server 192.168.8.11:80; } server { listen 80; server_name blog.benet.com; location / { proxy_pass http://web_cluster; #指向web网站域 include nginx_params; #这里指向优化文件 } } [root@lb2 ~]# vi /etc/nginx/nginx_params #添加: proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 30; proxy_send_timeout 60; proxy_read_timeout 60; proxy_buffering on; proxy_buffer_size 32k; proxy_buffers 4 128k; [root@lb2 /]# systemctl restart nginx
PHP服务器
PHP:
vim /etc/php-fpm.d/www.conf #定位并修改为: listen = 192.168.8.30:9000 listen.allowed_clients = 192.168.8.11,192.168.8.22 #保存退出 #重启php: systemctl restart php-fpm #从nginx服务器复制wordpress安装目录到php服务器 scp -rp /wordpress root@192.168.8.30:/
NFS服务器
NFS:
[root@nfs ~]# mkdir -p /nfs [root@nfs ~]# vi /etc/exports #添加: /nfs/blog 192.168.8.0/24(rw,sync,no_root_squash) 保存退出 [root@nfs ~]# systemctl restart rpcbind [root@nfs ~]# systemctl restart nfs #客户端: vim /etc/fstab #添加: 192.168.8.40:/nfs/log /wordpress/wp-content nfs defaults,_netdev 0 0 保存退出