標籤:sed lazy ace 連接埠 normal 其它 單節點 執行 tag
單點安裝
wget http://download.redis.io/releases/redis-4.0.2.tar.gztar zxvf redis-4.0.1.tar.gz -C /usr/localcd /usr/local/redis-4.0.2makemake testmake PREFIX=/usr/local/redis installcd /usr/local/redismkdir conf log datacd /usr/local/redis/confcp /usr/local/redis-4.0.2/redis.conf .
修改核心參數:
echo ‘vm.overcommit_memory = 1‘ >> /etc/sysctl.confsysctl -p
修改設定檔
主要修改以下值
daemonize no改為daemonize yes,以守護進程模式運行bind 127.0.0.0改為bind 0.0.0.0,監聽本機所有連接埠
以下為一個cluster node redis.conf設定檔
[[email protected] src]# cat /usr/local/redis-cluster-shijing2/redis/conf/7379.confbind 0.0.0.0protected-mode yesport 7379requirepass [email protected]masterauth [email protected]maxmemory 4000000000tcp-backlog 511timeout 0tcp-keepalive 300daemonize yessupervised nopidfile "/var/run/redis_7379.pid"loglevel noticelogfile "../log/redis_7379.log"databases 16always-show-logo yessave 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename "dump.rdb"dir "../data"slave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100lazyfree-lazy-eviction nolazyfree-lazy-expire nolazyfree-lazy-server-del noslave-lazy-flush noappendonly noappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yesaof-use-rdb-preamble nolua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yescluster-enabled yescluster-config-file "7379.conf"
cluster搭建1.將單點redis.conf複製多份
[[email protected] conf]# pwd/usr/local/redis-cluster-shijing2/redis/conf[[email protected] conf]# lltotal 28-rw-r--r-- 1 root root 1362 May 31 16:52 7379.conf-rw-r--r-- 1 root root 1362 May 31 16:52 7380.conf-rw-r--r-- 1 root root 1362 May 31 16:53 7381.conf-rw-r--r-- 1 root root 1362 May 31 16:53 7382.conf-rw-r--r-- 1 root root 1362 May 31 16:53 7383.conf-rw-r--r-- 1 root root 1362 May 31 16:53 7384.conf
設定檔需要修改的地方
其中dbfilename的檔案名稱和dir路徑可以不變
2.cluster的初始化
ruby環境安裝
yum -y install gcc ruby ruby-devel rubygems rpm-build zlib
ruby-redis介面安裝(ruby版本太低可以使用rvm安裝)
gem install redis
啟動各節點,初始化叢集
cd到 redis/src中,找到redis-trib.rb檔案,執行
redis-trib.rb create --replicas 1 host_ip:prot1 host_ip:port2例:./redis-trib.rb create --replicas 1 10.110.122.196:7379 10.110.122.196:7380 10.110.122.196:7381 10.110.122.196:7382 10.110.122.196:7383 10.110.122.196:7384其中--replicas 1表示有一個slave,以上例子中共6個執行個體,表示3主3從
執行到這裡之後基本就完成了叢集的搭建;
3.redis-cluster添加密碼
如果redis執行個體添加了密碼,則需要修改redis-trib.rb檔案
在def connect(o={})這個函數中,
將@r = Redis.new(:host => @info[:host], :port => @info[:port], :timeout => 60)改成
@r = Redis.new(:host => @info[:host], :port => @info[:port], :timeout => 60, :password => "填入你的redis密碼")
然後再在初始化
同時單個執行個體中的設定檔需要寫入requirepass和masterauth的值,以便密碼永久儲存
如下例
requirepass [email protected]masterauth [email protected]
4.查看cluster狀態
10.110.122.196:7379> CLUSTER infocluster_state:ok10.110.122.196:7379> CLUSTER NODES735d1a01bd4a8cba0d37fab42d1764775cb91cfd 10.110.122.196:[email protected] master - 0 1527762245102 3 connected 10923-16383bfd7678b97b5bb627a34e71d09b67982ecce4a7b 10.110.122.196:[email protected] slave 735d1a01bd4a8cba0d37fab42d1764775cb91cfd 0 1527762247108 6 connected
5.節點相互meet
在redis-cli 中 使用 meet IP PORT 即可與其它節點握手
redis的最佳化
10.110.122.196:7379> config set requirepass [email protected]
- 最大記憶體設定,建議設定,否則會佔用系統最大記憶體
10.110.122.196:7379> CONFIG SET maxmemory 4G
每個節點上面都需要設定,叢集最大記憶體大小為master最大記憶體總和
設定之後,使用info可以查看到最大記憶體值
也可以使用config get maxmemory
以上兩者需要持久化保持時,必須寫入設定檔中
- 對應執行個體密碼寫入,在叢集初始化的時候,可以先不進行指定,直接初始化,然後在redis-cli中使用
config set masterauth "[email protected]"和config set requirepass "[email protected]"指定兩個值,同時在使用config rewrite儲存,這兩個值需要在所有叢集執行個體上進行設定
redis單節點安裝及cluster的安裝