redis 安装启动
@(redis)[安装,启动]
下载
wget http://download.redis.io/releases/redis-4.0.2.tar.gz
解压
tar xf redis-4.0.2.tar.gz
cd redis-4.0.2
修改配置文件
vim redis.conf
启动
nohup src/redis-server redis.conf &
登陆
./redis-cli -h 192.168.15.38 -p 6379
添加自启动
修改redis路径
mv redis-4.0.2 /usr/local/redis
修改配置文件
cd /usr/local/redis
cp redis.conf 6379.conf
添加服务
cp utils/redis_init_script /etc/init.d/redis
编辑开机自启脚本
vim /etc/init.s/redis
开机自启脚本内容
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
# chkconfig: 2345 10 90
# description: Start and Stop redis
# Source function library.
. /etc/rc.d/init.d/functions
REDISPORT=6379
EXEC=/usr/local/redis/src/redis-server
CLIEXEC=/usr/local/redis/src/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/${REDISPORT}.conf"
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
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -h 192.168.15.38 -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
启动、设置自启
chmod +x /etc/init.d/redis
chkconfig --add redis `添加服务`
chkconfig --list redis `查看服务器启动状态`
chkconfig redis on `设置服务开机启动`
注意事项
- redis的配置文件必须有可执行权限
service redis does not support chkconfig
的解决办法,需要添加# chkconfig: 2345 10 90
. /etc/rc.d/init.d/functions
加载系统的函数