redis集羣、memcached高可用、vmware esxi

部署redis集羣

注意:master和slave不能是同一臺服務器的兩個端口
環境:
三臺服務器:A、B、C
6379:master
6380:slave
A:IP:192.168.100.11,port:6379、6380
B:IP:192.168.100.12,port:6379、6380
C:IP:192.168.100.11,port:6379、6380

編譯安裝

#安裝redis依賴的環境包
[root@localhost soft]# yum -y install gcc gcc-c++ bzip2
[root@localhost soft]# tar -jxvf jemalloc-5.2.0.tar.bz2
[root@localhost soft]# cd jemalloc-5.2.0
[root@localhost jemalloc-5.2.0]# ./configure --prefix=/usr/local/jemalloc
[root@localhost jemalloc-5.2.0]# make -j 2 && make install

#編譯安裝redis並設置軟連接
[root@localhost soft]# tar -zxvf redis-5.0.5.tar.gz
[root@localhost soft]# cd redis-5.0.5
[root@localhost redis-5.0.5]# make MALLOC=jemalloc
[root@localhost redis-5.0.5]# make PREFIX=/data/tools/redis-5.0.5 install
[root@localhost redis-5.0.5]# mkdir /data/tools/redis-5.0.5/conf
[root@localhost redis-5.0.5]# cp redis.conf /data/tools/redis-5.0.5/conf/redis_6379.conf
[root@localhost ~]# ln -sv /data/tools/redis-5.0.5 /data/tools/redis
‘/data/tools/redis’ -> ‘/data/tools/redis-5.0.5’
[root@localhost ~]# ln -sv /data/tools/redis/bin/redis-* /usr/bin/
‘/usr/bin/redis-benchmark’ -> ‘/data/tools/redis/bin/redis-benchmark’
‘/usr/bin/redis-check-aof’ -> ‘/data/tools/redis/bin/redis-check-aof’
‘/usr/bin/redis-check-rdb’ -> ‘/data/tools/redis/bin/redis-check-rdb’
‘/usr/bin/redis-cli’ -> ‘/data/tools/redis/bin/redis-cli’
‘/usr/bin/redis-sentinel’ -> ‘/data/tools/redis/bin/redis-sentinel’
‘/usr/bin/redis-server’ -> ‘/data/tools/redis/bin/redis-server’

redis_6379.conf、redis_6380.conf配置(兩份配置,除了端口其他都一樣)

#redis_6379.conf
bind 0.0.0.0
daemonize yes
pidfile /data/tools/redis/run/redis_6379.pid
logfile "/data/tools/redis/logs/redis_6379.log"
stop-writes-on-bgsave-error no
dbfilename redis6379_dump.rdb
dir /data/tools/redis/data/
requirepass 123456
#REPLICATION
masterauth 123456
maxmemory 1G
#CLUSTER
cluster-enabled yes
cluster-config-file /data/tools/redis/conf/nodes-6379.conf
cluster-node-timeout 15000
cluster-replica-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes

添加服務自啓動

#創建redis啓動用戶
[root@localhost ~]# groupadd  -g 1000 redis && useradd -u 1000 -g 1000 redis -s /sbin/nologin
[root@localhost ~]# mkdir -pv /data/tools/redis/{conf,logs,data,run} 
mkdir: created directory ‘/data/tools/redis/logs’
mkdir: created directory ‘/data/tools/redis/data’
mkdir: created directory ‘/data/tools/redis/run’
[root@localhost ~]# chown redis.redis -R  /data/tools/redis/

#添加服務自啓動redis6379.service、redis6380.service(除了配置文件名字不一樣,其他一樣)
[root@localhost ~]# cat /usr/lib/systemd/system/redis6379.service 
Description=Redis persistent key-value database 
After=network.target 
After=network-online.target 
Wants=network-online.target 

[Service] 
ExecStart = /data/tools/redis/bin/redis-server /data/tools/redis/conf/redis_6379.conf --supervised systemd 
ExecReload = /bin/kill -s HUP $MAINPID  
ExecStop = /bin/kill -s QUIT $MAINPID 
Type = notify 
User = redis 
Group = redis 
RuntimeDirectory = redis 
RuntimeDirectoryMode = 0755 

[Install] 
WantedBy=multi-user.target

