LNMP+NFS文件共享集群架构发布Discuz与WorPress

一、实验所需服务器

ps:做实验先关防火墙
[root@localhost ~]# systemctl stop firewalld.service

1、192.168.1.112 Nginx WEB前端
2、192.168.1.120 PHP-fpm+NFS 文件共享服务器
3、192.168.1.121 PHP-fpm服务器
4、192.168.1.117 主数据库
5、192.168.1.118 主数据库

二、部署NFS文件共享服务器

1.使用YUM安装NFS文件共享服务器

[root@localhost ~]# yum install nfs-utils rpcbind -y

2.创建共享文件目录

[root@localhost home]# mkdir -p /data/html

3.修改配置文件

[root@localhost home]# vim /etc/exports
添加
/data/html  *(rw,no_root_squash,no_all_squash,sync)

4.启动NFS服务

[root@localhost home]# systemctl start nfs
[root@localhost home]# systemctl status nfs   #查看运行状态

5.热加载配置文件

[root@localhost home]# exportfs -r

6.关闭NFS文件共享服务器防火墙

[root@localhost home]# systemctl stop firewalld

7.使用Nginx WEB前端服务器,挂载访问NFS文件共享服务器

[root@localhost ~]# mount -t nfs 192.168.1.120:/data/html /mnt

三、Nginx WEB前端配置

1、实验所需服务器
①、192.168.1.112 Nginx WEB前端
②、192.168.1.120 NFS 文件共享服务器
2.安装配置 Nginx
①、先关闭CentOS系统防火墙

[root@localhost nginx-1.14.0]# systemctl stop firewalld

②、安装PCRE库和基础库支持

[root@localhost ~]# yum install pcre-devel pcre gcc-c++ openssl openssl-devel zlib-devel -y

③、下载nginx-1.14.0源码包

[root@localhost ~]# wget -c http://nginx.org/download/nginx-1.14.0.tar.gz

④、解压nginx-1.14.0源码包,并创建服务用户

[root@localhost ~]# tar -xzf nginx-1.14.0.tar.gz
[root@localhost ~]# useradd -s /sbin/nologin nginx

⑤、进入nginx-1.14.0,进行预编译

[root@localhost ~]# cd nginx-1.14.0
[root@localhost nginx-1.14.0]# ./configure 
--user=nginx 
--group=nginx 
--prefix=/data/nginx 
--with-http_stub_status_module 
--with-http_ssl_module

⑥、编译与编译安装

[root@localhost nginx-1.14.0]# make && make install

⑦、检查nginx配置文件是否正确

[root@localhost nginx-1.14.0]# /data/nginx/sbin/nginx -t
nginx: the configuration file /data/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /data/nginx/conf/nginx.conf test is successful

⑧、启动nginx,进行测试

[root@localhost nginx-1.14.0]# /data/nginx/sbin/nginx

⑧、测试成功后,清空 /data/nginx/html 里的文件

[root@localhost html]# rm -rf *

四、MySQL主主集群

1、实验所需服务器
①、192.168.1.117 主数据库
②、192.168.1.118 从数据库
2、关闭防火墙

[root@localhost ~]# systemctl stop firewalld.service

3、安装编译需要的依赖

[root@localhost ~]# yum install cmake ncurses-devel ncurses libaio bison git gcc-c++ -y

4、下载MySQL-5.5.20源码包

[root@localhost ~]# wget -c http://down1.chinaunix.net/distfiles/mysql-5.5.20.tar.gz

5、解压MySQL-5.5.20源码包

[root@localhost ~]# tar -xzf mysql-5.5.20.tar.gz

6、进入MySQL-5.5.20,进行预编译

[root@localhost ~]# cd mysql-5.5.20
[root@localhost mysql-5.5.20]# cmake . 
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql55 \
> -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
> -DMYSQL_DATADIR=/data/mysql \
> -DSYSCONFDIR=/etc \
> -DMYSQL_USER=mysql \
> -DMYSQL_TCP_PORT=3306 \
> -DWITH_XTRADB_STORAGE_ENGINE=1 \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DWITH_PARTITION_STORAGE_ENGINE=1 \
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
> -DWITH_MYISAM_STORAGE_ENGINE=1 \
> -DWITH_READLINE=1 \
> -DENABLED_LOCAL_INFILE=1 \
> -DWITH_EXTRA_CHARSETS=1 \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DEXTRA_CHARSETS=all \
> -DWITH_BIG_TABLES=1 \
> -DWITH_DEBUG=0 \
> -DENABLE_DTRACE=0

