redis 安装
tar zxvf redis-3.2.8.tar.gz
cd redis-3.2.8/src/
make
make test
如有提示 you need tcl8.5 or newer in order to run the Redis test
安装依赖包
yum install tcl -y
*****************异常处理**************
ARNING The following tests failed:
*** [err]: Test replication partial resync: ok psync (diskless: yes, reconnect: 1)
in tests/integration/replication-psync.tcl
Expected condition '[s -1 sync_partial_ok] > 0'
to be true ([s -1 sync_partial_ok] > 0)
Cleanup: may take some time...
OK
make[1]: *** [test] Error 1
make[1]: Leaving directory `/usr/local/src/redis-3.2.1/src'
make: *** [test] Error 2
解决办法
1.只用单核运行 make test
taskset -c 1 sudo make test
2.更改 tests/integration/replication-psync.tcl 文件
vi tests/integration/replication-psync.tcl
对应报错的那段代码中的 after后面的数字,从100改成 500。我个人觉得,这个参数貌似是等待的毫秒数。
对应代码
test "Test replication partial resync: $descr (diskless: $diskless, reconnect: $reconnect)" {
# Now while the clients are writing data, break the maste-slave
# link multiple times.
if ($reconnect) {
for {set j 0} {$j < $duration*10} {incr j} {
after 500
# catch {puts "MASTER [$master dbsize] keys, SLAVE [$slave dbsize] keys"}
if {($j % 20) == 0} {
catch {
if {$delay} {
$slave multi
$slave client kill $master_host:$master_port
$slave debug sleep $delay
$slave exec
} else {
$slave client kill $master_host:$master_port
}
}
}
}
}
****************************
修改redis.conf配置
daemonize no 改为 yes 以守护进程方式启动
修改pid打印地址
pidfile /opt/software/redis-3.2.8/redis.pid
需要redis密码认证
修改redis.conf requirepass myPassword
启动redis
cd /opt/software/redis-3.2.8/src/
./redis-server /opt/software/redis-3.2.8/redis.conf
验证redis
cd /opt/software/redis-3.2.8/src/
./redis-cli ping
./redis-cli
set kin 1
get kin
关闭redis
/opt/software/redis-3.2.8/src/redis-cli -p 6397 shutdown
***********************************************************
redis服务优化
查看/srv/software/redis-3.0.1下的nohup日志查看是否有警告
如下警告优化
3261:M 10 Jul 10:45:25.759 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition.
解决方法:
在/etc/sysctl.conf末尾增加 vm.overcommit_memory = 1 需要重启服务器
若要临时生效用root用户在终端执行 sysctl vm.overcommit_memory=1
如以下警告优化
WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. 、
解决方法:
以root用户执行echo never > /sys/kernel/mm/transparent_hugepage/enabled
并在/etc/rc.local文件末尾新加
echo never > /sys/kernel/mm/transparent_hugepage/enabled
如以下警告优化
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
解决方法:
以root用户执行
echo 511 > /proc/sys/net/core/somaxconn
并在/etc/rc.local文件末尾新加
echo 511 > /proc/sys/net/core/somaxconn
****************************************
从机配置
配置两台机器,因此另外一个也是同样的配置方式
只不过在/opt/software/redis-3.2.8/redis.conf 当中加入
slaveof 192.168.1.107 6379
redis客户端管理相关命令
通过客户端命令行工具连接redis服务查看redis相关信息
/opt/software/redis-3.2.8/src/redis-cli
redis 127.0.0.1:6379> info #查看server版本内存使用连接等信息
redis 127.0.0.1:6379> client list #获取客户连接列表
redis 127.0.0.1:6379> client kill 127.0.0.1:33441 #终止某个客户端连接
redis 127.0.0.1:6379> dbsize #当前保存key的数量
redis 127.0.0.1:6379> save #立即保存数据到硬盘
redis 127.0.0.1:6379> bgsave #异步保存数据到硬盘
redis 127.0.0.1:6379> flushdb #当前库中移除所有key
redis密码认证
修复redis.conf requirepass myPassword
重启redis
d登录验证
./redis-cli -h 127.0.0.1 -p 6379 -a myPassword
> config get requirepass
先连接后认证
./redis-cli -h 127.0.0.1 -p 6379
> auth myPassword
ok
配置了集群的,从机密码配置和master保持一致
Redis主从配置关键点:
主节点: 10.1.0.252
从节点: 10.1.0.224
主节点的redis.conf
1. port 16379
2. daemonize yes
3. pidfile /var/run/redis_16379.pid
4. logfile "/home/prod/redis/redis-4.0.8/log-redis.log"
5. 【坑1】: bind 127.0.0.1(删掉) bind 0.0.0.0?
从节点
1. port 26379
2. daemonize yes
3. pidfile /var/run/redis_26379.pid
4. logfile "/data/logs/redis.slave1.log"
5. 【坑2】slaveof 127.0.0.1(删掉) 10.1.0.252 16379
6. 【坑3】 masterauth redis0326(主节点密码) ---- 注意, 主节点redis有密码,必须项
7. 【坑4】bind 127.0.0.1(删掉) bind 10.1.0.224 (本机IP)