数据库
首页 > 数据库> > CentOS7-离线编译安装Redis4.0.9

CentOS7-离线编译安装Redis4.0.9

作者:互联网

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