Redis 源码下载与编译安装
获取软件包
官方下载地址为:https://redis.io/download
建议在 /usr/local/src 目录下执行下载操作。
wget http://download.redis.io/releases/redis-3.2.8.tar.gz
进行安装
将源码包解压至 /usr/local/src 目录中。
tar xzf redis-3.2.8.tar.gz
创建用于存放执行文件的目录 /usr/local/redis:
make dir /usr/local/redis
进入解压后的源码目录:
cd /usr/local/src/redis-3.2.8
随后执行 make 命令,将编译结果安装至 /usr/local/redis/ 目录。
make PREFIX=/usr/local/redis install
建立软链接
将程序创建软链接至 bin 目录,以便直接调用。
ln -s /usr/local/redis/bin/redis-cli /usr/local/bin/redis-cli
ln -s /usr/local/redis/bin/redis-sentinel /usr/local/bin/redis-sentinel
ln -s /usr/local/redis/bin/redis-server /usr/local/bin/redis-server
主从节点与哨兵配置文件修改
准备配置文件
复制配置文件,源码包中包含 sentinel.conf 和 redis.conf 文件,将其复制到 /etc/redis/ 目录下。若存在多个实例,建议重命名,例如本例中 Redis 端口为 7021,Sentinel 端口为 17021:
mkdir /etc/redis
cp /usr/local/src/redis-3.2.8/redis.conf /etc/redis/redis_6379.conf
cp /usr/local/src/redis-3.2.8/sentinel.conf /etc/redis/sentinel_26379.conf
配置 redis_master_6379.conf
需修改以下参数:
port 6379
daemonize yes
#requirepass 123456
#masterauth 123456
其中 daemonize 属性应设置为 yes,以启用后台运行模式。
配置 redis_slave_6380.conf:
需修改以下参数:
port 6380
daemonize yes
#requirepass yingjun
slaveof 192.168.248.128 6379
masterauth 123456
其他从节点的配置与此类似。
配置 sentinel_26379.conf
port 23791
daemonize yes
logfile "/var/log/sentinel_63791.log"
#master-1
sentinel monitor master-1 192.168.248.128 6379 2
#sentinel auth-pass master-1 yingjun
配置 sentinel_26380.conf
port 23780
daemonize yes
logfile "/var/log/sentinel_63780.log"
#master-1
sentinel monitor master-1 192.168.248.128 6379 2
#sentinel auth-pass master-1 yingjun
服务启动与进程验证
启动服务
按照特定顺序依次启动各项服务。
redis-server /etc/redis/redis_master_6379.conf
redis-server /etc/redis/redis_slave_6380.conf
redis-sentinel /etc/redis/sentinel_26379.conf
redis-sentinel /etc/redis/sentinel_26380.conf
检查进程是否均已成功启动。
[root@iZj6cqZ redis]# ps -ef | grep redis
root 10910 1 0 08:11 ? 00:00:00 redis-server 127.0.0.1:6379
root 10918 1 0 08:11 ? 00:00:00 redis-server 127.0.0.1:6380
root 10939 1 0 08:15 ? 00:00:00 redis-sentinel *:26379 [sentinel]
root 10944 1 0 08:15 ? 00:00:00 redis-sentinel *:26380 [sentinel]
root 10948 10851 0 08:15 pts/1 00:00:00 grep --color=auto redis
以上即为全部内容,希望能对您的学习有所帮助,欢迎继续支持本站。