LNMP部署Wordpress网站

本文详细介绍了如何在四台服务器上进行LNMP(Nginx、PHP、MySQL主从)的分布式部署,并成功发布WordPress网站。首先在A服务器上安装Nginx,B服务器上安装PHP,C/D服务器上配置MySQL主从。然后通过rsync同步文件,设置权限,最后在C服务器创建数据库并授权,D服务器进行从库同步。整个过程涉及网络、系统配置、数据库管理和网站发布等关键步骤。
摘要由CSDN通过智能技术生成

基于四台虚拟机分离部署lnmp环境部署,发布一套网站wordpress。其中一台服务器部署nginx,一台部署PHP,其余两台部署MySQL主从。

基于四台服务器实现lnmp分离部署,A服务器部署nginx,B服务器部署php,C/D服务器部署MySQL主从 。
A服务器(nginx):10.75.65.103
B服务器(php):10.75.65.104
C服务器(master):10.75.65.105
D服务器(slave):10.75.65.106

A服务器(nginx)10.75.65.103部署Nginx:
yum install zlib zlib-devel gcc gcc-c++ openssl openssl-devel pcre pcre-devel -y
wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar -xzvf nginx-1.16.0.tar.gz
cd nginx-1.16.0
useradd nginx -s /sbin/nologin
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
上传网站代码并解压缩到nginx发布目录:
tar xvf wordpress-4.9.4-zh_CN.tar.gz -C /usr/local/nginx/html/
chown nginx. -R /usr/share/nginx/html/
上传wordpress网站代码并解压到nginx发布目录:
tar xvf wordpress-4.9.4-zh_CN.tar.gz -C /usr/local/nginx/html/
chown nginx. -R /usr/local/nginx/html/wordpress/

#创建wordpress虚拟主机:
指定应用的虚拟主机目录(主配置文件http指令块下添加):
include vhost/*.conf;
#创建虚拟主机目录:
mkdir -p /usr/local/nginx/conf/vhost
#创建虚拟主机配置文件:
vim /usr/local/nginx/conf/vhost/blog.wordpress.com.conf

server {
        listen       80;
        server_name wp.jjx.com;
        #charset koi8-r;
        access_log  logs/wordpress.access.log  main;
        location / {
            root   html/wordpress;
            index  index.php  index.html index.htm;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #error_page   500 502 503 504  /50x.html;
        location = /50x.html {
                root   html;
        }
        location ~ \.php$ {
            root           /data/wordpress;
            fastcgi_pass   10.75.65.104:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
}

启动nginx服务:/usr/local/nginx/sbin/nginx

B服务器(php)10.75.65.104安装PHP:
安装依赖:
yum -y install gd curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel
关闭防火墙并禁用开机启动:
systemctl stop firewalld
systemctl disable firewalld
上传源码包并解压缩:
tar xf php-5.6.8.tar.bz2
cd php-5.6.8
预编译:
./configure --prefix=/usr/local/php
–enable-fpm
–enable-debug
–with-gd
–with-jpeg-dir
–with-png-dir
–with-freetype-dir
–enable-mbstring
–with-curl
–with-mysql=mysqlnd
–with-mysqli=mysqlnd
–with-pdo-mysql=mysqlnd
–with-config-file-path=/usr/local/php/etc
–with-zlib-dir
#编译/安装
make && make install
cp php.ini-development /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

#修改php-fpm的用户为nginx:
[root@node4 html]# egrep “^(user|group)” /usr/local/php/etc/php-fpm.conf
user = nginx
group = nginx

#启动php-fpm:
/etc/init.d/php-fpm start
配置php远程服务器网站资源:
mkdir -p /data/
在A服务器同步目录到B服务器:
rsync -av /usr/share/nginx/html/wordpress 192.168.75.134:/data/

访问nginx:要数据库连接信息,但是现在还没有配置数据库,所以需要先配置数据库。
在这里插入图片描述

C/D服务器(Mariadb)10.75.65.105/106部署Mariadb,C主D从:
主库和从库均执行以下命令:
yum install mariadb mariadb-server mariadb-devel -y

C服务器:
关闭防火墙并禁用开机启动:
systemctl stop firewalld
systemctl disable firewalld
vim /etc/my.cnf
log-bin=jjx-bin
server-id=1
systemctl start mariadb
进入数据库授权从库

MariaDB [(none)]> grant replication slave on *.* to "tongbu"@"10.75.65.106" identified by "tb123456";
MariaDB [(none)]> flush privileges;
创建wordpress数据库:
MariaDB [(none)]> create database wordpress charset utf8;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on wordpress.* to "wordpress"@"10.75.65.104" identified by "wp123456";
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

D服务器:
vim /etc/my.cnf
server-id=2
systemctl start mariadb
进入数据进行同步:
mysql -p
MariaDB [(none)]>change master to master_host=“10.75.65.105”, master_user=“tongbu”, master_password=“tb123456”, master_log_file=“jjx-bin.000001”, master_log_pos=477;
执行show slave status\G,能看到以下状态表示互为主从搭建成功!
start slave;
show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

配置wordpress数据库:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

wordpress部署成功:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值