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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章