#設置開機啓動並啓動服務,每臺服務器啓動6379和6380端口
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl enable --now redis6379
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.

驗證服務

#6379、6380爲客戶端服務端口
#16379、16380爲服務端服務端口
[root@localhost ~]# ss -tln
State      Recv-Q Send-Q                                      Local Address:Port                                                     Peer Address:Port              
LISTEN     0      128                                                     *:6379                                                                *:*                  
LISTEN     0      128                                                     *:6380                                                                *:*                  
LISTEN     0      128                                                     *:22                                                                  *:*                  
LISTEN     0      128                                                     *:16379                                                               *:*                  
LISTEN     0      128                                                     *:16380                                                               *:*                  
LISTEN     0      128                                                    :::22                                                                 :::* 

創建集羣

[root@localhost ~]# redis-cli -a 123456 --cluster create 192.168.100.11:6379 192.168.100.11:6380 192.168.100.12:6379 192.168.100.12:6380 192.168.100.13:6379 192.168.100.13:6380  --cluster-replicas 1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.100.12:6380 to 192.168.100.11:6379
Adding replica 192.168.100.13:6380 to 192.168.100.12:6379
Adding replica 192.168.100.11:6380 to 192.168.100.13:6379
M: 6ea21fa0bd64dc75c065e7d0da7c8c3bbdfbb200 192.168.100.11:6379
   slots:[0-5460] (5461 slots) master
S: 047b0910f7268161e25199ac1e797a5ea1fe1e59 192.168.100.11:6380
   replicates 5894c491e89d893ba90deb85b282dc008d4e16c6
M: 1962b458826fef76e3b92a06e94dd82e4285854a 192.168.100.12:6379
   slots:[5461-10922] (5462 slots) master
S: 9be6ef428dda8b0fef89e2bb7bdee4de56cb8296 192.168.100.12:6380
   replicates 6ea21fa0bd64dc75c065e7d0da7c8c3bbdfbb200
M: 5894c491e89d893ba90deb85b282dc008d4e16c6 192.168.100.13:6379
   slots:[10923-16383] (5461 slots) master
S: 60bae29c47b0265fbf0f873b593aee62b7d4e215 192.168.100.13:6380
   replicates 1962b458826fef76e3b92a06e94dd82e4285854a
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
...
>>> Performing Cluster Check (using node 192.168.100.11:6379)
M: 6ea21fa0bd64dc75c065e7d0da7c8c3bbdfbb200 192.168.100.11:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 047b0910f7268161e25199ac1e797a5ea1fe1e59 192.168.100.11:6380
   slots: (0 slots) slave
   replicates 5894c491e89d893ba90deb85b282dc008d4e16c6
S: 60bae29c47b0265fbf0f873b593aee62b7d4e215 192.168.100.13:6380
   slots: (0 slots) slave
   replicates 1962b458826fef76e3b92a06e94dd82e4285854a
M: 1962b458826fef76e3b92a06e94dd82e4285854a 192.168.100.12:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 5894c491e89d893ba90deb85b282dc008d4e16c6 192.168.100.13:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 9be6ef428dda8b0fef89e2bb7bdee4de56cb8296 192.168.100.12:6380
   slots: (0 slots) slave
   replicates 6ea21fa0bd64dc75c065e7d0da7c8c3bbdfbb200
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

檢查集羣

[root@localhost ~]# redis-cli --cluster info 192.168.100.11:6379 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.100.11:6379 (6ea21fa0...) -> 0 keys | 5461 slots | 1 slaves.
192.168.100.12:6379 (1962b458...) -> 0 keys | 5462 slots | 1 slaves.
192.168.100.13:6379 (5894c491...) -> 0 keys | 5461 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.

[root@localhost ~]# redis-cli --cluster check 192.168.100.11:6379 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.100.11:6379 (6ea21fa0...) -> 0 keys | 5461 slots | 1 slaves.
192.168.100.12:6379 (1962b458...) -> 0 keys | 5462 slots | 1 slaves.
192.168.100.13:6379 (5894c491...) -> 0 keys | 5461 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.100.11:6379)
M: 6ea21fa0bd64dc75c065e7d0da7c8c3bbdfbb200 192.168.100.11:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 60bae29c47b0265fbf0f873b593aee62b7d4e215 192.168.100.13:6380
   slots: (0 slots) slave
   replicates 1962b458826fef76e3b92a06e94dd82e4285854a
