Centos7 分离部署lnmp+discuz+wordpress 及Redis

一、环境

在这里插入图片描述
软件版本
Nginx: 1.16.1
Php: 5.6
Mariadb: 5.5.6
Redis: 5.0
Discuz: 3.4
Wordpress: 5.4.2

二、流程(思路)

1、先安装LNMP(192.168.1.21,192.168.1.22,192.168.1.23),安装discuz、wordpress
2、源码安装配置redis, 6379(rdb持久化)对应discuz, 6380(aof持久化)对应wordpress
3、添加用户 -> 登录 - > 然后在数据库中删除用户 ->再次登录,验证redis缓存生效
4、其他测试redis功能测试,如redis突然宕机

三、安装lnmp、wordpress及discuz

1、安装nginx(192.168.21)

1)、Nginx安装

Nginx这里使用阿里的epel源直接yum安装

[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@localhost ~]# yum clean all
[root@localhost ~]# yum makecache
[root@localhost ~]# yum install –y nginx-1.16.1  安装nginx-1.16.1版本

下载wordpress并放至项目目录

[root@localhost src]# wget -c https://wordpress.org/latest.tar.gz -O /usr/share/nginx/html/wordpress.tar.gz
[root@localhost src]# cd /usr/share/nginx/html/
[root@localhost html]# tar xf wordpress.tar.gz
[root@localhost html]# chown -R nginx:nginx wordpress

下载discuz并放至项目目录

https://gitee.com/3dming/DiscuzL/attach_files
[root@localhost src]# unzip Discuz_X3.4_SC_UTF8【20191201】.zip -d /usr/share/nginx/html/discus
[root@localhost html]# chown -R nginx:nginx discuz/

2)、配置wordpress项目
[root@localhost html]# vim /etc/nginx/conf.d/blog.yjy.com.conf
        server {
        listen 80;
        server_name blog.yjy.com;
        location / {
                root         /usr/share/nginx/html/wordpress;
                index   index.php;
        }
        location ~ \.php$ {
               root           /data/nginx/html/wordpress/;  php服务器的路径
               fastcgi_pass   192.168.1.22:9000;
               fastcgi_index  index.php;
               fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
               include        fastcgi_params;
        }
}

3)、配置discuz 项目
[root@localhost conf.d]# pwd
/etc/nginx/conf.d
[root@localhost conf.d]# cp blog.yjy.com.conf bbs.yjy.com.conf
[root@localhost conf.d]# vim /etc/nginx/conf.d/bbs.yjy.com.conf
server {
        listen 80;
        server_name bbs.yjy.com;
        location / {
                root         /usr/share/nginx/html/discuz/upload/;
                index   index.php;
        }
        location ~ \.php$ {
               root           /data/nginx/html/discuz/upload/;
               fastcgi_pass   192.168.1.22:9000;
               fastcgi_index  index.php;
               fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
               include        fastcgi_params;
        }
}
[root@localhost conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

2、安装PHP(192.168.1.22)

1)、更换清华源,安装php5.6,默认是5.4
[root@localhost ~]# yum install https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm
[root@localhost yum.repos.d]# vim remi.repo
30 enabled=1

在这里插入图片描述
安装php及php-redis

[root@localhost ~]# yum install php php-fpm php-mysql php-devel php-xml php-redis –y

在这里插入图片描述
配置php-fpm用户组

[root@localhost ~]# vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx
listen = 192.168.1.22:9000
;listen.allowed_clients =	这里指的是nginx服务的IP,这里将他注释

[root@localhost ~]# chown -R nginx:nginx /var/lib/php/session/
[root@localhost ~]# mkdir -p /data/nginx/html		PHP的目录
[root@localhost ~]# chown -R nginx:nginx /data/nginx/html/	PHP的目录
[root@localhost ~]# mkdir -p /data/nginx/html/discuz
[root@localhost ~]# chown -R nginx:nginx /data/nginx/html/discuz/

项目同步,将nginx的项目目录同步到PHP的目录中,包含权限

[root@localhost ~]# rsync -av [email protected]:/usr/share/nginx/html/wordpress /data/nginx/html/
[root@localhost ~]# rsync -av [email protected]:/usr/share/nginx/html/discuz/upload /data/nginx/html/discuz/

