一、环境


软件版本
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.confserver {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 root@192.168.1.21:/usr/share/nginx/html/wordpress /data/nginx/html/
[root@localhost ~]# rsync -av root@192.168.1.21:/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 ~]# mysqlMariaDB [(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/ root@192.168.1.21:/usr/share/nginx/html/wordpress/

5、浏览器安装discuz

http://bbs.yjy.com

有页面排版乱码的现象,需要反同步一下nginx的项目目录
Php端

[root@localhost ~]# rsync -av /data/nginx/html/discuz/upload/ root@192.168.1.21:/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 serverPlease 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 serverPlease 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.conf70 bind 0.0.0.0             监听IP,本机IP或127.0.0.1或0.0.0.089 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 1220 save 300 10221 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.conf70 bind 0.0.0.0  监听IP,本机IP或127.0.0.1或0.0.0.093 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' => null411         );

刷新网页,发现已连接的状态

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:631646620@qq.com"
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

Centos7 分离部署lnmp+discuz+wordpress 及Redis相关推荐

  1. dockerfile二进制mysql_Dockerfile源码分离部署LNMP(Centos7)

    Dockerfile常用指令: 1.FROM:构建镜像基于哪个镜像 例如:FROM centos 2.MAINTAINER:镜像维护者姓名或邮箱地址 例如:MAINTAINER Sun qiu min ...

  2. CentOS7.2基于LNMP搭建Wordpress

    本次搭建LAMP+Wordpress环境如下 MySQL php Wordpress_CN 4.9 nginx CentOS 7.2 192.168.100.10 1. 安装mariadb.php.n ...

  3. docker分离部署lnmp

    以下所需的全部的文件.镜像.软件,如有需要请到我的百度云分享下载: 链接:http://pan.baidu.com/s/1kUVNdsj 密码:an9l 项目需求: 构建lnmp平台. 要求nginx ...

  4. Nginx实战基础篇六 通过源码包编译安装部署LNMP搭建Discuz论坛

    Nginx实战基础篇六 通过源码包编译安装部署LNMP搭建Discuz论坛 版权声明: 本文遵循"署名非商业性使用相同方式共享 2.5 中国大陆"协议 您可以自由复制.发行.展览. ...

  5. windows下Redis 主从读写分离部署

    windows下Redis 主从读写分离部署 原文: windows下Redis 主从读写分离部署 1.可直接下载window下的运行文件(下面这个链接) 也可以浏览github 查看相应的版本说明文 ...

  6. 分布式部署LNMP+WordPress

    一.MYSQL主从配置 1. 基础环境安装 (1)修改主机名 使用远程连接工具CRT连接到192.168.200.30.192.168.200.40这两台虚拟机,并对这两台虚拟机进行修改主机名的操作, ...

  7. 分布式部署 LNMP+WordPress

    本实验在之前发布的实验基础上的整合. 具体规划如下: 实验步骤 分布式 LNMP 环境的调试 (1)配置 Nginx 服务支持 PHP 环境 使用远程连接工具 CRT 连接到 192.168.200. ...

  8. 项目:部署LNMP动态网站

    部署LNMP动态网站 问题 部署LNMP动态网站,实现以下目标: 安装LNMP平台相关软件 配置Nginx实现动静分离 配置数据库,创建账户与密码 上线Wordpress代码 使用Wordpress后 ...

  9. 服务器硬件、部署LNMP动态网站 案例

    Top NSD Project1 DAY01 案例1:服务器硬件 案例2:部署LNMP动态网站 1 案例1:服务器硬件 1.1 问题 服务器硬件品牌有哪些,服务器硬件组成结构分析: 常见服务器品牌介绍 ...

最新文章

  1. 知乎的 Flink 数据集成平台建设实践
  2. java 中的路径问题总结(绝对路径与相对路径) .
  3. jQuery常用的元素查找方法总结 .
  4. 您对无法重新创建的表进行了更改或者启用了“阻止保存要求重新创建表的更改”选项...
  5. 接口implements(Java)
  6. 【Java】forward redirect 的差异
  7. 机器学习数学基础之高数篇——函数极限和导数(python版)
  8. 考勤打卡不如自我约束
  9. Ubuntu开启BBR加速
  10. LED点阵显示,有关特殊国别(阿拉伯,希伯来,泰文)字符排版和乱码问题解决
  11. openwrt-17.01.6 LEDE下载
  12. 基于机智云的智能花盆2.0
  13. 随机生成5个英文验证码,判断用户输入的是否正确不区分大小写
  14. 首战告捷!网易有道斩获首届NLPCC中文语法错误修正比赛冠军
  15. 学会这些,睡觉也能赚大钱
  16. 5分钟看懂│从深蓝到阿尔法狗,人机大战20年进化了什么?
  17. 谢启鸿老师思考题及解答合集
  18. 一测振系统包括微型计算机,激振器之振动测试系统组成及基本仪器的使用方法 ......
  19. 高新技术企业认定指导
  20. 知识管理:新时代企业竞争力核心

热门文章

  1. 计算机考研840考纲,2020年北航考研840网络空间安全专业综合考试大纲
  2. 会抓老鼠的猫不一定是好猫
  3. Powershell--正则表达式--字符--含义
  4. 太秀了!那个在 GitHub 用文言文编程的小哥,竟从 28 万行唐诗中找出了对称矩阵
  5. fest + selenium进行In-browser Applet自动化测试
  6. android打包aab并安装到手机
  7. DB2存储过程入门实例
  8. 这些有意思的女产品经理...你一定要知道
  9. SEI(Supplemental Enhancement Information)
  10. 【Java开发岗:SpringCould篇】