redis 安装启动

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      `设置服务开机启动`

注意事项

  1. redis的配置文件必须有可执行权限
  2. service redis does not support chkconfig的解决办法,需要添加# chkconfig: 2345 10 90
  3. . /etc/rc.d/init.d/functions加载系统的函数
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值