一、安装说明
1、我们在192.168.110.56和192.168.110.63上分别搭建4个多实例
2、启动端口分别如下:
192.168.110.56:7000--7003
192.168.110.63:7004--7007
3、下面的多实例配置只针对一台服务器做说明,请自行配置安装另外一台
二、操作步骤
1、本地redis环境安装
安装方式一:(RPM包安装)
(1)请下载链接中的rpm包使用rpm -ivh直接安装即可
(2)链接:
https://raw.githubusercontent.com/bazingafraser/cv/master/rpm/redis-3.2.3-1.x86_64.rpm
安装方式二:(源码安装)
(1)安装依赖环境
[root@localhost ~]# yum install -y wget gcc make tcl
(2)下载源码包
[root@localhost ~]# wget http://download.redis.io/releases/redis-3.2.3.tar.gz
(3)编译安装redis
[root@localhost ~]# tar -xvzf redis-3.2.3.tar.gz
[root@localhost ~]# cd redis-3.2.3
[root@localhost ~]# make
[root@localhost ~]# make install prefix=/usr/local
(4)配置内核参数
[root@localhost ~]# vi /etc/sysctl.conf
在文件中写入
[root@localhost ~]# vm.overcommit_memory = 1
保存后更新配置
[root@localhost ~]# sysctl –p
2、创建多实例配置文件
[root@localhost ~]# mkdir /etc/redis
[root@localhost ~]# cd /etc/redis
A、以上操作请在两台机器上都进行操作
(1)192.168.110.56操作:
[root@localhost ~]# touch redis_{7000..7003}.conf
[root@localhost ~]# ls
redis_7000.conf redis_7001.conf redis_7002.conf redis_7003.conf
[root@localhost ~]#
(2)192.168.110.63操作:
[root@localhost ~]# touch redis_{7004..7007}.conf
B、配置文件中添加相同的配置文件,自行修改端口即可,配置内容如下:
port 7000 //端口7000,7001,7002,7003,7004,7005,7006,7007
bind 192.168.110.56 //默认ip为127.0.0.1 需要改为其他节点机器可访问的ip 否则创建集群时无法访问对应的端口,无法创建集群
daemonize yes //redis后台运行
pidfile /var/run/redis_7000.pid //pidfile文件对应7000,7001,7002,7003,7004,7005,7006,7007
cluster-enabled yes //开启集群
cluster-config-file nodes_7000.conf //集群的配置 配置文件首次启动自动生成 7000,7001,7002,7003,7004,7005,7006,7007
cluster-node-timeout 15000 //请求超时 默认15秒,可自行设置
appendonly no //aof日志开启 有需要就开启,它会每次写操作都记录一条日志
3、开启redis多实例进程
(1)192.168.110.56
启动:
[root@localhost ~]# /usr/bin/redis-server /etc/redis/redis_7000.conf
[root@localhost ~]# /usr/bin/redis-server /etc/redis/redis_7001.conf
[root@localhost ~]# /usr/bin/redis-server /etc/redis/redis_7002.conf
[root@localhost ~]# /usr/bin/redis-server /etc/redis/redis_7003.conf
查看进程:
[root@localhost ~]# ps -ef|grep cluster
root 14840 1 0 Mar14 ? 00:01:25 redis-server 192.168.110.56:7000 [cluster]
root 14851 1 0 Mar14 ? 00:01:26 redis-server 192.168.110.56:7003 [cluster]
root 14922 1 0 Mar14 ? 00:01:22 redis-server 192.168.110.56:7001 [cluster]
root 14927 1 0 Mar14 ? 00:01:23 redis-server 192.168.110.56:7002 [cluster]
root 15187 14371 0 11:32 pts/3 00:00:00 grep cluster
[root@localhost ~]#
(2)192.168.110.63
启动:
[root@localhost ~]# /usr/bin/redis-server /etc/redis/redis_7004.conf
[root@localhost ~]# /usr/bin/redis-server /etc/redis/redis_7005.conf
[root@localhost ~]# /usr/bin/redis-server /etc/redis/redis_7006.conf
[root@localhost ~]# /usr/bin/redis-server /etc/redis/redis_7007.conf
查看进程:
[root@localhost ~]# ps -ef|grep cluster
root 14840 1 0 Mar14 ? 00:01:25 redis-server 192.168.110.56:7004 [cluster]
root 14851 1 0 Mar14 ? 00:01:26 redis-server 192.168.110.56:7005 [cluster]
root 14922 1 0 Mar14 ? 00:01:22 redis-server 192.168.110.56:7006 [cluster]
root 14927 1 0 Mar14 ? 00:01:23 redis-server 192.168.110.56:7007 [cluster]
root 15187 14371 0 11:32 pts/3 00:00:00 grep cluster
[root@localhost ~]#
4、至此两台服务器上的redis多实例我们就安装完成了