S: 047b0910f7268161e25199ac1e797a5ea1fe1e59 192.168.100.11:6380
   slots: (0 slots) slave
   replicates 5894c491e89d893ba90deb85b282dc008d4e16c6
M: 1962b458826fef76e3b92a06e94dd82e4285854a 192.168.100.12:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 9be6ef428dda8b0fef89e2bb7bdee4de56cb8296 192.168.100.12:6380
   slots: (0 slots) slave
   replicates 6ea21fa0bd64dc75c065e7d0da7c8c3bbdfbb200
M: 5894c491e89d893ba90deb85b282dc008d4e16c6 192.168.100.13:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

可以看到,至此redis的cluster創建完成。

memcached高可用

通過yum 安裝與氣動

yum -y install memcached

#cat /etc/sysconfig/memcached
PORT="11211" #監聽端口
PORT="memcached" #氣動用戶
MAXCONN="1024" 最大連接數
CACHESIZE="1024" #最大使用內存
OPTIONS="" 其他選項

#氣動
systemctl start memcached

#驗證服務
[root@localhost ~]# ps -ef|grep memcached
memcach+  10767      1  0 13:22 ?        00:00:00 /usr/bin/memcached -u memcached -p 11211 -m 64 -c 1024
root      10775   9419  0 13:22 pts/0    00:00:00 grep --color=auto memcached
[root@localhost ~]# netstat -tunlpa|grep memcached
tcp        0      0 0.0.0.0:11211           0.0.0.0:*               LISTEN      10767/memcached     
tcp6       0      0 :::11211                :::*                    LISTEN      10767/memcached     
udp        0      0 0.0.0.0:11211           0.0.0.0:*                           10767/memcached     
udp6       0      0 :::11211                :::*                                10767/memcached

#部署repcached實現雙主
[root@localhost ~]# yum -y install lievent libevent-devel
[root@localhost ~]# mkdir -p /data/soft
[root@localhost ~]# cd /data/soft/
[root@localhost soft]# tar -zxvf memcached-1.2.8-repcached-2.2.1.tar.gz 
[root@localhost memcached-1.2.8-repcached-2.2.1]# ./configure \
--prefix=/data/tools/repcached --enable-replication

#報錯
[root@localhost memcached-1.2.8-repcached-2.2.1]# make && make install
make  all-recursive
make[1]: Entering directory `/data/soft/memcached-1.2.8-repcached-2.2.1'
Making all in doc
make[2]: Entering directory `/data/soft/memcached-1.2.8-repcached-2.2.1/doc'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/data/soft/memcached-1.2.8-repcached-2.2.1/doc'
make[2]: Entering directory `/data/soft/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 `/data/soft/memcached-1.2.8-repcached-2.2.1'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/data/soft/memcached-1.2.8-repcached-2.2.1'
make: *** [all] Error 2
#解決,刪除57和60行這個
[root@localhost memcached-1.2.8-repcached-2.2.1]# vim memcached.c
#if defined(__FreeBSD__) || defined(__APPLE__)
#endif

#驗證是否可執行,-x爲對方主的ip地址,-X爲數據庫同步端口
#server1操作
[root@localhost ~]# /data/tools/repcached/bin/memcached -d -m 11211 -u root -c 2048 -x 192.168.100.12 -X 16000
[root@localhost ~]# ss -tln
State       Recv-Q Send-Q                                      Local Address:Port                                                     Peer Address:Port              
LISTEN      0      128                                                     *:11211                                                               *:*                  
LISTEN      0      128                                                     *:6379                                                                *:*                  
LISTEN      0      128                                                     *:6380                                                                *:*                  
LISTEN      0      128                                                     *:22                                                                  *:*                  
LISTEN      0      128                                                     *:16379                                                               *:*                  
LISTEN      0      128                                                     *:16380                                                               *:*                  
LISTEN      0      128                                                     *:16000                                                               *:*                  
LISTEN      0      128                                                    :::11211                                                              :::*                  
LISTEN      0      128                                                    :::22                                                                 :::*  

#server2操作
[root@localhost ~]# /data/tools/repcached/bin/memcached -d -m 11211 -u root -c 2048 -x 192.168.100.11 -X 16000
[root@localhost ~]# ss -tln
State       Recv-Q Send-Q                                      Local Address:Port                                                     Peer Address:Port              
LISTEN      0      128                                                     *:11211                                                               *:*                  
LISTEN      0      128                                                     *:6379                                                                *:*                  
LISTEN      0      128                                                     *:6380                                                                *:*                  
LISTEN      0      128                                                     *:22                                                                  *:*                  
LISTEN      0      128                                                     *:16379                                                               *:*                  
LISTEN      0      128                                                     *:16380                                                               *:*                  
LISTEN      0      128                                                     *:16000                                                               *:*                  
LISTEN      0      128                                                    :::11211                                                              :::*                  
LISTEN      0      128                                                    :::22    

#驗證
#server1操作,連接server2的服務器
[root@localhost ~]# yum -y install telnet
[root@localhost ~]# telnet 192.168.100.11 11211
Trying 192.168.100.11...
Connected to 192.168.100.11.
Escape character is '^]'.
set name 0 0 4
jack
STORED
stored
ERROR
get name
VALUE name 0 4
jack
END
quit

#server1上查看數據是否同步
[root@localhost ~]# telnet 192.168.100.11 11211
Trying 192.168.100.11...
Connected to 192.168.100.11.
Escape character is '^]'.
get name
END
set name 0 0 4
jack
STORED
get name
VALUE name 0 4
jack
END
quit
Connection closed by foreign host.
[root@localhost ~]# telnet 192.168.100.12 11211
Trying 192.168.100.12...
Connected to 192.168.100.12.
Escape character is '^]'.
get name
VALUE name 0 4
jack
END
quit
Connection closed by foreign host.

可以看到memcached高可用正常

安裝 Vmware esxi

基於vmware workstation虛擬機運行vmware esxi,安裝兩臺esxi服務器,IP地址分爲是192.168.126.128/129

稍後指定操作系統
redis集羣、memcached高可用、vmware esxi
redis集羣、memcached高可用、vmware esxi
選擇esxi版本(因爲我們裝的是7.0沒有,所以就選擇了6.x)
redis集羣、memcached高可用、vmware esxi
選擇保存的位置
redis集羣、memcached高可用、vmware esxi
選擇磁盤容量
redis集羣、memcached高可用、vmware esxi
自定義硬件
redis集羣、memcached高可用、vmware esxi
配置內存redis集羣、memcached高可用、vmware esxi
配置處理器數量,開啓虛擬化(不開啓後期會報錯)
redis集羣、memcached高可用、vmware esxi
選擇鏡像
redis集羣、memcached高可用、vmware esxi
redis集羣、memcached高可用、vmware esxi
開始安裝esxi節點
加載內核
redis集羣、memcached高可用、vmware esxi
加載驅動
redis集羣、memcached高可用、vmware esxi
確認安裝redis集羣、memcached高可用、vmware esxi
同意協議,按F11
redis集羣、memcached高可用、vmware esxi
掃描可用硬盤redis集羣、memcached高可用、vmware esxi
選擇硬盤並安裝
redis集羣、memcached高可用、vmware esxi
redis集羣、memcached高可用、vmware esxi
設置管理員密碼
redis集羣、memcached高可用、vmware esxi
開始安裝
redis集羣、memcached高可用、vmware esxi
安裝過程中
redis集羣、memcached高可用、vmware esxi
安裝完成
redis集羣、memcached高可用、vmware esxi
配置IP地址:將服務器配置爲靜態IP地址,當前爲DHCP獲取的IP地址。
配置界面進程登錄,按F2進行登錄
redis集羣、memcached高可用、vmware esxi
登錄服務器
輸入安裝過程中管理員密碼,管理員賬號爲root,密碼爲安裝過程中設置的密碼
redis集羣、memcached高可用、vmware esxi
配置靜態IP地址:
當前爲DHCP獲取的IP地址
redis集羣、memcached高可用、vmware esxi
redis集羣、memcached高可用、vmware esxi
更改IP地址爲靜態IP地址、配置DNS並重啓網絡服務
redis集羣、memcached高可用、vmware esxi
輸入Y保存
redis集羣、memcached高可用、vmware esxi
至此vmware esxi安裝和配置基本完成。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章