7、编辑MySQL文件权限与配置文件,并启动

[root@localhost mysql-5.5.20]# cd /usr/local/mysql55
[root@localhost mysql55]# \cp -f support-files/my-large.cnf /etc/my.cnf
[root@localhost mysql55]# \cp -f support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql55]# chkconfig --add mysqld
[root@localhost mysql55]# chkconfig --level 35 mysqld on
[root@localhost mysql55]# mkdir -p /data/mysql
[root@localhost mysql55]# useradd -s /sbin/nologin mysql
[root@localhost mysql55]# /usr/local/mysql55/scripts/mysql_install_db --user=mysql --datadir=/data/mysql/ --basedir=/usr/local/mysql55/
[root@localhost mysql55]# ln -s /usr/local/mysql55/bin/* /usr/bin/
[root@localhost mysql55]# service mysqld start

8、配置两台 MySQL 数据库服务器配置文件/etc/my.cnf

1️⃣192.168.1.117 主数据库
[client]
port		= 3306
socket		= /tmp/mysql.sock

[mysqld]
port		= 3306
socket		= /tmp/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
thread_concurrency = 8
log-bin=mysql-bin
binlog_format=mixed
server-id	= 1   #修改这里


[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
2️⃣192.168.1.118 主数据库
[client]
port		= 3306
socket		= /tmp/mysql.sock

[mysqld]
port		= 3306
socket		= /tmp/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
thread_concurrency = 8
log-bin=mysql-bin
binlog_format=mixed
server-id	= 2   #修改这里

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

9、重启 MySQL 数据库

[root@www ~]# systemctl restart mysql

10、主从同步配置
①、创建主数据库连接账户

[root@localhost ~]# mysql   #进入数据库
mysql> grant replication slave on *.* to 'tongbu'@'192.168.1.118' identified by '123456';

②、查看 bin-log 文件

mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      396 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

③、连接主数据库

mysql> change master to master_host='192.168.1.117',master_user='tongbu',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=396;
Query OK, 0 rows affected (0.27 sec)

④、启动同步,查看主从集群是否创建完成

mysql> slave start;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status \G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

当前如果 Slave_IO_Running 进程和 Slave_SQL_Running 进程都是yes,就代表主从同步建立完成。

11、从主同步配置
①、在从数据库创建连接账户

mysql> grant replication slave on *.* to 'tongbu'@'192.168.1.117' identified by '123456789';

②、查看从数据库bin-log文件

mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000008 |      404 |              |                  |
+------------------+----------+--------------+------------------+

③、进入主数据库连接从数据库

mysql> change master to master_host='192.168.1.115',master_user='tongbu',master_password='123456789',master_log_file='mysql-bin.000008',master_log_pos=404;

④、启动同步,查看主从集群是否创建完成

mysql> slave start;

mysql> show slave status \G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

五、部署Discuz

1、实验环境
①、192.168.1.112 Nginx WEB前端
②、192.168.1.120 NFS 文件共享服务器
③、192.168.1.117 主数据库
④、192.168.1.120 Discuz PHP-fpm服务器
2、部署安装可正常使用的PHP-fpm服务
①、安装编译需要的依赖

[root@localhost ~]# yum install gcc gd curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql-devel -y

②、下载PHP-5.6.9源码包

[root@localhost ~]# wget -c http://museum.php.net/php5/php-5.6.9.tar.gz

③、解压PHP-5.6.9源码包

[root@localhost ~]# tar -xzf php-5.6.9.tar.gz

④、进入PHP-5.6.9源码包,进行预编译

[root@localhost ~]# cd php-5.6.9
[root@localhost php-5.6.9]# ./configure 
--prefix=/usr/local/php5 
--enable-fpm 
--enable-debug 
--with-gd 
--with-jpeg-dir 
--with-png-dir 
--with-freetype-dir 
--enable-mbstring 
--with-curl 
--with-mysql 
--with-mysqli 
--disable-fileinfo

⑤、编译与编译安装

[root@localhost php-5.6.9]# make && make install

⑥、编辑PHP文件权限与配置文件,并启动

[root@localhost php-5.6.9]# \cp php.ini-development /usr/local/php5/lib/php.ini
[root@localhost php-5.6.9]# \cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
[root@localhost php-5.6.9]# \cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-5.6.9]# chmod 755 /etc/init.d/php-fpm
[root@localhost php-5.6.9]# chkconfig --add php-fpm
[root@localhost php-5.6.9]# chkconfig php-fpm on

⑦、修改 php-fpm.conf 配置文件

[root@localhost php-5.6.9]# vim /usr/local/php5/etc/php-fpm.conf

25 ;pid = run/php-fpm.pid   #原来
25 pid = run/php-fpm.pid   #修改为

⑧、重启 php ,使其配置文件生效

[root@localhost nginx]# service php-fpm restart   #平滑关闭并启动
systemctl status php-fpm   #查看运行状态

3、修改 /etc/php.ini 配置文件,否则会有函数报错

[root@localhost ~]# yum install php-mysql -y   #先下载
[root@localhost ~]# find / -name pdo_mysql.so   #查看路径
/usr/lib64/php/modules/pdo_mysql.so
728行  ;extension_dir = "./"   #原来
728行  extension_dir = "/usr/lib64/php/modules"   #修改为

4、修改 /usr/local/php5/etc/php-fpm.conf 配置文件,使Nginx WEB前端可以正常连接

164行  listen = 127.0.0.1:9000   #原来
164行  listen = 0.0.0.0:9002   #修改为
如下取消注释并修改
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500

5、重启 PHP-fpm 使配置生效

[root@localhost nginx]# service php-fpm restart

6、创建 /data/html/dz.jf.com 目录

[root@localhost ~]# mkdir -p /data/html/dz.jf.com

7、下载Discuz软件包

[root@localhost ~]# wget -c http://download.comsenz.com/DiscuzX/3.1/Discuz_X3.1_SC_UTF8.zip   #下载Discuz软件包

8、解压拷贝至 /data/html/dz.jf.com 目录(与PHP-CGI文件目录相同)

[root@localhost ~]# yum install zip unzip -y
[root@localhost ~]# unzip Discuz_X3.1_SC_UTF8.zip
[root@localhost ~]# cd Discuz_X3.1_SC_UTF8/upload
[root@localhost upload]# mv * /data/html/dz.jf.com

9、修改 Nginx WEB前端 配置文件

user  nginx;
worker_processes  1;

events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
**Discuz server:**
    server {
        listen       80;
        server_name  dz.jf.com;
        location / {
        root   /mnt/dz.jf.com;
        index  index.html index.php;
        }
location ~ \.php$ {
		root           /data/html/dz.jf.com;
		fastcgi_pass   192.168.1.120:9002;
        fastcgi_index  index.php;
		fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
        include        fastcgi_params;
		}
	}
}

