redis7.2.0 centos源码编译安装并设置开机自启动

下载源码包

wget https://github.com/redis/redis/archive/7.2.0.tar.gz
tar -zxf 7.2.0.tar.gz

编译编码

编译编码

cd redis-7.2.0
make && make install

此时默认redis-server redis-cli等命令行安装到目录/usr/local/bin/目录中。
如果你想安装命令行到指定目录中你可以指定位置 如 make install PREFIX=/usr/local/redis

修改redis.conf

后台启动
daemonize yes

支持远程连接 注释或者指定为0.0.0.0
bind 127.0.0.1 -::1
protected-mode no

设置密码
requirepass 12345

设置开机自启动

vi /etc/init.d/redis

#!/bin/bash
#
# chkconfig: 2345 10 90  
# description: redis service manager   
PATH=/usr/local/bin:/sbin:/usr/bin:/bin   
REDISPORT=6379  
EXEC=/usr/local/bin/redis-server   
REDIS_CLI=/usr/local/bin/redis-cli   
PIDFILE=/var/run/redis.pid   
CONF="/etc/redis.conf"  
AUTH="123456"  
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)   
                ${0} stop   
                ${0} start   
                ;;   
        *)   
               echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2  
                exit 1  
esac

设置redis 权限
chmod 755 /etc/init.d/redis

启动redis
/etc/init.d/redis start

设置开机启动
cd /etc/init.d/
chkconfig redis on

posted @ 2023-08-31 21:00  peachyy  阅读(173)  评论(0编辑  收藏  举报