Redis的安装部署手册
单机部署:
1.安装gcc
yum install gcc-c++
yum install ruby
2.上传tar包到/src目录
3. 解压
tar -zxvf redis-3.2.8.tar.gz
4.进入redis-3.2.8
cd redis-3.2.8/
5.编译
make
6.安装
make PREFIX=/usr/local/redis install
redis-server的路径在/usr/local/redis/bin/下
或者
make install
redis-server默认安装的路径就是/usr/local/bin/
7.把redis配置文件拷贝到安装目录
cp redis.conf /usr/local/redis
8.启动(这里使用的路径是:PREFIX=/usr/local/redis)
cd /usr/local/redis
./bin/redis-server
后端启动
1.修改配置文件
cd /usr/local/redis
vim redis.conf
找到daemonize no将其改为yes
2.启动
./bin/redis-server ./redis.conf
3.查看redis程序状态
ps -ef | grep -i redis
4.关闭redis
./bin/redis-cli shutdown
出现以下问题:
WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommi
t_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
解决方案:
echo vm.overcommit_memory=1 >> /etc/sysctl.conf
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. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
解决方案:
echo never > /sys/kernel/mm/transparent_hugepage/enabled
vi /etc/rc.d/rc.local 或者vi /etc/rc.local
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
chmod +x /etc/rc.d/rc.local
重启
出现以下问题:
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128
.
解决方案
vi /etc/sysctl.conf
net.core.somaxconn= 1024
wq
sysctl -p
测试
./bin/redis-cli
[root@localhost redis]# ./bin/redis-cli
//检查网络是否可以
127.0.0.1:6379> ping
PONG
//设置一个键值对
127.0.0.1:6379> set name cheny
OK
//获取刚刚设置的键值对
127.0.0.1:6379> get name
"cheny"
redis后台启动
vi /usr/local/redis/redis.conf
daexxx=yes
wq
./bin/redis-server ./redis.conf (没有-c参数)
开启6379端口
CentOS 7 采用了 firewalld 防火墙
firewall-cmd --query-port=6379/tcp
no
firewall-cmd --add-port=6379/tcp
yes
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-port=6379/tcp
firewall-cmd --reload
集群搭建(三组六从)
1.建立集群目录
cd /usr/local/src/redis-3.2.8
mkdir cluster
2.建立7000目录
cd cluster
mkdir 7000
3.复制redis.conf文件到7000下
cd /usr/local/src/redis-3.2.8
cp redis.conf cluster/7000
4.修改7000下的redis.conf
cd /usr/local/src/redis-3.2.8/cluster/7000
vim redis.conf
4.1关闭aof文件模式使用rdb模式
[图片上传失败...(image-2cad6a-1632147565460)]
4.2.注释bind 127.0.0.1,取消ip绑定
[图片上传失败...(image-1b5096-1632147565460)]
4.3.关闭保护模式
[图片上传失败...(image-3ea4e0-1632147565460)]
4.4.修改端口号
[图片上传失败...(image-24d699-1632147565460)]
4.5.开启后台启动
[图片上传失败...(image-449fe7-1632147565460)]
4.6.修改pidfile
[图片上传失败...(image-d65b5e-1632147565460)]
4.7修改dir文件
[图片上传失败...(image-39b45f-1632147565460)]
4.8修改内存策略
[图片上传失败...(image-8ab5e7-1632147565460)]
4.9开启集群配置
[图片上传失败...(image-74c563-1632147565460)]
4.10.开启集群的配置
[图片上传失败...(image-26dbd1-1632147565460)]
4.11.修改集群的推选时间 [图片上传失败...(image-96b4e6-1632147565459)]
5.同样的方式7001,7002,7003,7004,7005,7006,7007,7008
5.1.复制所有文件
cd /usr/local/src/redis-3.2.8/cluster
cp -r 7000 7001
cp -r 7000 7002
cp -r 7000 7003
cp -r 7000 7004
cp -r 7000 7005
cp -r 7000 7006
cp -r 7000 7007
cp -r 7000 7008
5.2.修改7001
vim 7001/redis.conf
:%s/7000/7001/g
单击回车
:wq
5.3.修改7002,7003,7004,7005,7006,7007,7008
同5.2
6.集群脚本
cd /usr/local/src/redis-3.2.8/cluster
vim startAll.sh
!/bin/sh
/usr/local/redis/bin/redis-server /usr/local/src/redis-3.2.8/cluster/7000/redis.conf &
/usr/local/redis/bin/redis-server /usr/local/src/redis-3.2.8/cluster/7001/redis.conf &
/usr/local/redis/bin/redis-server /usr/local/src/redis-3.2.8/cluster/7002/redis.conf &
/usr/local/redis/bin/redis-server /usr/local/src/redis-3.2.8/cluster/7003/redis.conf &
/usr/local/redis/bin/redis-server /usr/local/src/redis-3.2.8/cluster/7004/redis.conf &
/usr/local/redis/bin/redis-server /usr/local/src/redis-3.2.8/cluster/7005/redis.conf &
/usr/local/redis/bin/redis-server /usr/local/src/redis-3.2.8/cluster/7006/redis.conf &
/usr/local/redis/bin/redis-server /usr/local/src/redis-3.2.8/cluster/7007/redis.conf &
/usr/local/redis/bin/redis-server /usr/local/src/redis-3.2.8/cluster/7008/redis.conf &
wq
7.安装ruby(ruby的version于2.2.2)
7.1. 安装RVM
命令1:
gpg --keyserver hkp://pgp.mit.edu --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
命令2:
curl -sSL https://get.rvm.io | bash -s stable
命令3:
find / -name rvm -print
命令4:(加载文件)
source /usr/local/rvm/scripts/rvm
7.2.查看rvm库中已知的ruby版本
rvm list known
7.3.安装一个ruby版本
rvm install 2.4
7.4.使用一个ruby版本
rvm use 2.4.10
7.5.设置默认版本
rvm use 2.4.10 --default
7.6.卸载一个已知版本(不需要做)
rvm remove 2.4.10
7.7.查看ruby版本
ruby --version
7.8.安装gem
gem install redis
参考:https://cloud.tencent.com/developer/article/1409323
8.通过ruby创建集群
cd /usr/local/src/redis-3.2.8/src
./redis-trib.rb create --replicas 2 192.168.47.133:7000 192.168.47.133:7001 192.168.47.133:7002 192.168.47.133:7003 192.168.47.133:7004 192.168.47.133:7005 192.168.47.133:7006 192.168.47.133:7007 192.168.47.133:7008
显示安装成功
测试
cd /usr/local/src/redis-3.2.8/src
./redis-cli -p 7000 –c
set aa aa
set qq qq
9. redis集群在创建的时候不能配置密码认证,因此在集群创建完成之后可以配置密码认证:
redis-cli -p 7000
config set requirepass 123456
auth 123456
config rewrite
参考资料:https://blog.csdn.net/u011330018/article/details/106114205
https://www.cnblogs.com/wxzhe/p/10751449.html
https://www.cnblogs.com/shengdimaya/p/6800423.html
TODO redis6的版本如何集群搭建?
网友评论