LAMP + Redis 主从复制

测试环境:

LAMP + Redis 主从复制:

LAMP server ip:10.0.0.4

主 Redis server ip:10.0.0.5

从Redis server  ip:10.0.0.6

LAMP 已经安装成功,安装过程见其他博文;

Redis主从配置非常简单,只需要在Redis丛库10.0.0.6配置中设置如下指令,slaveof表示指定主库的IP,10.0.0.5为master服务器,6379为master服务器Redis端口;

redis 安装:

wget http://download.redis.io/releases/redis-4.0.9.tar.gz 
tar zxf redis-4.0.9.tar.gz cd redis-4.0.9

 yum install gcc-c++ -y

 make PREFIX=/usr/local/redis MALLOC=libc install

cp redis.conf /usr/local/redis/

将/usr/local/redis/bin/目录加入至环境变量配置文件/etc/profile末尾,然后Shell终端执行source /etc/profile让环境变量生效:

echo "export PATH=/usr/local/redis/bin:$PATH" >> /etc/profile 
source /etc/profile

 nohup  /usr/local/redis/bin/redis-server  /usr/local/redis/redis.conf  &

 nohup不挂断地运行命令。 一般是和&号同时使用

 /usr/local/redis/bin/redis-cli  -p  6379 shutdown

2)在lamp server上添加php-redis 模块wget  https://github.com/phpredis/phpredis/archive/3.1.2.tar.gz

tar   xzf  3.1.2.tar.gz

#复制配置文件到/usr/local/php5/lib/下:此目录是在phpinfo页面Configuration File参数的目录下

cp /usr/src/php-5.3.28/php.ini-production  /usr/local/php5/lib/php.ini

#phpize 是属于 php-devel 中的东西,主要是设定 php 外挂模块的一些设定

例如你的php不支持mysql, mbstring、redis等

yum install autoconf  -y

Autoconf产生的配置脚本通常叫做configure。configure运行的时候会产生几个文件,这几个文件包含了有合适的值的配置参数。自动生成configure脚本的

cd   phpredis-3.1.2/

/usr/local/php5/bin/phpize

#phpize 是属于 php-devel 中的东西,主要是设定 php 外挂模块的一些设定

例如你的php不支持mysql, mbstring、redis等

./configure  --with-php-config=/usr/local/php5/bin/php-config  --enable-redis

make && make install

修改vim /usr/local/php5/lib/php.ini配置文件,添加redis.so模块,代码如下:

extension_dir = "/usr/local/php5/lib/php/extensions/no-debug-zts-20090626"

extension=redis.so

重启lamp中的Apache 服务,编写phpinfo 测试页面:

<? php

phpinfo();

?>

会检测到redis模块:

redis从库配置:redis.conf

grep -v -E  "^#|^$" /usr/local/redis/redis.conf

redis.conf配置: daemonize no pidfile /var/run/redis.pid port 6379 slaveof 10.0.0.5 6379 #添加redis主库的ip和port tcp-backlog 511 timeout 0 tcp-keepalive 0 loglevel notice logfile "" databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename redis.rdb dir /data/redis/ slave-serve-stale-data yes slave-read-only yes repl-disable-tcp-nodelay no slave-priority 100 appendonly no appendfilename "appendonly.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb lua-time-limit 5000 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-entries 512 list-max-ziplist-value 64 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes

  

重启Redis主库、丛库服务,在Redis主库创建key及values,登录Redis丛库查看:

主库宕机之后可以使用从库继续配置,需要将discuz配置文件修改成从库地址:

Redis从库需要将配置修改成监听所有并去掉从库标签:

没有借口
原文地址:https://www.cnblogs.com/wutao1935/p/11977800.html