在这里插入图片描述
关闭selinux,开启9000端口后访问浏览器
在这里插入图片描述

3、安装mariadb(192.168.1.23)

安装

[root@VM_0_14_centos ~]# yum install mariadb mariadb-devel mariadb-server mariadb-libs –y
[root@VM_0_14_centos ~]# systemctl start  mariadb             
[root@VM_0_14_centos ~]# mysql

MariaDB [(none)]> create database wordpress charset utf8;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> create database discuz charset utf8;               
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]>  grant all on wordpress.* to "wordpress"@"%" identified by "123456";
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>  grant all on discuz.* to "discuz"@"%" identified by "123456";                  
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

4、浏览器安装wrodpress

http://blog.yjy.com
在这里插入图片描述
在这里插入图片描述
改中文界面
在这里插入图片描述
注:如果有页面排版乱码的现象,需要反同步一下nginx的项目目录
Php端

[root@localhost ~]# rsync -av /data/nginx/html/wordpress/ [email protected]:/usr/share/nginx/html/wordpress/

5、浏览器安装discuz

http://bbs.yjy.com
在这里插入图片描述
有页面排版乱码的现象,需要反同步一下nginx的项目目录
Php端

[root@localhost ~]# rsync -av /data/nginx/html/discuz/upload/ [email protected]:/usr/share/nginx/html/discuz/upload/

在这里插入图片描述

四、安装redis

下载redis

[root@localhost src]# wget -c http://download.redis.io/releases/redis-5.0.5.tar.gz

编译安装

[root@localhost src]# tar xf redis-5.0.5.tar.gz
[root@localhost redis-5.0.5]# vim src/Makefile
PREFIX?=/usr/local/redis
[root@localhost redis-5.0.5]# make PREFIX=/usr/local/redis MALLOC=libc install
[root@localhost redis-5.0.5]# make install
[root@localhost redis-5.0.5]# mkdir -p /usr/local/redis/6379
[root@localhost redis-5.0.5]# mkdir -p /usr/local/redis/6380
[root@localhost redis-5.0.5]# cp redis.conf /usr/local/redis/6379/6379.conf
[root@localhost redis-5.0.5]# cp redis.conf /usr/local/redis/6380/6380.conf

在这里插入图片描述
前端启动

[root@localhost ~]#/usr/local/redis/bin/redis-server /usr/local/redis/6379/6379.conf

在这里插入图片描述
有警告
vim /etc/sysctl.conf

net.core.somaxconn=512
vm.overcommit_memory=1		1表示内核将所有的物理内存给进程,保留swap,2表示,所有内存,包括swap都给进程
[root@localhost ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled		让redis负责内存管理
[root@localhost ~]# sysctl -p
net.core.somaxconn = 512
vm.overcommit_memory = 1

后端启动

[root@localhost ~]# nohup /usr/local/redis/bin/redis-server /usr/local/redis/6379/6379.conf &
[1] 3567
nohup: ignoring input and appending output to ‘nohup.out’
[root@localhost ~]#

关闭进程

[root@localhost ~]# /usr/local/redis/bin/redis-cli -p 6379 shutdown

这样启动、关闭服务很麻烦,可以设置脚本来启动与关闭

配置脚本启动6379:

[root@localhost redis-5.0.5]# cp /usr/local/redis/bin/redis-server /usr/local/redis/bin/redis6379-server
[root@localhost redis-5.0.5]# /usr/src/redis-5.0.5/utils/install_server.sh                              
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 6379
Please select the redis config file name [/etc/redis/6379.conf] /usr/local/redis/6379/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] /usr/local/redis/6379/6379.log
Please select the data directory for this instance [/var/lib/redis/6379] /usr/local/redis/6379
Please select the redis executable path [] /usr/local/redis/bin/redis6379-server
Selected config:
Port           : 6379
Config file    : /usr/local/redis/6379/6379.conf
Log file       : /usr/local/redis/6379/6379.log
Data dir       : /usr/local/redis/6379
Executable     : /usr/local/redis/bin/redis6379-server
Cli Executable : /usr/local/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!