10、重启 Nginx WEB 前端,使配置生效

[root@localhost conf]# /data/nginx/sbin/nginx -s reload

11.使用浏览器访问 http://dz.jf.com ,进行论坛安装
LNMP+NFS文件共享集群架构发布Discuz与WorPress_第1张图片
12、在MySQL创建Discuz数据库

mysql> grant all on Discuz.* to Discuz@'192.168.1.120' identified by "gdl";   #创建MySQL连接用户
mysql> create database discuz charset=utf8;   创建Discuz数据库
mysql> flush privileges;   #更新权限

13、在 PHP-fpm 服务器添加 hosts

[root@localhost ~]# vim /etc/hosts
192.168.1.117 mysql.jf.com

LNMP+NFS文件共享集群架构发布Discuz与WorPress_第2张图片
LNMP+NFS文件共享集群架构发布Discuz与WorPress_第3张图片
LNMP+NFS文件共享集群架构发布Discuz与WorPress_第4张图片
LNMP+NFS文件共享集群架构发布Discuz与WorPress_第5张图片
LNMP+NFS文件共享集群架构发布Discuz与WorPress_第6张图片
LNMP+NFS文件共享集群架构发布Discuz与WorPress_第7张图片

到这里Discuz就部署完成了。

六、部署WorPress

