這裡建立6個redis節點,其中三個為主節點,三個為從節點。redis和埠對應關係:
127.0.0.1:7000
127.0.0.1:7001
127.0.0.1:7002
從:127.0.0.1:7003
127.0.0.1:7004
127.0.0.1:7005
步驟:2:上傳伺服器,解壓,編譯
tar -zxvf redis-3.0.0.tar.gz
mv redis-3.0.0 redis3.0
cd /usr/local/redis3.0
make & make install
3:建立集群需要的目錄並拷貝redis
mkdir -p /usr/local/cluster
mkdir -p /usr/local/cluster/7000
mkdir -p /usr/local/cluster/7001
mkdir -p /usr/local/cluster/7002
mkdir -p /usr/local/cluster/7003
mkdir -p /usr/local/cluster/7004
mkdir -p /usr/local/cluster/7005
cp -rf /usr/local/redis3.0/* /usr/local/cluster/7000/
cp -rf /usr/local/redis3.0/* /usr/local/cluster/7001/
cp -rf /usr/local/redis3.0/* /usr/local/cluster/7002/
cp -rf /usr/local/redis3.0/* /usr/local/cluster/7003/
cp -rf /usr/local/redis3.0/* /usr/local/cluster/7004/
cp -rf /usr/local/redis3.0/* /usr/local/cluster/7005/
4:修改配置檔案redis.conf
vi /usr/local/cluster/7000/redis.conf
##修改配置檔案中的下面選項
port 7000
daemonize yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
#同樣再對其它配置檔案進行修改
vi /usr/local/cluster/7001/redis.conf
vi /usr/local/cluster/7002/redis.conf
vi /usr/local/cluster/7003/redis.conf
vi /usr/local/cluster/7004/redis.conf
vi /usr/local/cluster/7005/redis.conf
##注意:不同的目錄配置不同的redis.conf中的port
5:啟動6個redis
cd /usr/local/cluster/7000/src
redis-server ../redis.conf
cd /usr/local/cluster/7001/src
redis-server ../redis.conf
cd /usr/local/cluster/7002/src
redis-server ../redis.conf
cd /usr/local/cluster/7003/src
redis-server ../redis.conf
cd /usr/local/cluster/7004/src
redis-server ../redis.conf
cd /usr/local/cluster/7005/src
redis-server ../redis.conf
##啟動之後使用命令檢視redis的啟動情況ps -ef|grep redis
6,建立redis集群
cd /usr/local/redis3.0/src
./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
6.1執行上面的命令的時候會報錯,因為是執行的的指令碼,需要
錯誤內容:/usr/bin/env: ruby: no such file or directory
所以需要安裝ruby的環境,這裡推薦使用yum install ruby
yum install ruby
6.2然後再執行第步的建立集群命令,還會報錯,提示缺少rubygems元件
錯誤內容:
./redis-trib.rb:24:in `require': no such file to load -- rubygems (loaderror)
from ./redis-trib.rb:24
yum install rubygems
6.3再次執行第步的命令,還會報錯,提示不能載入redis,是因為缺少redis的介面
錯誤內容:
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
gem_original_require': no such file to load -- redis (loaderror)
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:inrequire'
from ./redis-trib.rb:25
gem install redis
這裡可能無法安裝,因為無法連線gem伺服器:
[@zw_22_90 src]# gem install redis --version 3.0.0
error: could not find a valid gem 'redis' (= 3.0.0) in any repository
error: while executing gem ... (gem::remotefetcher::fetcherror)
wget
gem install -l ./redis-3.2.1.gem
6.4 再次執行第步的命令,正常執行
輸入yes,然後配置完成。
[@zw_22_90 src]# ./redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
7,redis-cli命令進入集群環境
[@zw_22_90 src]# redis-cli -c -p 7000
Centos7搭建redis集群
1.分別在node2,3,4上安裝redis 2.配置集群 以下操作只需要在一台機器上安裝即可,這裡我選用 node2 上安裝 1 在 redis安裝目錄的 src 目錄下有乙個檔案 redis trib.rb 這是乙個ruby版的 redis服務安裝指令碼,為了使用它,請首先安裝 ruby.安裝r...
Redis5 0 0集群搭建 centos7
cd usr local src wget 注意要有gcc環境,沒有需要安裝 tar zxvf redis 5.0.0.tar.gz cd redis 5.0.0 make make install 建立四個節點測試,複製redis conf並修改埠 cd usr local mkdir redis...
Centos7中搭建Redis環境
yum install gcc c 1.3,轉到 usr local src 目錄,再將redis壓縮包解壓到 usr local 下 tar zxvf redis 3.0.0.tar.gz c usr localmake malloc libcmake prefix usr local redis...