配置启动脚本6380

[root@localhost redis-5.0.5]# cp /usr/local/redis/bin/redis-server /usr/local/redis/bin/redis6380-server
[root@localhost redis-5.0.5]# /usr/src/redis-5.0.5/utils/install_server.sh       
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] 6380
Please select the redis config file name [/etc/redis/6380.conf] /usr/local/redis/6380/6380.conf
Please select the redis log file name [/var/log/redis_6380.log] /usr/local/redis/6380/6380.log
Please select the data directory for this instance [/var/lib/redis/6380] /usr/local/redis/6380/
Please select the redis executable path [] /usr/local/redis/bin/redis6380-server
Selected config:
Port           : 6380
Config file    : /usr/local/redis/6380/6380.conf
Log file       : /usr/local/redis/6380/6380.log
Data dir       : /usr/local/redis/6380/
Executable     : /usr/local/redis/bin/redis6380-server
Cli Executable : /usr/local/redis/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6380.conf => /etc/init.d/redis_6380
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

如此,就可以使用/etc/init.d/redis_6380 start stop restart了

五、编译redis配置文件

1、配置rdb半持久化,6379.conf对应discuz

 [root@localhost ~]# vim /usr/local/redis/6379/6379.conf
  70 bind 0.0.0.0				监听IP,本机IP或127.0.0.1或0.0.0.0
  89 protected-mode yes		可以查看键值
  93 port 6379				监听端口
102 tcp-backlog 511			tcp队列长度,这里默认
114 timeout 0					客户端与服务器之间的连接超时时间,0为永不超时
131 tcp-keepalive 300			每30秒给客户端发送ACK握手包
148 daemonize yes				默认为no,在前端运行,yes为在后端运行
 149 supervised no				可以通过upstart和systemd管理redis守护进程
160 pidfile /var/run/redis_6379.pid	pid文件
168 loglevel notice			日志级别,默认即可
173 logfile /usr/local/redis/6379/6379.log	日志路径
177 # syslog-enabled no		是否输出到系统日志
188 databases 16			数据库个数0-15编号,共16个数据库
196 always-show-logo yes	启动时是否显示日志
219 save 900 1
 220 save 300 10
 221 save 60 10000
237 stop-writes-on-bgsave-error yes	快照出问题时,不可写
243 rdbcompression yes		rdb模式,是否启动压缩,启用
252 rdbchecksum yes		对rdb数据文件操作时,启动校验
255 dbfilename dump.rdb	rdb文件名
265 dir /usr/local/redis/6379	rdb文件路径

2、配置aof全持久化, 6380.conf对应wordpress

[root@localhost ~]# vim /usr/local/redis/6380/6380.conf
  70 bind 0.0.0.0	监听IP,本机IP或127.0.0.1或0.0.0.0
  93 port 6380	监听端口
137 daemonize yes		后端运行
#save 900 1
#save 300 10
#save 60 10000	关闭rdb半持久化
700 appendonly yes	开启aof持久化,默认为no,不开启
704 appendfilename "appendonly.aof"		aof数据文件名
729 # appendfsync always		当键值有变化时,写入
730 appendfsync everysec		每秒写入,同步数据到磁盘
731 # appendfsync no			写入操作由操作系统完成,注释掉
752 no-appendfsync-on-rewrite yes	当rdb写入时,停止aof写入,这里没有开启rdb,此条不起作用
771 auto-aof-rewrite-percentage 100	aof文件增长100%时,重写
772 auto-aof-rewrite-min-size 64mb	aof文件大于64M时,重写
796 aof-load-truncated yes			aof文件加载时,忽略最后一条命令
其他默认

在这里插入图片描述

六、discuz网站连接redis的6379端口

192.168.1.22 PHP端

[root@localhost ~]# vim /data/nginx/html/discuz/upload/config/config_global.php
// ----------------------------  CONFIG DB  ----------------------------- //
$_config['db']['1']['dbhost'] = '192.168.1.23';
$_config['db']['1']['dbuser'] = 'discuz';
$_config['db']['1']['dbpw'] = '123456';
$_config['db']['1']['dbcharset'] = 'utf8';
$_config['db']['1']['pconnect'] = '0';
$_config['db']['1']['dbname'] = 'discuz';
$_config['db']['1']['tablepre'] = 'pre_';
$_config['db']['slave'] = '';
$_config['db']['common']['slave_except_table'] = '';

