1.安装ruby2.5.5
yum install ruby
2.安装依赖
yum -y install gcc gcc-c++ libstdc++-devel
yum install make
3.下载redis5.0.7
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
4.解压安装
tar -zxvf redis-5.0.7.tar.gz
cd redis-5.0.7
#make后面的参数,是为解决报错: jemalloc/jemalloc.h: No such file or directory
make MALLOC=libc
#指定编译路径
make install PREFIX=/usr/local/redis
5.编辑redis.conf
#设置内网外网都能访问
bind 0.0.0.0
#后台运行
daemonize yes
#开启集群
cluster-enabled yes
#密码配置
masterauth 123456
requirePass 123456
6.启动
复制redis-5.0.7/redis.conf到/usr/local/redis/bin
cd到/usr/local/redis/bin
./redis-server /redis.conf
关闭命令
./redis-cli -a 密码 shutdown
或者强制关闭
pkill redis-server
7.设置开机启动
新建文件
vim /etc/systemd/system/redis.service
新增内容:
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
配置说明:
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
添加开机启动:
systemctl daemon-reload
systemctl enable redis
相关命令:
systemctl start redis.service 启动
systemctl stop redis.service 停止服务
systemctl restart redis.service 重新启动服务
systemctl list-units --type=service 查看所有已启动的服务
systemctl status redis.service 查看服务当前状态
systemctl enable redis.service 设置开机自启动
systemctl disable redis.service 停止开机自启动
8.集群部署
按照以上方式在其他机器上安装好redis
安装好后执行一下命令:
./redis-cli --cluster create 10.0.0.1:6379 10.0.0.2:6379 10.0.0.3:6379 -a 123456 --cluster-replicas 0
参数说明:
cluster-replicas 副本数量我这里设置0没有副本
-a 密码