Redis的三種啟動方式

來源:互聯網
上載者:User

標籤:redis 啟動方式 記憶體資料庫

Part I. 直接啟動下載

官網下載

 

 

安裝

 

Shell代碼  650) this.width=650;" class="star" src="http://futeng.iteye.com/images/icon_star.png" alt="收藏代碼" />

  1. tar zxvf redis-2.8.9.tar.gz  

  2. cd redis-2.8.9  

  3. #直接make 編譯  

  4. make  

  5. #可使用root使用者執行`make install`,將可執行檔拷貝到/usr/local/bin目錄下。這樣就可以直接敲名字運行程式了。  

  6. make install  

 啟動

 

Shell代碼  650) this.width=650;" class="star" src="http://futeng.iteye.com/images/icon_star.png" alt="收藏代碼" />

  1. #加上`&`號使redis以背景程式方式運行  

  2. ./redis-server &  

 檢測

 

Shell代碼  650) this.width=650;" class="star" src="http://futeng.iteye.com/images/icon_star.png" alt="收藏代碼" />

  1. #檢測後台進程是否存在  

  2. ps -ef |grep redis  

  3.   

  4. #檢測6379連接埠是否在監聽  

  5. netstat -lntp | grep 6379  

  6.   

  7. #使用`redis-cli`用戶端檢測串連是否正常  

  8. ./redis-cli  

  9. 127.0.0.1:6379> keys *  

  10. (empty list or set)  

  11. 127.0.0.1:6379> set key "hello world"  

  12. OK  

  13. 127.0.0.1:6379> get key  

  14. "hello world"  

 停止

 

Shell代碼  650) this.width=650;" class="star" src="http://futeng.iteye.com/images/icon_star.png" alt="收藏代碼" />

  1. #使用用戶端  

  2. redis-cli shutdown  

  3. #因為Redis可以妥善處理SIGTERM訊號,所以直接kill -9也是可以的  

  4. kill -9 PID  

 

 

Part II. 通過指定設定檔啟動設定檔

可為redis服務啟動指定設定檔,設定檔redis.conf在Redis根目錄下。

 

Shell代碼  650) this.width=650;" class="star" src="http://futeng.iteye.com/images/icon_star.png" alt="收藏代碼" />

  1. #修改daemonize為yes,即預設以背景程式方式運行(還記得前面手動使用&號強制後台運行嗎)。  

  2. daemonize no  

  3. #可修改預設監聽連接埠  

  4. port 6379  

  5. #修改產生預設記錄檔位置  

  6. logfile "/home/futeng/logs/redis.log"  

  7. #配置持久化檔案存放位置  

  8. dir /home/futeng/data/redisData  

 

 

啟動時指定設定檔

 

Shell代碼  650) this.width=650;" class="star" src="http://futeng.iteye.com/images/icon_star.png" alt="收藏代碼" />

  1. redis-server ./redis.conf  

  2. #如果更改了連接埠,使用`redis-cli`用戶端串連時,也需要指定連接埠,例如:  

  3. redis-cli -p 6380  

 

 

其他啟停同直接啟動方式。設定檔是非常重要的組態工具,隨著使用的逐漸深入將顯得尤為重要,推薦在一開始就使用設定檔。

 

Part III. 使用Redis啟動指令碼設定開機自啟動啟動指令碼

推薦在生產環境中使用啟動指令碼方式啟動redis服務。啟動指令碼redis_init_script位於位於Redis的/utils/目錄下。

 

Shell代碼  650) this.width=650;" class="star" src="http://futeng.iteye.com/images/icon_star.png" alt="收藏代碼" />

  1. #大致瀏覽下該啟動指令碼,發現redis習慣性用監聽的連接埠名作為設定檔等命名,我們後面也遵循這個約定。  

  2. #redis伺服器監聽的連接埠  

  3. REDISPORT=6379  

  4. #服務端所處位置,在make install後預設存放與`/usr/local/bin/redis-server`,如果未make install則需要修改該路徑,下同。  

  5. EXEC=/usr/local/bin/redis-server  

  6. #用戶端位置  

  7. CLIEXEC=/usr/local/bin/redis-cli  

  8. #Redis的PID檔案位置  

  9. PIDFILE=/var/run/redis_${REDISPORT}.pid  

  10. #設定檔位置,需要修改  

  11. CONF="/etc/redis/${REDISPORT}.conf"  

 

 

配置環境

1. 根據啟動指令碼要求,將修改好的設定檔以連接埠為名複製一份到指定目錄。需使用root使用者。

 

Shell代碼  650) this.width=650;" class="star" src="http://futeng.iteye.com/images/icon_star.png" alt="收藏代碼" />

  1. mkdir /etc/redis  

  2. cp redis.conf /etc/redis/6379.conf  

 2. 將啟動指令碼複製到/etc/init.d目錄下,本例將啟動指令碼命名為redisd(通常都以d結尾表示是後台自啟動服務)。

 

Shell代碼  650) this.width=650;" class="star" src="http://futeng.iteye.com/images/icon_star.png" alt="收藏代碼" />

  1. cp redis_init_script /etc/init.d/redisd  

 3. 設定為開機自啟動

 

此處直接配置開啟自啟動chkconfig redisd on將報錯誤:service redisd does not support chkconfig
參照此篇文章,在啟動指令碼開頭添加如下兩行注釋以修改其運行層級:

 

Shell代碼  650) this.width=650;" class="star" src="http://futeng.iteye.com/images/icon_star.png" alt="收藏代碼" />

  1. #!/bin/sh  

  2. # chkconfig:   2345 90 10  

  3. # description:  Redis is a persistent key-value database  

  4. #  

 再設定即可成功。

 

 

Shell代碼  650) this.width=650;" class="star" src="http://futeng.iteye.com/images/icon_star.png" alt="收藏代碼" />

  1. #設定為開機自啟動伺服器  

  2. chkconfig redisd on  

  3. #開啟服務  

  4. service redisd start  

  5. #關閉服務  

  6. service redisd stop 

本文出自 “技術成就夢想” 部落格,請務必保留此出處http://pizibaidu.blog.51cto.com/1361909/1674290

Redis的三種啟動方式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.