1、設定redis.conf中daemonize為yes,確保守護程序開啟。
2、編寫開機自啟動指令碼
vi /etc/init.d/redis
指令碼內容如下:
[cpp] view plain
copy
#!/bin/bash
#chkconfig: 2345 80 90
# ****** redis init.d script conceived to work on linux systems
# as it does use of the /proc filesystem.
# description: start and stop redis
path=/usr/local/bin:/sbin:/usr/bin:/bin
# redis埠號
redisport=6379
# redis-server所在目錄的絕對路徑
exec=/usr/apk/redis-2.8.17/redis-server
# redis-cli所在目錄的絕對路徑
redis_cli=/usr/apk/redis-2.8.17/redis-cli
pidfile=/var/run/redis.pid
# redis.conf所在目錄的絕對路徑
conf="/usr/apk/redis-2.8.17/redis.conf"
auth="nginx"
case"$1" in
start)
if[ -f $pidfile ]
then
echo "$pidfile exists, process is already running or crashed."
else
echo "starting redis server..."
$exec $conf
fi
if[ "$?"="0" ]
then
echo "redis is running..."
fi
;;
stop)
if[ ! -f $pidfile ]
then
echo "$pidfile exists, process is not running."
else
pid=$(cat $pidfile)
echo "stopping..."
$redis_cli -p $redisport shutdown
sleep 2
while[ -x $pidfile ]
do
echo "waiting for redis to shutdown..."
sleep 1
done
echo "redis stopped"
fi
;;
restart|force-reload)
$ stop
$ start
;;
*)
echo "usage: /etc/init.d/redis " >&2
exit 1
esac
寫完後儲存退出vi
3、設定許可權
chmod 755 /etc/init.d/redis
4,設定開機啟動服務
[html]view plain
copy
sudo chkconfig redis on
5,啟動,停止redis
[html]view plain
copy
service redis start #或者 /etc/init.d/redis start
service redis stop #或者 /etc/init.d/redis stop
啟動成功會提示如下資訊:
starting redis server...
redis is running...
使用redis-cli測試:
[root@rk ~]# /usr/redisbin/redis-cli
127.0.0.1:6379> set foo bar
ok127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379> exit
6、關機重啟測試
reboot
然後在用redis-cli測試即可。 centos下redis安裝配置
直接用yum安裝即可 yum install redisredis server直接啟動即可。直接啟動時是用的預設配置,而為了外網能夠連線並且安全起見,需要我們自己配置redis。linux下的redis.conf在 etc redis.conf requirepass 密碼 修改授權的ip 預設的...
CentOS7下Redis的安裝和設定開機啟動
以下命令預設都是在root許可權下執行 wget tar xvzf redis 5.0.2.tar.gz cd redis 5.0.2 make 編譯 make install redis cli redis server等執行檔案會拷貝到 usr local bin 成功安裝完成後可以在任意目錄執...
Centos下Redis的安裝及配置
list b 伺服器環境 centos 6.6 b list list list wget tar xzf redis stable.tar.gz cd redis stable make 編譯後在redis源 目錄src資料夾中可以找到若干個可執行程式。在實際執行redis前推薦使用make te...