// --------------------------  CONFIG MEMORY  --------------------------- //
$_config['memory']['prefix'] = 'yWmPMV_';
$_config['memory']['redis']['server'] = '192.168.1.11';
$_config['memory']['redis']['port'] = 6379;
$_config['memory']['redis']['pconnect'] = 1;
$_config['memory']['redis']['timeout'] = '0';
$_config['memory']['redis']['requirepass'] = '';
$_config['memory']['redis']['serializer'] = 1;
$_config['memory']['redis']['db'] = 2;     增加此行
$_config['memory']['memcache']['server'] = '';
$_config['memory']['memcache']['port'] = 11211;
$_config['memory']['memcache']['pconnect'] = 1;
$_config['memory']['memcache']['timeout'] = 1;
$_config['memory']['apc'] = '0';
$_config['memory']['apcu'] = '0';
$_config['memory']['xcache'] = '0';
$_config['memory']['eaccelerator'] = '0';
$_config['memory']['wincache'] = '0';
$_config['memory']['yac'] = '0';
$_config['memory']['file']['server'] = '';

// --------------------------  CONFIG SERVER  -----------------------

[root@localhost ~]# vim /data/nginx/html/discuz/upload/source/class/memory/memory_driver_redis.php

 45                                 @$this->obj->setOption(Redis::OPT_SERIALIZER, $config['serializer']);
 46                                 $this->select($config['db']);
 47     

登录redis-cli,查看结果
在这里插入图片描述

七、wordpress连接redis

1、浏览器上传安装redis-cache插件

http://blog.yjy.com
安装插件并启用
在这里插入图片描述
启用插件
在这里插入图片描述
在这里插入图片描述
连接失败,这里会生成一个配置文件object-cache.php,直接编辑

[root@localhost ~]# vim /data/nginx/html/wordpress/wp-content/object-cache.php
404         $parameters = array(
 405             'scheme' => 'tcp',
 406             'host' => '192.168.1.11',
 407             'port' => 6380,
 408             'timeout' => 5,
 409             'read_timeout' => 5,
 410             'retry_interval' => null
 411         );

刷新网页,发现已连接的状态
在这里插入图片描述

2、查看redis-cli,看是否有KEY产生

[root@localhost ~]# /usr/local/redis/bin/redis-cli -p 6380
127.0.0.1:6380> KEYS *
 1) "wp:options:alloptions"
 2) "wp:users:1"
 3) "wp:site-transient:update_plugins"
 4) "wp:posts:3"
 5) "wp:user_meta:1"
 6) "wp:default:is_blog_installed"
 7) "wp:site-options:1-notoptions"
 8) "wp:site-transient:theme_roots"
 9) "wp:transient:doing_cron"
10) "wp:site-transient:update_themes"
11) "wp:site-transient:update_core"
12) "wp:post_meta:3"
13) "wp:useremail:[email protected]"
14) "wp:options:can_compress_scripts"
15) "wp:userslugs:toyix"
16) "wp:userlogins:toyix"
17) "wp:options:notoptions"
127.0.0.1:6380>

八、新建wordpress用户,登录,在mariadb中删除此用户,测试登录

新建用户aaa
在这里插入图片描述
aaa用户登录
在这里插入图片描述
在mariadb数据库中删除aaa用户
在这里插入图片描述
网页登录aaa用户(使用其他浏览器,如谷歌)
在这里插入图片描述

九、测试,当redis突然宕机时,用户是否可以正常访问且登录

关闭redis_6380

[root@localhost ~]# /etc/init.d/redis_6380 stop
Stopping ...
Redis stopped

结果:

1、aaa用户无法登录(刚才已删除)

在这里插入图片描述
2、普通用户可以正常登录,不影响使用
在这里插入图片描述

-----end

猜你喜欢

转载自blog.csdn.net/oToyix/article/details/106752988
今日推荐