針對 /alidata/redis-3.2.9/src 路徑使用設定檔啟動
cd /alidata/redis-3.2.9/src 執行 ./redis-server /alidata/redis-3.2.9/redis.conf &
使用設定檔 後台啟動。 目錄結構如下面兩個圖
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
./redis-server /alidata/redis-3.2.9/redis.conf &
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
/alidata/redis-3.2.9/src
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
/alidata/redis-3.2.9/src
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
/alidata/redis-3.2.9/src
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
/alidata/redis-3.2.9/src
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
/alidata/redis-3.2.9/src
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
[root@iZ23tkclljpZ src]# ps -ef|grep redis
root 12472 12214 0 14:45 pts/1 00:00:00 ./redis-server *:6379
root 12518 12214 0 14:46 pts/1 00:00:00 grep --color=auto redis
[root@iZ23tkclljpZ src]# kill -9 12472
[1]+ Killed ./redis-server /alidata/redis-3.2.9/redis.conf
[root@iZ23tkclljpZ src]# ps -ef|grep redis
root 12570 12214 0 14:48 pts/1 00:00:00 grep --color=auto redis
[root@iZ23tkclljpZ src]# ./redis-server /alidata/redis-3.2.9/redis.conf &
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
[root@iZ23tkclljpZ src]# ps -ef|grep redis
root 12472 12214 0 14:45 pts/1 00:00:00 ./redis-server *:6379
root 12518 12214 0 14:46 pts/1 00:00:00 grep --color=auto redis
[root@iZ23tkclljpZ src]# kill -9 12472
[1]+ Killed ./redis-server /alidata/redis-3.2.9/redis.conf
[root@iZ23tkclljpZ src]# ps -ef|grep redis
root 12570 12214 0 14:48 pts/1 00:00:00 grep --color=auto redis
[root@iZ23tkclljpZ src]# ./redis-server /alidata/redis-3.2.9/redis.conf &
-----------------------------------------------------------------------------------------
Redis安裝配置完成後,啟動過程非常簡單,執行命令/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf即可(在Linux裡一般執行 ./redis-server ../redis.conf)。停止Redis的最簡單的方法是在啟動執行個體的session中,直接使用Control-C命令。當然還可以通過用戶端來停止服務,如可以用shutdown來停止Redis執行個體,具體命令為src/redis-cli shutdown。
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown[10171] 03 Jun 18:13:45.577 # User requested shutdown...[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.[10171] 03 Jun 18:13:45.580 * DB saved on disk[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...[1]- Done ./redis-serverroot@iZ23tkclljpZ:/usr/bin# ps -ef|grep redisroot 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
ps:轉載下redis的開機自啟動
Redis的三種啟動方式 時間 2014-05-26 22:05:39 ITeye-部落格 原文 http://futeng.iteye.com/blog/2071867 主題 Redis
Part I. 直接啟動
下載
官網下載 安裝
tar zxvf redis-2.8.9.tar.gzcd redis-2.8.9#直接make 編譯make#可使用root使用者執行`make install`,將可執行檔拷貝到/usr/local/bin目錄下。這樣就可以直接敲名字運行程式了。make install
啟動
#加上`&`號使redis以背景程式方式運行./redis-server &
檢測
#檢測後台進程是否存在ps -ef |grep redis#檢測6379連接埠是否在監聽netstat -lntp | grep 6379#使用`redis-cli`用戶端檢測串連是否正常./redis-cli127.0.0.1:6379> keys *(empty list or set)127.0.0.1:6379> set key "hello world"OK127.0.0.1:6379> get key"hello world"
停止
#使用用戶端redis-cli shutdown#因為Redis可以妥善處理SIGTERM訊號,所以直接kill -9也是可以的kill -9 PID
Part II. 通過指定設定檔啟動
設定檔
可為redis服務啟動指定設定檔,設定檔 redis.conf 在Redis根目錄下。
#修改daemonize為yes,即預設以背景程式方式運行(還記得前面手動使用&號強制後台運行嗎)。daemonize no#可修改預設監聽連接埠port 6379#修改產生預設記錄檔位置logfile "/home/futeng/logs/redis.log"#配置持久化檔案存放位置dir /home/futeng/data/redisData
啟動時指定設定檔
redis-server ./redis.conf#如果更改了連接埠,使用`redis-cli`用戶端串連時,也需要指定連接埠,例如:redis-cli -p 6380
其他啟停同 直接啟動 方式。設定檔是非常重要的組態工具,隨著使用的逐漸深入將顯得尤為重要,推薦在一開始就使用設定檔。 Part III. 使用Redis啟動指令碼設定開機自啟動 啟動指令碼
推薦在生產環境中使用啟動指令碼方式啟動redis服務。啟動指令碼redis_init_script 位於位於Redis的 /utils/ 目錄下。
#大致瀏覽下該啟動指令碼,發現redis習慣性用監聽的連接埠名作為設定檔等命名,我們後面也遵循這個約定。#redis伺服器監聽的連接埠REDISPORT=6379#服務端所處位置,在make install後預設存放與`/usr/local/bin/redis-server`,如果未make install則需要修改該路徑,下同。EXEC=/usr/local/bin/redis-server#用戶端位置CLIEXEC=/usr/local/bin/redis-cli#Redis的PID檔案位置PIDFILE=/var/run/redis_${REDISPORT}.pid#設定檔位置,需要修改CONF="/etc/redis/${REDISPORT}.conf"
配置環境
1. 根據啟動指令碼要求,將修改好的設定檔以連接埠為名複製一份到指定目錄。需使用root使用者。
mkdir /etc/rediscp redis.conf /etc/redis/6379.conf
2. 將啟動指令碼複製到/etc/init.d目錄下,本例將啟動指令碼命名為redisd(通常都以d結尾表示是後台自啟動服務)。
cp redis_init_script /etc/init.d/redisd
3. 設定為開機自啟動
此處直接配置開啟自啟動 chkconfig redisd on 將報錯誤: service redisd does not support chkconfig
參照 此篇文章 ,在啟動指令碼開頭添加如下兩行注釋以修改其運行層級:
#!/bin/sh# chkconfig: 2345 90 10# description: Redis is a persistent key-value database#
再設定即可成功。
#設定為開機自啟動伺服器chkconfig redisd on#開啟服務service redisd start#關閉服務service redisd stop
轉載請標明作者和原