redis服務啟動和停止
針對
/alidata/redis-3.2.9/src 路徑使用配置檔案啟動
cd /alidata/redis-3.2.9/src
執行
./redis-server /alidata/redis-3.2.9/redis.conf &
使用配置檔案 後臺啟動。
目錄結構如下面兩個圖
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
./redis-server /alidata/redis-3.2.9/redis.conf &
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
/alidata/redis-3.2.9/src
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
/alidata/redis-3.2.9/src
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
/alidata/redis-3.2.9/src
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
/alidata/redis-3.2.9/src
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
/alidata/redis-3.2.9/src
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
[[email protected] 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
[[email protected] src]# kill -9 12472
[1]+ Killed ./redis-server /alidata/redis-3.2.9/redis.conf
[[email protected] src]# ps -ef|grep redis
root 12570 12214 0 14:48 pts/1 00:00:00 grep --color=auto redis
[[email protected] src]# ./redis-server /alidata/redis-3.2.9/redis.conf &
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
[[email protected] 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
[[email protected] src]# kill -9 12472
[1]+ Killed ./redis-server /alidata/redis-3.2.9/redis.conf
[[email protected] src]# ps -ef|grep redis
root 12570 12214 0 14:48 pts/1 00:00:00 grep --color=auto redis
[[email protected] 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。
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
ps:轉載下redis的開機自啟動
Redis的三種啟動方式
時間 2014-05-26 22:05:39 ITeye-部落格
主題 Redis
Part I. 直接啟動
下載
安裝
tar zxvf redis-2.8.9.tar.gz
cd redis-2.8.9
#直接make 編譯
make
#可使用root使用者執行`make install`,將可執行檔案拷貝到/usr/local/bin目錄下。這樣就可以直接敲名字執行程式了。
make install
#直接make 編譯
make
#可使用root使用者執行`make install`,將可執行檔案拷貝到/usr/local/bin目錄下。這樣就可以直接敲名字執行程式了。
make install
啟動
#加上`&`號使redis以後臺程式方式執行
./redis-server &
./redis-server &
檢測
#檢測後臺程序是否存在
ps -ef |grep redis
#檢測6379埠是否在監聽
netstat -lntp | grep 6379
#使用`redis-cli`客戶端檢測連線是否正常
./redis-cli
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set key "hello world"
OK
127.0.0.1:6379> get key
"hello world"
ps -ef |grep redis
#檢測6379埠是否在監聽
netstat -lntp | grep 6379
#使用`redis-cli`客戶端檢測連線是否正常
./redis-cli
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set key "hello world"
OK
127.0.0.1:6379> get key
"hello world"
停止
#使用客戶端
redis-cli shutdown
#因為Redis可以妥善處理SIGTERM訊號,所以直接kill -9也是可以的
kill -9 PID
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
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
#如果更改了埠,使用`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"
#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/redis
cp redis.conf /etc/redis/6379.conf
/etc/redis
cp 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: 2345 90 10
# description: Redis is a persistent key-value database
#
再設定即可成功。
#設定為開機自啟動伺服器
chkconfig redisd on
#開啟服務
service redisd start
#關閉服務
service redisd stop
chkconfig redisd on
#開啟服務
service redisd start
#關閉服務
service redisd stop
轉載請標明作者和原
當你的才華還撐不起你的野心的時候,快來這裡愉快的學習吧
wx公眾號:java架構獅 乾貨滿滿 視訊多多
贈送視訊如下:
不定期送視訊
1700G it視訊 等你來!
留言給他 即可贈送一套視訊
更新!!
元宵節鉅獻:2月12 號 贈送 多套花錢買的架構師視訊
趕緊去關注吧!!
注意:關注微訊號發訊息 給我們 不一定及時回覆 !!每天會抽時間統一回復兩三次!
注意:關注微訊號發訊息 給我們 不一定及時回覆 !!每天會抽時間統一回復兩三次!
注意:關注微訊號發訊息 給我們 不一定及時回覆 !!每天會抽時間統一回復兩三次!
注意:關注微訊號發訊息 給我們 不一定及時回覆 !!每天會抽時間統一回復兩三次!
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。
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis
[email protected]:/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-server
[email protected]:/usr/bin# ps -ef|grep redis
root 12909 9997 0 18:13 pts/2 00:00:00 grep --color=auto redis