#cd /www/server/redis
#cp redis.conf redis6380.conf
#vi redis6380.conf #注:修改redis6380.conf这一步可以进宝塔面板修改,只修改以下几项哦
port 6380
pidfile /www/server/redis/redis_6380.pid
logfile "/www/server/redis/redis_6380.log"
dbfilename dump_6380.rdb
#cd /etc/init.d
#cp redis redis6380
#vi redis6380
#!/bin/sh
# chkconfig: 2345 56 26
# description: Redis Service
### BEGIN INIT INFO
# Provides: Redis
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts Redis
# Description: starts the BT-Web
### END INIT INFO
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDIS_PORT="6380"
CONF="/www/server/redis/redis${REDIS_PORT}.conf"
REDISPORT=$(cat $CONF |grep port|grep -v '#'|awk '{print $2}')
REDISPASS=$(cat $CONF |grep requirepass|grep -v '#'|awk '{print $2}')
REDISHOST=$(cat $CONF |grep bind|grep -v '#'|awk '{print $2}')
if [ "$REDISPASS" != "" ];then
REDISPASS=" -a $REDISPASS"
fi
if [ -f "/www/server/redis/start${REDIS_PORT}.pl" ];then
STARPORT=$(cat /www/server/redis/start${REDIS_PORT}.pl)
else
STARPORT="${REDIS_PORT}"
fi
EXEC=/www/server/redis/src/redis-server
CLIEXEC="/www/server/redis/src/redis-cli -h $REDISHOST -p $STARPORT$REDISPASS"
PIDFILE=/var/run/redis_${REDIS_PORT}.pid
redis_start(){
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
nohup sudo -u redis $EXEC $CONF >> /www/server/redis/logs${REDIS_PORT}.pl 2>&1 &
echo ${REDISPORT} > /www/server/redis/start${REDIS_PORT}.pl
fi
}
redis_stop(){
echo "Stopping ..."
$CLIEXEC shutdown
sleep 1
PID=`ps aux|grep "sudo -u redis"|grep -v "grep"|grep -v "/etc/init.d/redis${REDIS_PORT}"|awk '{print $2}'`
if [ "${PID}" != "" ];then
sleep 3
pkill -9 redis-server
rm -f $PIDFILE
fi
echo "Redis stopped"
}
case "$1" in
start)
redis_start
;;
stop)
redis_stop
;;
restart|reload)
redis_stop
sleep 0.3
redis_start
;;
*)
echo "Please use start or stop as first argument"
;;
esac
启动redis6378
/www/server/redis/src/redis-server /www/server/redis/redis6380.conf
启动redis6380
/etc/init.d/redis6380 start
1
如果这里报权限错误,需要给redi.log权限,然后再执行上面的命令直到成功
最后设置开机启动
chkconfig redis6380 on
1
reboot 重启测试。
如果是debian系统,在/etc/systemd/system中新建redis6387.service,在文件中编辑如下
[Unit]
Description=Redis Instance 6387
After=network.target
[Service]
Type=forking
User=redis
ExecStart=/www/server/redis/src/redis-server /www/server/redis/redis6387.conf
ExecStop=/www/server/redis/src/redis-cli -p 6387 shutdown
Restart=always
[Install]
WantedBy=multi-user.target
StandardOutput=journal
StandardError=journal
如果是debian系统,无法添加自启动命令,可以执行
systemctl unmask redis6380
systemctl enable redis6380
systemctl start redis6380
systemctl status redis6380