[root@localhost ~]# yum install gcc gcc-c++ make -y #安裝環(huán)境包
[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 #關(guān)閉保護(hù)功能
#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 #設(shè)置群集超時(shí)時(shí)間為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快照文件,節(jié)點(diǎn)配置文件
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 #導(dǎo)入密鑰
[root@localhost 6379]# curl -sSL https://get.rvm.io | bash -s stable #尋找這個(gè)地址安裝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
主服務(wù)器安裝三塊網(wǎng)卡
192.168.136.229
192.168.136.232
192.168.136.231
從服務(wù)器安裝三塊網(wǎng)卡
192.168.136.185
192.168.136.233
192.168.136.234創(chuàng)新互聯(lián)公司專注骨干網(wǎng)絡(luò)服務(wù)器租用十多年,服務(wù)更有保障!服務(wù)器租用,聯(lián)通服務(wù)器托管 成都服務(wù)器租用,成都服務(wù)器托管,骨干網(wǎng)絡(luò)帶寬,享受低延遲,高速訪問。靈活、實(shí)現(xiàn)低成本的共享或公網(wǎng)數(shù)據(jù)中心高速帶寬的專屬高性能服務(wù)器。
[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 #出現(xiàn)這行輸入yes
三個(gè)節(jié)點(diǎn)master,三個(gè)副本節(jié)點(diǎn),彼此對(duì)應(yīng)關(guān)系是隨機(jī)的,但是是一主帶一從。
[root@localhost opt]# redis-cli -h 192.168.136.229 -p 6379 #登錄一臺(tái)主服務(wù)器229
192.168.136.229:6379> set name zhangsan #創(chuàng)建鍵值對(duì)
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 #登錄一臺(tái)從服務(wù)器234
192.168.136.234:6379> keys *
1) "name"
192.168.136.234:6379> get name #查看數(shù)據(jù),查看不了,會(huì)提示你數(shù)據(jù)存放在231服務(wù)器中
(error) MOVED 5798 192.168.136.231:6379
[root@localhost opt]# redis-cli -h 192.168.136.231 -p 6379 #登錄231服務(wù)器,就看到數(shù)據(jù)了
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方式建立鍵值對(duì)
(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 ##設(shè)置鍵的刪除時(shí)間5s
(integer) 1
192.168.136.229:6379> keys *
1) "person"
192.168.136.229:6379> keys *
(empty list or set)
新聞名稱:非關(guān)系數(shù)據(jù)庫——redis群集
文章源于:http://www.rwnh.cn/article16/jsddgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供、網(wǎng)站改版、虛擬主機(jī)、Google、網(wǎng)站營銷、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
移動(dòng)網(wǎng)站建設(shè)知識(shí)