您好,登錄后才能下訂單哦!
[root@localhost ~]# yum install gcc gcc-c++ make -y #安裝環境包
[root@localhost ~]# mkdir /abc
[root@localhost ~]# mount.cifs //192.168.100.25/redis /abc/ 掛載
Password for root@//192.168.100.25/redis:
[root@localhost ~]# cd /abc/
[root@localhost abc]# ls
redis-5.0.7.tar.gz
[root@localhost abc]# tar zxvf redis-5.0.7.tar.gz -C /opt/ #解壓到opt底下
[root@localhost abc]# cd /opt/redis-5.0.7/
make
[root@localhost redis-5.0.7]# make PREFIX=/usr/local/redis install #安裝
[root@localhost redis-5.0.7]# ln -s /usr/local/redis/bin/* /usr/local/bin/ #做軟連接
[root@localhost redis-5.0.7]# cd /opt/redis-5.0.7/utils/
[root@localhost utils]# ./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379]
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] /usr/local/redis/bin/redis-server
[root@localhost utils]# vim /etc/redis/6379.conf
#70 bind 127.0.0.1
70 #bind 127.0.0.1
#89 protected-mode yes
89 protected-mode no #關閉保護功能
#833 # cluster-enabled yes
833 cluster-enabled yes #開啟群集功能
#841 # cluster-config-file nodes-6379.conf
841 cluster-config-file nodes-6379.conf #開啟群集功能配置文件
#847 # cluster-node-timeout 15000
847 cluster-node-timeout 15000 #設置群集超時時間為15000秒
#700 appendonly no
700 appendonly yes #開啟AOF支持
[root@localhost redis]# /etc/init.d/redis_6379 restart #開起redis
Stopping ...
Waiting for Redis to shutdown ...
Redis stopped
Starting Redis server...
[root@localhost utils]# cd /var/lib/redis/
[root@localhost redis]# cd 6379/
[root@localhost 6379]# ls
appendonly.aof dump.rdb nodes-6379.conf
#aof配置文件,rdb快照文件,節點配置文件
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 #導入密鑰
[root@localhost 6379]# curl -sSL https://get.rvm.io | bash -s stable #尋找這個地址安裝RVM
[root@localhost 6379]# cd /opt/
[root@localhost opt]# ls
redis-5.0.7 rh
[root@localhost opt]# vim abc.sh #rvm的腳本很長
[root@localhost opt]# ls
abc.sh redis-5.0.7 rh
[root@localhost opt]# chmod +x abc.sh
[root@localhost opt]# ls
abc.sh redis-5.0.7 rh
[root@localhost opt]# source /etc/profile.d/rvm.sh
[root@localhost opt]# rvm list known #查看rvm安裝的版本
[root@localhost opt]# rvm install 2.4.1 #安裝rvm2.4.1版本
[root@localhost opt]# rvm use 2.4.1 #使用rvm
Using /usr/local/rvm/gems/ruby-2.4.1
[root@localhost opt]# ruby -v #查看ruby的版本
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
[root@localhost opt]# gem install redis #安裝redis
主服務器安裝三塊網卡
192.168.136.229
192.168.136.232
192.168.136.231
從服務器安裝三塊網卡
192.168.136.185
192.168.136.233
192.168.136.234
[root@localhost opt]# systemctl restart network
[root@localhost opt]# systemctl stop firewalld.service
[root@localhost opt]# setenforce 0
[root@localhost 6379]# /etc/init.d/redis_6379 restart #重啟redis
redis-cli --cluster create 192.168.136.229:6379 192.168.136.232:6379 192.168.136.231:6379 192.168.136.185:6379 192.168.136.233:6379 192.168.136.234:6379 --cluster-replicas 1
Can I set the above configuration? (type 'yes' to accept): yes #出現這行輸入yes
三個節點master,三個副本節點,彼此對應關系是隨機的,但是是一主帶一從。
[root@localhost opt]# redis-cli -h 192.168.136.229 -p 6379 #登錄一臺主服務器229
192.168.136.229:6379> set name zhangsan #創建鍵值對
OK
192.168.136.229:6379> keys * #查看所有鍵
1) "name"
192.168.136.229:6379> get name #查看值
"zhangsan"
192.168.136.229:6379> quit
[root@localhost opt]# redis-cli -h 192.168.136.234 -p 6379 #登錄一臺從服務器234
192.168.136.234:6379> keys *
1) "name"
192.168.136.234:6379> get name #查看數據,查看不了,會提示你數據存放在231服務器中
(error) MOVED 5798 192.168.136.231:6379
[root@localhost opt]# redis-cli -h 192.168.136.231 -p 6379 #登錄231服務器,就看到數據了
192.168.136.231:6379> keys *
1) "name"
192.168.136.231:6379> get name
"zhangsan"
[root@master opt]# redis-cli -h 192.168.136.229 -p 6379
192.168.136.229:6379> hset person age 20 ##用hash方式建立鍵值對
(integer) 1
192.168.136.229:6379> hset person name lisi
(integer) 1
192.168.136.229:6379> keys *
1) "person"
192.168.136.229:6379> hget person age ##獲取鍵的值
"20"
192.168.136.229.128:6379> expire person 5 ##設置鍵的刪除時間5s
(integer) 1
192.168.136.229:6379> keys *
1) "person"
192.168.136.229:6379> keys *
(empty list or set)
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。