本文收集並整理了Redis集羣搭建的網文、網站、本身的經驗。水平有限,只分享環境搭建。本文分爲如下幾個部分:html
請你們按照以上步驟來查看此文node
說明:linux
wget http://download.redis.io/releases/redis-4.0.10.tar.gz tar xzf redis-4.0.10.tar.gz cd redis-4.0.10 make PREFIX=/usr/local/redis install
注:若是不想將Redis做爲一個服務,到這就已經安裝完了redis
Create a directory where to store your Redis config files and your data:(有道詞典:建立一個目錄來存儲Redis配置文件和數據:)shell
# 這只是一個目錄結構,你們不要着急爲何本身沒有,往下看,一步一步來 [root@amor ~]# cd /usr/local/redis [root@amor redis]# tree . ├── bin # 編譯安裝指定目錄後自動生成目錄及文件 │ ├── redis-benchmark │ ├── redis-check-aof │ ├── redis-check-rdb │ ├── redis-cli │ ├── redis-sentinel -> redis-server │ └── redis-server ├── conf # 本身創建的存儲配置文件的目錄及本身建立的單個Redis配置文件 │ └── 6379.conf └── data # 本身創建的存儲Redis數據的目錄及單個Redis服務數據存儲目錄 └── 6379 4 directories, 7 files
注意:cp /usr/src/redis-4.0.10/src/redis-trib.rb /usr/local/redis/bin/
後面建立集羣要用到ubuntu
Copy the init script that you'll find in the Redis distribution under the utils directory into /etc/init.d. We suggest calling it with the name of the port where you are running this instance of Redis. For example:(有道詞典:將在utils目錄下的Redis發行版中找到的init腳本複製到/etc/init.d中咱們建議使用正在運行這個Redis實例的端口的名稱來調用它。例如:)vim
sudo cp utils/redis_init_script /etc/init.d/redis_6379
Edit the init script.(有道詞典:編輯init腳本。)centos
#!/bin/sh # chkconfig 2345 90 25 # linux 開機啓動設置 2345 運行級別 90 啓動優先級(參考 memcached head /etc/rc.d/rc3.d/S90memcached ) 25 關閉優先級 (參考memcached) # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. ### BEGIN INIT INFO # Provides: redis_6379 # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Redis data structure server # Description: Redis data structure server. See https://redis.io ### END INIT INFO REDISPORT=6379 EXEC=/usr/local/redis/bin/redis-server # 修改成本身的可執行文件所在目錄 CLIEXEC=/usr/local/redis/bin/redis-cli # 修改成本身的可執行文件所在目錄 PIDFILE=/var/run/redis_${REDISPORT}.pid # 默認就好 CONF="/usr/local/redis/conf/${REDISPORT}.conf" # 修改成本身的配置文件存放目錄 ···省略··· esac
開始修改redis.confapi
Make sure to modify REDISPORT accordingly to the port you are using. Both the pid file path and the configuration file name depend on the port number.(有道詞典:請確保根據您正在使用的端口對從新分配進行相應的修改。pid文件路徑和配置文件名都取決於端口號。)安全
sudo cp redis.conf /usr/local/redis/conf/6379.conf
(修改爲本身定義的目錄。參考上述目錄結構 redis.conf 在大家redis解壓目錄中的src目錄下)sudo mkdir /usr/local/redis/data/6379
(修改爲本身定義的目錄。參考上述目錄結構)Edit the configuration file, making sure to perform the following changes:(有道詞典:編輯配置文件,確保執行如下更改:)
注:上面的意思是讓大家修改 /usr/local/redis/conf/6379.conf,用vim 打開,搜索上述關鍵詞便可,參考如下設置(若是全部的步驟都是粘貼複製的走下來的,直接修改爲下面這樣:0.0):
port 6379 daemonize yes pidfile /var/run/redis_6379.pid loglevel notice logfile "/var/log/redis_6379.log" dir /usr/local/redis/data/6379
Finally add the new Redis init script to all the default runlevels using the following command:(有道詞典:最後,使用如下命令將新的Redis init腳本添加到全部默認的運行級別:)
# ubuntu sudo update-rc.d redis_6379 defaults
# centos chkconfig --add redis_6379
You are done! Now you can try running your instance with:
sudo /etc/init.d/redis_6379 start
sudo /etc/init.d/redis_6379 start /usr/local/redis/bin/redis-server redis.conf # 注意此處缺省:配置文件路徑 redis-cli -h 127.0.0.1 -p 6379 shutdown
注:若是隻是中止本地redis 請執行: redis-cli shutdown
kill -9 進程號
pkill redis
curl -sSL https://rvm.io/mpapis.asc | gpg2 --import - curl -L get.rvm.io | bash -s stable rvm user gemsets # 創建用戶配置目錄,更換源的時候須要向 db 文件寫入配置信息 echo "ruby_url=https://cache.ruby-china.org/pub/ruby" > ~/.rvm/user/db # 更換源 # 注意:上面的仍是有點問題,你們用下面的這個方式安裝吧 gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 curl -sSL https://get.rvm.io | bash -s stable usermod -a root -G rvm source /etc/profile.d/rvm.sh # 關shell 窗口,從新打開 rvm user gemsets echo "ruby_url=https://cache.ruby-china.org/pub/ruby" > ~/.rvm/user/db
yum -y remove ruby # 卸載centos yum 安裝的 1.8 版本 # Rvm 安裝 Ruby rvm list known rvm install ruby-head rvm use ruby-head --default # 檢查 ruby -v gem -v # Rvm 卸載 Ruby rvm uninstall ruby # 此處帶不帶版本本身測試
gem install rubygems-update rubygems-update gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/ gem sources -l gem install redis
注:下面的內容是我本身參考這篇博文加上我熟悉Redis安裝後本身的配置過程。你們能夠參考NrwLm - Redis 集羣搭建詳細指南。
cd /usr/local/redis/conf cp 6379.conf redis.conf.default # 用做集羣其餘配置文件的藍本 sudo vim redis.conf.default
修改內容以下
bind 192.168.2.123 # 綁定當前機器 IP cluster-enabled yes # 取消註釋,啓動集羣模式 cluster-config-file nodes-6379.conf # 取消註釋,修改成 /usr/local/redis/data/6379/nodes-6379.conf (若是遇到須要從新創建集羣,不將此項修改成指定路徑而和啓動配置文件放在一塊兒,會致使創建集羣時,刪除重建conf 文件) cluster-node-timeout 15000 # 取消註釋 appendonly yes # 將 no 修改成 yes
cd /usr/local/redis/conf echo 9001.conf 9002.conf 9003.conf 9004.conf 9005.conf 9006.conf | xargs -n 1 cp -v redis.conf.default sed -i 's/6379/9001/g' 9001.conf sed -i 's/6379/9002/g' 9002.conf sed -i 's/6379/9003/g' 9003.conf sed -i 's/6379/9004/g' 9004.conf sed -i 's/6379/9005/g' 9005.conf sed -i 's/6379/9006/g' 9006.conf
cd /usr/local/redis/data mkdir -p 9001 9002 9003 9004 9005 9006 # 後期可能須要刪除該文件件下的文件,用於重建集羣,因此,刪除命令也寫一下 rm -rf 900*/*
/usr/local/redis/bin/redis-server /usr/local/redis/conf/9001.conf /usr/local/redis/bin/redis-server /usr/local/redis/conf/9002.conf /usr/local/redis/bin/redis-server /usr/local/redis/conf/9003.conf /usr/local/redis/bin/redis-server /usr/local/redis/conf/9004.conf /usr/local/redis/bin/redis-server /usr/local/redis/conf/9005.conf /usr/local/redis/bin/redis-server /usr/local/redis/conf/9006.conf
/usr/local/redis/bin/redis-trib.rb create --replicas 1 192.168.2.123:9001 192.168.2.123:9002 192.168.2.123:9003 192.168.2.123:9004 192.168.2.123:9005 192.168.2.123:9006
執行命令: /usr/local/redis/bin/redis-cli -c -h 192.168.2.123 -p 9001
redis /usr/bin/env: ruby: 沒有那個文件或目錄
rvm get stable --auto-dotfiles
,或者執行 nvm list
有詳細的錯誤說明(查了資料說,線上不要用rvm安裝ruby)這是我本身的解決方案
# 把這個添加到 /etc/profile 文件中(放到最後就行) rvm use ruby-2.6.0-preview2