CentOS 6.5安裝Redis及開機啟動指令碼
一:CentOS 6.5下載安裝Redis
1、下載源碼,解壓縮後編譯源碼
# wget http://download.redis.io/releases/redis-2.8.3.tar.gz
# tar xzf redis-2.8.3.tar.gz
# cd redis-2.8.3
# make
2、進入安裝目錄的src檔案夾下,有四個可執行檔redis-server、redis-benchmark、redis-cli和redis.conf,複製到同一個目錄下
# mkdir /usr/redis
# cp redis-server /usr/redis
# cp redis-benchmark /usr/redis
# cp redis-cli /usr/redis
# cp redis.conf /usr/redis
# cd /usr/redis
3、啟動Redis服務。
# cd /usr/redis
# ./redis-server redis.conf
啟動異常:
情況一:
[17496] 08 Oct 11:48:09.153 # Server started, Redis version 2.8.17
[17496] 08 Oct 11:48:09.153 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[17496] 08 Oct 11:48:09.153 * The server is now ready to accept connections on port 6379
解決辦法:編輯 /etc/sysctl.conf , 添加一項 vm.overcommit_memory = 1,重啟生效。
4、用戶端測試。
redis 127.0.0.1:6379> #顯示此行意味著安裝成功。
二:設定redis開機啟動
環境:Linux系統為CentOS 6.6
1.編寫啟動指令碼
注意:預設的redis.conf檔案參數是前台啟動的,修改daemonize no為daemonize yes則為後台啟動。
指令碼的編碼格式在Windows上編碼放在Linux可能不識別,可以用UltraEdit轉換下格式“檔案-->轉換-->DOS 轉 UNIX“
#!/bin/sh
#chkconfig: 345 86 14
#description: Startup and shutdown script for Redis
PROGDIR=/usr/redis #安裝路徑
PROGNAME=redis-server
DAEMON=$PROGDIR/$PROGNAME
CONFIG=/usr/redis/redis.conf
PIDFILE=/var/run/redis.pid
DESC="redis daemon"
SCRIPTNAME=/etc/rc.d/init.d/redis
start()
{
if test -x $DAEMON
then
echo -e "Starting $DESC: $PROGNAME"
if $DAEMON $CONFIG
then
echo -e "OK"
else
echo -e "failed"
fi
else
echo -e "Couldn't find Redis Server ($DAEMON)"
fi
}
stop()
{
if test -e $PIDFILE
then
echo -e "Stopping $DESC: $PROGNAME"
if kill `cat $PIDFILE`
then
echo -e "OK"
else
echo -e "failed"
fi
else
echo -e "No Redis Server ($DAEMON) running"
fi
}
restart()
{
echo -e "Restarting $DESC: $PROGNAME"
stop
start
}
list()
{
ps aux | grep $PROGNAME
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
list)
list
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|list}" >&2
exit 1
;;
esac
exit 0
把redis指令檔放在 /etc/rc.d/init.d/ 目錄下
2、增加服務並開機啟動
# chmod +x /etc/rc.d/init.d/redis
# chkconfig --add redis
# chkconfig --level 345 redis on
# chkconfig --list redis
3、重啟測試。
下面關於Redis的文章您也可能喜歡,不妨參考下:
Ubuntu 14.04下Redis安裝及簡單測試
Redis主從複製基本配置
Redis叢集明細文檔
Ubuntu 12.10下安裝Redis(圖文詳解)+ Jedis串連Redis
Redis系列-安裝部署維護篇
CentOS 6.3安裝Redis
Redis安裝部署學習筆記
Redis設定檔redis.conf 詳解
Redis 的詳細介紹:請點這裡
Redis 的:請點這裡
本文永久更新連結地址: