Linux之Redis集群搭建

2018-06-16  本文已影响0人  掖莯圷

1、解压

[root@localhost soft]# mkdir /u01/redis

[root@localhost soft]# tar -zxvf redis-4.0.10.tar.gz -C  /u01/redis
[root@localhost soft]# cd /u01/redis
[root@localhost soft]# ll
[root@localhost redis]# ll
总用量 4
drwxrwxr-x. 6 root root  4096 6月  13 19:02 redis-4.0.10

2、ruby环境

yum install -y ruby rubygems

3、下载redis-3.3.3.gem

[root@localhost redis]# wget https://rubygems.org/downloads/redis-3.3.3.gem

4、安装redis

[root@localhost redis]# mkdir redis01
[root@localhost redis]# cd redis-4.0.10/
[root@localhost redis-4.0.10]#  make && make install  PREFIX=/u01/redis/redis01

5、配置文件

[root@localhost redis-4.0.10]# cd ../redis01/
[root@localhost redis01]# mkdir conf

拷贝 redis-4.0.10目录下的redis.conf到/u01/redis/redis01/conf下

[root@localhost redis01]# ll
总用量 0
drwxr-xr-x. 2 root root 134 6月  16 16:35 bin
drwxr-xr-x. 2 root root   6 6月  16 16:39 conf
[root@localhost redis01]# cp ../redis-4.0.10/redis.conf ./conf/

6、修改配置文件

#配置端口 
 port  7001    
#绑定本机ip 
 bind 192.168.163.149
pidfile /var/run/redis_7001.pid
#开启集群 
cluster-enabled  yes 
#后台启动
daemonize yes
#集群的配置 
cluster-config-file /u01/redis/redis01/conf/nodes_7001.conf
#aof日志开启  本次使用aof
appendonly  yes
#禁用rdb 注释掉save
#save 900 1
#save 300 10
#save 60 10000

7、复制redis01

[root@localhost redis]# cp -r redis01 redis02
[root@localhost redis]# cp -r redis01 redis03
[root@localhost redis]# cp -r redis01 redis04
[root@localhost redis]# cp -r redis01 redis05
[root@localhost redis]# cp -r redis01 redis06

修改配置文件端口分别为7002、7003...
其他参考第6步
8、 安装Ruby Redis工具包:

[root@localhost redis]# gem install -l ./redis-3.3.3.gem

9、启动

[root@localhost redis]# vim startredis.sh

内容如下

cd /u01/redis/redis01
./bin/redis-server ./conf/redis.conf

cd /u01/redis/redis02
./bin/redis-server ./conf/redis.conf

cd /u01/redis/redis03
./bin/redis-server ./conf/redis.conf

cd /u01/redis/redis04
./bin/redis-server ./conf/redis.conf

cd /u01/redis/redis05
./bin/redis-server ./conf/redis.conf

cd /u01/redis/redis06
./bin/redis-server ./conf/redis.conf

修改权限

[root@localhost redis]# chmod 755 startredis.sh
[root@localhost redis]# ./startredis.sh

10、启动集群
复制 redis-trib.rb

[root@localhost redis]# cp redis-4.0.10/src/redis-trib.rb ./
[root@localhost redis]# ll
总用量 168
drwxr-xr-x. 4 root root    51 6月  16 17:07 redis01
drwxr-xr-x. 4 root root    51 6月  16 17:08 redis02
drwxr-xr-x. 4 root root    51 6月  16 17:08 redis03
drwxr-xr-x. 4 root root    51 6月  16 17:08 redis04
drwxr-xr-x. 4 root root    51 6月  16 17:08 redis05
drwxr-xr-x. 4 root root    51 6月  16 17:08 redis06
-rw-r--r--. 1 root root 92672 1月  24 2017 redis-3.3.3.gem
drwxrwxr-x. 6 root root  4096 6月  13 19:02 redis-4.0.10
-rwxr-xr-x. 1 root root 65991 6月  16 17:17 redis-trib.rb
-rwxr-xr-x. 1 root root   522 6月  16 17:04 startredis.sh

创建集群节点

./redis-trib.rb create --replicas 1 192.168.163.149:7001 192.168.163.149:7002 192.168.163.149:7003 192.168.163.149:7004 192.168.163.149:7005 192.168.163.149:7006
上一篇 下一篇

猜你喜欢

热点阅读