作者:三少乾坤_943 | 来源:互联网 | 2023-10-17 21:34
nginx反向代理、动静分离、负载均衡及rewrite隐藏路径详解
(Nginx Apache mysql Redis)
楓城浪子原创,转载请标明出处!
更多技术博文请见个人博客:https://fengchenglangzi.000webhostapp.com
微信bh19890922
QQ445718526、490425557
2.3 Redis 主从搭建
2.3.1 redis安装配置
1 2 3 4 5
| [root@localhost redis-2.8.13]# yum install gcc gcc-c++ -y
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget -c http://download.redis.io/releases/redis-2.8.13.tar.gz |
注:安装gcc gcc-c++,下载redis源码包
1 2 3 4 5 6 7 8 9
| [root@localhost src]# tar -zxf redis-2.8.13.tar.gz
[root@localhost src]# cd redis-2.8.13
[root@localhost redis-2.8.13]# make
[root@localhost redis-2.8.13]# cd src
[root@localhost src]# make install PREFIX=/usr/local/redis |
注:解压redis,并编译安装到指定目录
1
| [root@localhost redis-2.8.13]# cp redis.conf /usr/local/redis/ |
注:将redis配置文件复制到安装目录下,由于redis安装不会自动生成配置文件,故此操作在源码解压目录中操作
1 2 3
| [root@localhost redis-2.8.13]# echo ‘export PATH=/usr/local/redis/bin:$PATH‘ >> /etc/profile
[root@localhost redis-2.8.13]# source /etc/profile |
注:把redis下的bin目录加入环境变量profile末尾,然后执行命令使其生效。
1
| [root@localhost redis]# sed -i ‘s/daemonize no/daemonize yes/g‘ redis.conf |
注:由于默认redis启动不是后端启动,所以可以修改redis配置文件,把此处的no改为yes即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| [root@localhost redis]# ./bin/redis-server ./redis.conf
[root@localhost redis]# ps aux | grep redis
root 4490 0.1 0.4 137372 2324 pts/0 Sl 05:26 0:00 /usr/local/redis/bin/redis-server *:6379
root 4500 0.0 0.1 103320 884 pts/0 S+ 05:32 0:00 grep redis
[root@localhost redis]# netstat -anlp | grep redis
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 4490/redis-server *
tcp 0 0 :::6379 :::* LISTEN 4490/redis-server *
[root@localhost redis]# |
注:执行./bin/redis-server ./redis.conf 启动redis,虽然无任何提示,但可以使用ps命令查看redis进程以及使用netstat命令查看redis端口号
停止redis
redis-cli shutdown
关闭所有
redis-cli -p 6397 shutdown
关闭6397端口的redis
注:关闭以后缓存数据会自动转储到硬盘上,硬盘地址可以查看redis.conf配置文件中的dbfilename dump.rdb
2.3.2 Redis主从配置
Redis主从配置非常简单,而且redis支持多重slave,所以可以无限延伸下去
1
| [root@localhost ~]# sed -i ‘/port 6379/a\slaveof 192.168.8.135 6379‘ /usr/local/redis/redis.conf |
注:只需要在slave上面的redis主配置文件中port 6379 行下面加上slaveof 192.168.8.135 6379即可
1 2 3 4 5 6 7
| [root@localhost ~]# pkill redis
[root@localhost ~]# /usr/local/redis/bin/redis-server ./redis.conf
[root@localhost ~]# redis-cli
127.0.0.1:6379> info |
注:重启redis,并执行info命令,如果显示如下图所示,表示slave配置完成
2.3.3 安装php-redis连接驱动
注:驱动需要和php安装在一起
所以一下配置在LAP上面进行
驱动作用:要确保PHP能够连接Redis缓存服务器,需添加PHP Redis扩展程序,即添加PHP扩展模块
1 2 3 4 5 6 7 8 9 10 11
| [root@localhost src]# wget -c https://github.com/phpredis/phpredis/archive/3.1.2.tar.gz
[root@localhost src]# tar zxf 3.1.2.tar.gz
[root@localhost src]# cd phpredis-3.1.2/
[root@localhost phpredis-3.1.2]# /usr/local/php5/bin/phpize
[root@localhost phpredis-3.1.2]# ./configure --with-php-cOnfig=/usr/local/php5/bin/php-config --enable-redis
[root@localhost phpredis-3.1.2]# make -j8 && make install |
注:下载驱动并编译安装,由于驱动本身解压后是没有configure执行文件的,所以使用phpize命令创建
如果出现以下报错请执行yum install m4 autoconf -y
记录下图中部分/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/
1 2 3 4 5 6 7
| [root@localhost phpredis-3.1.2]# cat >> /usr/local/php5/lib/php.ini <
extension_dir = "/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/"
extension=redis.so
EOF |
注:在php.ini最后追加以上内容
1
| [root@localhost phpredis-3.1.2]# /usr/local/apache2/bin/apachectl restart |
注:重启apache,然后刷新网页出现如下redis信息,即集成完成!
2.4 发布Discuz论坛
1 2 3 4 5 6 7 8 9
| [root@localhost src]# wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_UTF8.zip
root@localhost src]# unzip Discuz_X3.2_SC_UTF8.zip
[root@localhost src]# cp -a readme/ upload/ utility/ /usr/local/apache2/htdocs/
[root@localhost htdocs]# cp -a ./upload/* .
[root@localhost htdocs]# ../bin/apachectl restart |
注:下载discuz软件,并解压复制到apache发布目录,并拷贝upload里的文件到发布根目录
访问http://192.168.8.135/install/进行安装
提示不可写,直接在发布目录执行如下命令
1
| [root@localhost htdocs]# chmod -R o+w .* |
此处省略discuz的安装过程,出现以下界面表示discuz安装完成
1
| [root@localhost config]# vim config_global.php |
注:修改config_global.php ,此文件在发布目录config下,修改为如下图所示
第二台LAP无需安装discuz,直接从第一台LAP上把发布目录拷贝过来即可,或者更方便的做法是部署一台NFS服务器,两台LAP共享发布目录即可
1
| [root@localhost htdocs]# scp -r .* [email&#160;protected]:/usr/local/apache2/htdocs/ |
2.5 测试redis缓存discuz以及redis主从
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| [root@localhost config]# redis-cli 127.0.0.1:6379> KEYS *
(empty list or set)
127.0.0.1:6379> KEYS *
1) "NgoypY_diytemplatenamehome"
2) "NgoypY_usergroups"
3) "NgoypY_onlinerecord"
4) "NgoypY_announcements"
5) "NgoypY_heats"
6) "NgoypY_pluginlanguage_system"
7) "NgoypY_userstats"
8) "NgoypY_usergroup_7"
9) "NgoypY_forum_index_page_7"
10) "NgoypY_pluginlanguage_script"
11) "NgoypY_style_default"
12) "NgoypY_userapp"
13) "NgoypY_historyposts"
14) "NgoypY_setting"
15) "NgoypY_plugin"
16) "NgoypY_cronnextrun"
17) "NgoypY_diytemplatenameforum"
18) "NgoypY_ipbanned"
19) "NgoypY_diytemplatename"
20) "NgoypY_magic"
21) "NgoypY_forumlinks"
22) "NgoypY_onlinelist"
127.0.0.1:6379> |
注:在discuz论坛上面随便点击内容,然后在redis master上面执行以上命令,可以看到缓存的数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| [root@localhost ~]# redis-cli
127.0.0.1:6379> KEYS *
1) "NgoypY_magic"
2) "NgoypY_heats"
3) "NgoypY_diytemplatenamehome"
4) "NgoypY_historyposts"
5) "NgoypY_userapp"
6) "NgoypY_pluginlanguage_system"
7) "NgoypY_style_default"
8) "NgoypY_usergroup_7"
9) "NgoypY_forumlinks"
10) "NgoypY_plugin"
11) "NgoypY_usergroups"
12) "NgoypY_setting"
13) "NgoypY_onlinerecord"
14) "NgoypY_diytemplatenameforum"
15) "NgoypY_diytemplatename"
16) "NgoypY_userstats"
17) "NgoypY_cronnextrun"
18) "NgoypY_announcements"
19) "NgoypY_pluginlanguage_script"
20) "NgoypY_onlinelist"
21) "NgoypY_ipbanned"
127.0.0.1:6379> |
注:以上是redis slave上面查看的内容,与master一致,表示redis缓存与redis主从配置无问题
至此基本环境搭建完毕!
本文出自 “楓城浪子” 博客,请务必保留此出处http://fengchenglangzi.blog.51cto.com/1322043/1963223