1、实验环境
①、192.168.1.112 Nginx WEB前端
②、192.168.1.120 NFS 文件共享服务器
③、192.168.1.117 主数据库
④、192.168.1.121 PHP-fpm服务器
2、部署安装可正常使用的PHP-fpm服务
①、安装编译需要的依赖

[root@localhost ~]# yum install gcc gd curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql-devel -y

②、下载PHP-5.6.9源码包

[root@localhost ~]# wget -c http://museum.php.net/php5/php-5.6.9.tar.gz

③、解压PHP-5.6.9源码包

[root@localhost ~]# tar -xzf php-5.6.9.tar.gz

④、进入PHP-5.6.9源码包,进行预编译

[root@localhost ~]# cd php-5.6.9
[root@localhost php-5.6.9]# ./configure 
--prefix=/usr/local/php5 
--enable-fpm 
--enable-debug 
--with-gd 
--with-jpeg-dir 
--with-png-dir 
--with-freetype-dir 
--enable-mbstring 
--with-curl 
--with-mysql 
--with-mysqli 
--disable-fileinfo

⑤、编译与编译安装

[root@localhost php-5.6.9]# make && make install

⑥、编辑PHP文件权限与配置文件,并启动

[root@localhost php-5.6.9]# \cp php.ini-development /usr/local/php5/lib/php.ini
[root@localhost php-5.6.9]# \cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
[root@localhost php-5.6.9]# \cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-5.6.9]# chmod 755 /etc/init.d/php-fpm
[root@localhost php-5.6.9]# chkconfig --add php-fpm
[root@localhost php-5.6.9]# chkconfig php-fpm on

⑦、修改 php-fpm.conf 配置文件

[root@localhost php-5.6.9]# vim /usr/local/php5/etc/php-fpm.conf

25 ;pid = run/php-fpm.pid   #原来
25 pid = run/php-fpm.pid   #修改为

⑧、重启 php ,使其配置文件生效

[root@localhost nginx]# service php-fpm restart   #平滑关闭并启动
systemctl status php-fpm   #查看运行状态

3、修改 /etc/php.ini 配置文件,否则会有函数报错

[root@localhost ~]# yum install php-mysql -y   #先下载
[root@localhost ~]# find / -name pdo_mysql.so   #查看路径
/usr/lib64/php/modules/pdo_mysql.so
728行  ;extension_dir = "./"   #原来
728行  extension_dir = "/usr/lib64/php/modules"   #修改为

4、修改 /usr/local/php5/etc/php-fpm.conf 配置文件,使Nginx WEB前端可以正常连接

164行  listen = 127.0.0.1:9000   #原来
164行  listen = 0.0.0.0:9003   #修改为
如下取消注释并修改
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500

5、重启 PHP-fpm 使配置生效

[root@localhost nginx]# service php-fpm restart

6、创建 /data/html/wp.jf.com 目录

[root@localhost ~]# mkdir -p /data/html/wp.jf.com

7、下载WordPress软件包

[root@localhost ~]# wget -c https://wordpress.org/wordpress-4.9.7.tar.gz   #下载WordPress软件包

8、解压拷贝至 /data/html/wp.jf.com 目录

[root@localhost ~]# tar -xzf wordpress-4.9.7.tar.gz
[root@localhost ~]# cd wordpress-4.9.7
[root@localhost wordpress-4.9.7]# cd wordpress-4.9.7
[root@localhost wordpress-4.9.7]# mv * /data/html/wp.jf.com

9、修改 Nginx WEB前端 配置文件

user  nginx;
worker_processes  1;

events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
**Discuz server:**
    server {
        listen       80;
        server_name  dz.jf.com;
        location / {
        root   /mnt/dz.jf.com;
        index  index.html index.php;
        }
location ~ \.php$ {
		root           /data/html/dz.jf.com;
		fastcgi_pass   192.168.1.120:9002;
        fastcgi_index  index.php;
		fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
        include        fastcgi_params;
		}
	}
