搭建redis集群及安装ESXI6.7

1、安装配置redis的cluster集群

1.1 规划

操作系统:CentOS Linux release 7.6.1810 (Core)
master:c1 c2 c3
slave:c4 c5 c6

1.2 在各个虚拟机安装redis

[ src]#wget http://download.redis.io/releases/redis-3.2.12.tar.gz
[ src]#tar xf redis-3.2.12.tar.gz
[ src]#cd redis-3.2.12
[ src]#make
[ src]#cp redis.conf /usr/local/redis/etc/

1.3 修改每个Redis的配置文件

cluster-enabled yes #去掉注释
#bind 127.0.0.1     #注释这一行
daemonize yes       #把no改成yes
requirepass 123456
[ src]#/usr/local/bin/redis-server /usr/local/etc/redis.conf  #启动redis

1.4 解决ruby版本问题

[ src]# pwd
/usr/local/src
[ src]# wget https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.5.tar.gz
[ src]# tar xf ruby-2.5.5.tar.gz 
[ src]# cd ruby-2.5.5/
[ ruby-2.5.5]# ./configure
[ ruby-2.5.5]# make -j 2
[ ruby-2.5.5]# make install
[ ruby-2.5.5]# gem install redis

1.5 创建redis集群

[ src]# ./redis-trib.rb create --replicas 1 10.0.1.242:6379 10.0.1.243:6379 10.0.1.244:6379 10.0.1.245:6379 10.0.1.246:6379 10.0.1.247:6379

1.6 验证集群状态

[ src]# /usr/local/bin/redis-cli -h 10.0.1.245 -a 123456
10.0.1.245:6379> INFO Replication
# Replication
role:slave
master_host:10.0.1.242
master_port:6379
master_link_status:down  ###状态要为up
master_last_io_seconds_ago:-1
master_sync_in_progress:0
slave_repl_offset:1
master_link_down_since_seconds:1595772946
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

1.7 分别设置masterauth密码

[ src]# /usr/local/bin/redis-cli -h 10.0.1.245 -a 123456
10.0.1.245:6379> CONFIG SET masterauth 123456
OK
10.0.1.245:6379> quit
[ src]# /usr/local/bin/redis-cli -h 10.0.1.246 -a 123456
10.0.1.246:6379> CONFIG SET masterauth 123456
OK
10.0.1.246:6379> quit
[ src]# /usr/local/bin/redis-cli -h 10.0.1.247 -a 123456
10.0.1.247:6379> CONFIG SET masterauth 123456
OK
10.0.1.247:6379> quit

1.8 验证slave状态

[ src]# /usr/local/bin/redis-cli -h 10.0.1.245 -a 123456
10.0.1.245:6379> INFO Replication
# Replication
role:slave
master_host:10.0.1.242
master_port:6379
master_link_status:up
master_last_io_seconds_ago:-1
master_sync_in_progress:0
slave_repl_offset:1
master_link_down_since_seconds:1595772946
slave_priority:100
slave_read_only:1
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

1.9 验证master状态

[ src]# /usr/local/bin/redis-cli -h 10.0.1.242 -a 123456
10.0.1.242:6379> INFO Replication
# Replication
role:master
connected_slaves:1
slave0:ip=10.0.1.245,port=6379,state=online,offset=309,lag=1
master_repl_offset:309
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:308

1.10 验证集群状态

[ src]# /usr/local/bin/redis-cli -h 10.0.1.242 -a 123456
10.0.1.242:6379> CLUSTER INFO
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_sent:1507
cluster_stats_messages_received:1507

1.11 验证集群写入key

10.0.1.242:6379> set key1 value1    #经过算法计算,当前key的槽位需要写入指定的node
(error) MOVED 9189 10.0.1.243:6379  #槽位不在当前node所以无法写入
10.0.1.242:6379> 

[ bin]# ./redis-cli -h 10.0.1.243 -a 123456  #指定的node就可以写入
10.0.1.243:6379> set key1 value1
OK
10.0.1.243:6379>
[ bin]# ./redis-cli -h 10.0.1.246 -a 123456
10.0.1.246:6379> KEYS *
1) "key1"
10.0.1.246:6379>

2、安装配置memcached高可用

2.1 部署repcached

