centos7安裝redis3.2.1
一、下載:
官網下載安裝包,再上傳到服務器,解壓放到指定的目錄。
redis工具
yum install -y ruby
2.需要手工下載並安裝:
[seven@localhost download]$wget https://rubygems.global.ssl.fastly.net/gems/redis-3.2.1.gem
gem install -l ./redis-3.2.1.gem
[seven@localhost download]$ tar -zxvf redis-3.2.1.tar.gz
[seven@localhost download]$ mv redis-3.2.1 /opt/redis
二、安裝:(root)
1、*安裝redis前一定要先安裝gcc
如果安裝過程出現錯誤,重新解壓安裝
[root@localhost ~]# yum install gcc
2、開始安裝redis
[root@localhost ~]# cd /opt/redis/
3 、#使用make命令安裝
[root@localhost redis]# make
...
4、#最後出現這兩句話說明安裝成功
Hint: It's a good idea to run 'make test' ;
make[1]: 離開目錄“/opt/redis/src”
5.修改配置文件redis.conf (根據個人使用需求情況而定)
vi redis.conf
##修改配置文件中的下面選項
port 6371
daemonize yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 2000
appendonly yes
bind 10.10.0.101
save
6、啓動redis:
[root@localhost redis]# src/redis-server
7、#加&符號讓redis在後臺運行,然後Ctrl+C
[root@localhost redis]# src/redis-server &
8、啓動節點(根據個人使用需求情況而定)
redis-server /opt/redis/conf/redis-6371.conf > /opt/redis/logs/redis-6371.log 2>&1 &
redis-server /opt/redis/conf/redis-6372.conf > /opt/redis/logs/redis-6372.log 2>&1 &
redis-server /opt/redis/conf/redis-6373.conf > /opt/redis/logs/redis-6373.log 2>&1 &
redis-server /opt/redis/conf/redis-7371.conf > /opt/redis/logs/redis-7371.log 2>&1 &
redis-server /opt/redis/conf/redis-7372.conf > /opt/redis/logs/redis-7372.log 2>&1 &
redis-server /opt/redis/conf/redis-7373.conf > /opt/redis/logs/redis-7373.log 2>&1 &
8、使用redis客戶端測試
[root@localhost redis]# src/redis-cli
127.0.0.1:6371> set myKey helloworld
OK
127.0.0.1:6371> get myKey
"helloworld"
到這裏就安裝完了!
三、redis集羣設密碼
單個節點登入redis,通過config set + config rewrite命令逐個節點設置密碼
2.如果對集羣設置密碼,那麼requirepass和masterauth都需要設置,否則發生主從切換時,就會遇到授權問題,可以模擬並觀察日誌
3.各個節點的密碼都必須一致,否則Redirected就會失敗
設置密碼:
$ ./redis-cli -h 192.168.4.201 -p 6371
192.168.4.201:6371> config set masterauth passwd ###設置密碼
OK
192.168.4.201:6371> config set requirepass passwd ###設置密碼,和master密碼一致
OK
192.168.4.201:6371> config rewrite ###重新寫入到配置文件
OK
192.168.4.201:6371> exit
#######無需重啓redis,即時生效,配置完成######