1.服务器规划
服务器 | 端口 | 角色 |
---|---|---|
192.168.135.135 | 7001 | Master |
192.168.135.132 | 7002 | Master |
192.168.135.136 | 7003 | Master |
192.168.135.135 | 7004 | Slave |
192.168.135.132 | 7005 | Slave |
192.168.135.136 | 7006 | Slave |
2.环境准备
2.1 安装gcc
yum -y install gcc
2.2 安装tcl
#cd /usr/local
#wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
#tar -xzvf tcl8.6.1-src.tar.gz
#rm tcl8.6.1-src.tar.gz
#cd /usr/local/tcl8.6.1/unix/
#./configure
#make && make install
3.安装redis
3.1 安装
#cd /usr/local
#tar -zxvf redis-3.2.8.tar.gz
#rm redis-3.2.8.tar.gz
#cd redis-3.2.8
#make && make test && make install
3.2 配置
-
创建两个目录:/etc/redis(存放redis的配置文件),/var/redis/XXX端口号(存放redis的持久化文件)
#mkdir -p /etc/redis #mkdir -p /var/redis/? #mkdir -p /etc/redis-cluster #mkdir -p /var/log/redis
-
修改redis配置文件
#cp /usr/local/redis-3.2.8/redis.conf /etc/redis/?.conf #vi /etc/redis/?.conf port ? cluster-enabled yes #开启集群 #供cluster模式下的redis实例将集群状态保存在那里,包括集群中其他机器的信息,比如节点的上线和下限,故障转移 #不是我们去维护的,给它指定一个文件,让redis自己去维护的 cluster-config-file /etc/redis-cluster/node-?.conf #节点存活超时时长,超过一定时长,认为节点宕机,master宕机的话就会触发主备切换,slave宕机就不会提供服务 cluster-node-timeout 15000 daemonize yes pidfile /var/run/redis_?.pid dir /var/redis/? logfile /var/log/redis/?.log bind xxx.xxx.xxx.xxx appendonly yes
-
修改/etc/init.d/redis_?,支持开机自启动
#cp /usr/local/redis-3.2.8/utils/redis_init_script /etc/init.d/redis_? # vi /etc/init.d/redis_? #!/bin/sh # # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. # chkconfig: 2345 90 10 # description: Redis is a persistent key-value database
3.3 启动
--启动
#/etc/init.d/redis_? start
--确认redis进程是否启动
# ps -ef |grep redis
root 47453 1 0 16:29 ? 00:00:01 /usr/local/bin/redis-server 127.0.0.1:?
root 48678 2812 0 16:52 pts/2 00:00:00 grep --color=auto redis
--开启服务自启动
#chkconfig redis_? on
--加入开机自启服务
#chkconfig --add redis_?
4.创建集群
# cd /usr/local/
#yum erase ruby ruby-libs ruby-mode ruby-rdoc ruby-irb ruby-ri ruby-docs
# yum -y install zlib-devel curl-devel openssl-devel httpd-devel apr-devel apr-util-devel mysql-devel
# wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
# tar -zxvf ruby-2.3.1.tar.gz
# rm ruby-2.3.1.tar.gz
# cd ruby-2.3.1
# ./configure -prefix=/usr/local/ruby
# make && make install
# cp /usr/local/ruby/bin/ruby /usr/bin/ruby
# cp /usr/local/ruby/bin/gem /usr/bin/gem
#ruby -v
# cd /usr/local/
# wget http://rubygems.org/downloads/redis-3.3.0.gem
# gem install -l ./redis-3.3.0.gem
#cp /usr/local/redis-3.2.8/src/redis-trib.rb /usr/local/bin
#redis-trib.rb create --replicas 1 192.168.135.135:7001 192.168.135.132:7002 192.168.135.136:7003 192.168.135.135:7004 192.168.135.132:7005 192.168.135.136:7006
#发现失败了
#yum install -y ruby
#yum install -y rubygems
#gem install redis
#redis-trib.rb create --replicas 1 192.168.135.126:7001 192.168.135.129:7002 192.168.135.130:7003 192.168.135.126:7004 192.168.135.129:7005 192.168.135.130:7006
#redis-trib.rb check 192.168.135.126:7001
# redis-cli -c -h 192.168.135.126 -p 7001
192.168.135.135:7001> set a 1
-> Redirected to slot [15495] located at 192.168.135.136:7003
OK
192.168.135.136:7003> get a
"1"