[ src]# pwd
/usr/local/src
[ memcached-1.2.8-repcached-2.2.1]# yum install libevent libevent-devel -y
[ src]# wget https://kumisystems.dl.sourceforge.net/project/repcached/repcached/2.2.1-1.2.8/memcached-1.2.8-repcached-2.2.1.tar.gz
[ src]# tar xvf memcached-1.2.8-repcached-2.2.1.tar.gz
[ memcached-1.2.8-repcached-2.2.1]# ./configure --prefix=/usr/local/repcached --enable-replication
[ memcached-1.2.8-repcached-2.2.1]# make
make  all-recursive
make[1]: Entering directory `/usr/local/src/memcached-1.2.8-repcached-2.2.1‘
Making all in doc
make[2]: Entering directory `/usr/local/src/memcached-1.2.8-repcached-2.2.1/doc‘
make[2]: Nothing to be done for `all‘.
make[2]: Leaving directory `/usr/local/src/memcached-1.2.8-repcached-2.2.1/doc‘
make[2]: Entering directory `/usr/local/src/memcached-1.2.8-repcached-2.2.1‘
gcc -DHAVE_CONFIG_H -I.  -DNDEBUG   -g -O2 -MT memcached-memcached.o -MD -MP -MF .deps/memcached-memcached.Tpo -c -o memcached-memcached.o `test -f ‘memcached.c‘ || echo ‘./‘`memcached.c
memcached.c: In function ‘add_iov’:
memcached.c:697:30: error: ‘IOV_MAX’ undeclared (first use in this function)
         if (m->msg_iovlen == IOV_MAX ||
                              ^
memcached.c:697:30: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [memcached-memcached.o] Error 1
make[2]: Leaving directory `/usr/local/src/memcached-1.2.8-repcached-2.2.1‘
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/memcached-1.2.8-repcached-2.2.1‘
make: *** [all] Error 2
[ memcached-1.2.8-repcached-2.2.1]# vim memcached.c 
56 #ifndef IOV_MAX 
57 #if defined(__FreeBSD__) || defined(__APPLE__) 
58 # define IOV_MAX 1024 
59 #endif 
60 #endif 
改为如下内容: 
55 /* FreeBSD 4.x doesn‘t have IOV_MAX exposed. */ 
56 #ifndef IOV_MAX 
57 # define IOV_MAX 1024 
58 #endif
[ memcached-1.2.8-repcached-2.2.1]# make && make install
[ memcached-1.2.8-repcached-2.2.1]# /usr/local/repcached/bin/memcached -d -m 2048 -p 11211 -u root -c 2048 -x 10.0.1.245 -X 16000
[ memcached-1.2.8-repcached-2.2.1]# ss -tnl
State      Recv-Q Send-Q    Local Address:Port                   Peer Address:Port              
LISTEN     0      128                   *:11211                             *:*                  
LISTEN     0      128                   *:16000                             *:*          

LISTEN     0      128                  :::11211                            :::*          

LISTEN     0      128                  :::22                               :::*                  
LISTEN     0      100                 ::1:25                               :::*
另一个虚拟机按同样步骤安装memcached,启动命令如下
[ memcached-1.2.8-repcached-2.2.1]# /usr/local/repcached/bin/memcached -d -m 2048 -p 11211 -u root -c 2048 -x 10.0.1.246 -X 16000

2.2 连接到memcache验证数据

[ src]# telnet 10.0.1.246 11211
Trying 10.0.1.246...
Connected to 10.0.1.246.
Escape character is ‘^]‘.
set name 0 0 4
jack
STORED
get name
VALUE name 0 4
jack
END
quit
Connection closed by foreign host.
###检查数据是否同步
[ src]# telnet 10.0.1.245 11211
Trying 10.0.1.245...
Connected to 10.0.1.245.
Escape character is ‘^]‘.
get name
VALUE name 0 4
jack
END
quit
Connection closed by foreign host

3、安装vmware esxi

3.1 安装VMware Workstation

步骤跟安装普通软件一样,这里不再详细展开

3.2 创建虚拟机
搭建redis集群及安装ESXI6.7
搭建redis集群及安装ESXI6.7
搭建redis集群及安装ESXI6.7
搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7
搭建redis集群及安装ESXI6.7
搭建redis集群及安装ESXI6.7
搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7

3.3 安装esxi6.7
搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7搭建redis集群及安装ESXI6.7

相关推荐