ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

CentOS7-离线编译安装Redis4.0.9

2021-01-26 14:01:03  阅读:302  来源: 互联网

标签:status stop tar 离线 redis echo CentOS7 Redis4.0 PROG


CentOS7-离线编译安装Redis4.0.9

redis下载官方地址: redis-4.0.9.tar.gz

1. 下载并解压

curl -o redis-4.0.9.tar.gz http://download.redis.io/releases/redis-4.0.9.tar.gz
tar -zxvf redis-4.0.9.tar.gz

2.编译源码

cd redis-4.0.9
mkdir -p /opt/tbp/redis
make && make PREFIX=/opt/tbp/redis install

3.创建启动项脚本

cat >> /etc/init.d/redisd <<EOF
#!/bin/bash
# chkconfig: 2345 85 80
# description: Starts and Stops the redisd server.

### BEGIN INIT INFO
# Provides: redis-server
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start up the redisd server:n
# Description: This service starts up the redis server daemon.
### END INIT INFO
# source function library.
#. /etc/init.d/functions
source /etc/profile
DIR=${TBP_HOME}/redis/
PROG=bin/redis-server
CONF=bin/redis.conf
CMD="${DIR}${PROG} ${DIR}${CONF}"


# check for $PROG script
if [ ! -f $DIR$PROG ]
then
    echo "${PROG} not exists..."
    exit
fi

start()
{
     echo "starting $PROG : "
        nohup $CMD >/dev/null 2>&1 &
        sleep 0.5
        status
}
stop()
{
    echo "stopping $PROG: "
    ps -ef | grep "$PROG" | kill -9 `awk '{print $2}'` >/dev/null 2>&1
    sleep 0.5
    status
}
restart()
{
    stop
    start
    echo -n ""
}
status()
{
    count=`ps -ef | grep -c $PROG`
    if [ $count -gt 1 ]
    then
        echo "${PROG} is running."
    else
        echo "${PROG} is stoped."
    fi
    echo -n ""

}
case "$1" in
    start)
        start ;;
    stop)
        stop ;;
    restart)
        restart ;;
    status)
        status ;;
    *)
        echo "Usage: ${PROG} {start|stop|restart|status}"
        exit 1
esac
exit 0
EOF

4.添加启动项脚本权限

chmod +x /etc/init.d/redisd

5.添加服务

chkconfig --add redisd

5.配置启动级别

chkconfig --level 2345 redisd on

5.总结一句话脚本

curl -o redis-4.0.9.tar.gz http://download.redis.io/releases/redis-4.0.9.tar.gz && \
tar -zxvf redis-4.0.9.tar.gz && \
cd redis-4.0.9 && \
mkdir -p /opt/tbp/redis && \
make && make PREFIX=/opt/tbp/redis install && \
cat >> /etc/init.d/redisd <<EOF
#!/bin/bash
# chkconfig: 2345 85 80
# description: Starts and Stops the redisd server.

### BEGIN INIT INFO
# Provides: redis-server
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start up the redisd server:n
# Description: This service starts up the redis server daemon.
### END INIT INFO
# source function library.
#. /etc/init.d/functions
source /etc/profile
DIR=${TBP_HOME}/redis/
PROG=bin/redis-server
CONF=bin/redis.conf
CMD="${DIR}${PROG} ${DIR}${CONF}"


# check for $PROG script
if [ ! -f $DIR$PROG ]
then
    echo "${PROG} not exists..."
    exit
fi

start()
{
     echo "starting $PROG : "
        nohup $CMD >/dev/null 2>&1 &
        sleep 0.5
        status
}
stop()
{
    echo "stopping $PROG: "
    ps -ef | grep "$PROG" | kill -9 `awk '{print $2}'` >/dev/null 2>&1
    sleep 0.5
    status
}
restart()
{
    stop
    start
    echo -n ""
}
status()
{
    count=`ps -ef | grep -c $PROG`
    if [ $count -gt 1 ]
    then
        echo "${PROG} is running."
    else
        echo "${PROG} is stoped."
    fi
    echo -n ""

}
case "$1" in
    start)
        start ;;
    stop)
        stop ;;
    restart)
        restart ;;
    status)
        status ;;
    *)
        echo "Usage: ${PROG} {start|stop|restart|status}"
        exit 1
esac
exit 0
EOF

chmod +x /etc/init.d/redisd && \
chkconfig --add redisd && \
chkconfig --level 2345 redisd on

标签:status,stop,tar,离线,redis,echo,CentOS7,Redis4.0,PROG
来源: https://www.cnblogs.com/jarowlu666/p/14329929.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有