Linux环境配置之:redis安装及开机启动

一台新服务器,不想要装软件装得乱乱的,记录一下 CentOS7.4 下安装 redis 4.0 的过程,软件包下载目录 /opt/download ,软件安装目录 /usr/local/redis

安装tcl

这个是后面装完 redis ,完成测试需要用到的工具。

cd /opt/download
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
tar xzvf tcl8.6.1-src.tar.gz
cd tcl8.6.1/unix/
sudo mkdir /usr/local/tcl
./configure
make
make PREFIX=/usr/local/tcl install

下载安装redis

cd /opt/download
wget http://download.redis.io/releases/redis-4.0.14.tar.gz
tar -zxvf redis-4.0.14.tar.gz
cd redis-4.0.14
# 建安装目录然后指定目录安装
sudo mkdir /usr/local/redis
make PREFIX=/usr/local/redis install
make test
# 未安装上面得tcl会,报错 You need tcl 8.5 or newer in order to run the Redis test
# 开机启动
sudo cp /opt/download/redis-4.0.14/utils/redis_init_script /etc/init.d/redis
# 修改启动脚本
sudo vim /etc/init.d/redis

修改启动脚本

REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/conf/${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 -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

配置文件

sudo mkdir /usr/local/redis/conf
sudo cp /opt/download/redis-4.0.14/redis.conf /usr/local/redis/conf/6379.conf
sudo vim /usr/local/redis/conf/6379.conf
# 将 daemonize no 修改为 daemonize yes 保存
sudo chmod +x /etc/init.d/redis
sudo chkconfig redis on
# 启动
service redis start
# 确认启动成功
ps -aux | grep redis
# 使用 redis-cli 进入redis
/usr/local/redis/bin/redis-cli
# 确认版本
/usr/local/redis/bin/redis-server -v

重启服务器可知, redis 开机启动已经生效。

标题:Linux环境配置之:redis安装及开机启动

原文链接:https://beltxman.com/2673.html

若无特殊说明本站内容为 行星带 原创,未经同意请勿转载。

Scroll to top