**WordPress server:**
	    server {
        listen       80;
        server_name  wp.jf.com;
        location / {
        root   /mnt/wp.jf.com;
        index  index.html index.php;
        }
location ~ \.php$ {
		root           /data/html/wp.jf.com;
		fastcgi_pass   192.168.1.121:9003;
        fastcgi_index  index.php;
		fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
        include        fastcgi_params;
		}
	}
}

10、重启 Nginx WEB 前端,使配置生效

[root@localhost conf]# /data/nginx/sbin/nginx -s reload

11、打开浏览器输入 http://wp.jf.com 进行博客安装
LNMP+NFS文件共享集群架构发布Discuz与WorPress_第8张图片
12、在MySQL创建WordPress数据库

MariaDB [(none)]> grant all on wordpress.* to wordpress@'192.168.1.121' identified by "gdl";   #创建MySQL连接用户
MariaDB [(none)]> create database wordpress;   创建WordPress数据库
MariaDB [(none)]> flush privileges;   #更新权限

13、在 PHP-fpm 服务器添加 hosts

[root@localhost ~]# vim /etc/hosts
192.168.1.117 mysql.jf.com

LNMP+NFS文件共享集群架构发布Discuz与WorPress_第9张图片
LNMP+NFS文件共享集群架构发布Discuz与WorPress_第10张图片
14、上图发生错误,提升缺少一个php文件
进入NFS文件共享服务器与本地PHP读取目录添加wp-config.php文件
①、192.168.1.120 NFS 文件共享服务器

[root@localhost wp.jf.com]# pwd
/data/html/wp.jf.com
[root@localhost wordpress]# touch wp-config.php   #创建 wp-config.php 空文件
[root@localhost wordpress]# vim wp-config.php   #修改 wp-config.php

②、192.168.1.121 PHP-fpm服务器

[root@localhost wp.jf.com]# pwd
/data/html/wp.jf.com
[root@localhost wordpress]# touch wp-config.php   #创建 wp-config.php 空文件
[root@localhost wordpress]# vim wp-config.php   #修改 wp-config.php
14x|QBmf:[B)BA&]GqK');
define('SECURE_AUTH_KEY',  'cSvH/n/K7VW?faos`Cqs_7J53fh+:G6#MU7!f4wpQ');
define('LOGGED_IN_KEY',    'dS*x5!eP.C A8;cqz|sG#fhS`&*]5NC4F5%$z.RE&?53SOeJTr_kx1=9_.MZa;I@');
define('NONCE_KEY',        'u-)*XXw~yAla>2f/veo[Sh-HLAA+/*.LQmFbDb=[lVb1YOdTE=}P<5h3TYwRkRua');
define('AUTH_SALT',        'xP]ZCe;[ni@gL7:H7#V`F&{D)4Pw] a6}o5E}$4CU$|jF,xfmG;KX1rN].1Jw=iG');
define('SECURE_AUTH_SALT', '/7qX7^AQ~@1&Z|ek(Io+xd8r_OmYZlVgJ:hl0aSj?B3y,^++mk*J2)7RUs@Ncu:@');
define('LOGGED_IN_SALT',   ' oC@Hh*N&?hdt ~EuMRLSk*lF=1(@0?]cGimZ*|8!ZSC}w0qlQNY|j6;}.@%N.Kq');
define('NONCE_SALT',       'MQ?xfzhk9wusFl^M}qM]hsQLjU)}Cs>$d(j{PA#3szA^,>%)J&R5cJyU|@#=WA#Q');

/**#@-*/

/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix  = 'wp_';

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 *
 * For information on other constants that can be used for debugging,
 * visit the Codex.
 *
 * @link https://codex.wordpress.org/Debugging_in_WordPress
 */
define('WP_DEBUG', false);

/* That's all, stop editing! Happy blogging. */

/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
	define('ABSPATH', dirname(__FILE__) . '/');

/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');
?>

LNMP+NFS文件共享集群架构发布Discuz与WorPress_第11张图片
LNMP+NFS文件共享集群架构发布Discuz与WorPress_第12张图片

到这里WorPress就部署完成了。

七、LNMP+NFS文件共享集群架构图

LNMP+NFS文件共享集群架构发布Discuz与WorPress_第13张图片

你可能感兴趣的:(Linux,服务,集群架构)