Redis配置成服務啟動

來源:互聯網
上載者:User

把redis配置為開機啟動有很多方法
但看過官方的指令碼,還是用官方的(自己shell水平還是還自知之明的…)
1.複製指令碼到系統目錄中

cp /redis/utils/redis_init_script /etc/rc.d/init.d/redis

2.修改指令碼
vim /etc/rc.d/init.d/redis

#!/bin/sh## Simple Redis init.d script conceived to work on Linux systems# as it does use of the /proc filesystem.REDISPORT=6379EXEC=/usr/local/bin/redis-serverCLIEXEC=/usr/local/bin/redis-cliPIDFILE=/var/run/redis_${REDISPORT}.pidCONF="/etc/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 -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

1).在#!/bin/sh添加#chkconfig: 2345 80 90,(如果不添加,註冊服務時:service redis does not support chkconfig)
2).REDISPORT根據自己環境配置來配置
3).EXEC=/usr/local/bin/redis-server 改為自己環境下EXEC=redis/src/redis-server
4).CLIEXEC=/usr/local/bin/redis-cli 改為自己環境下CLIEXEC=redis/src/redis-cli
5).CONF=/etc/redis/{REDISPORT}.conf”改為自己環境下CONF=redis/redis.conf  
6).PIDFILE=/var/run/redis_{REDISPORT}.conf”改為自己環境下CONF=redis/redis.conf 6).PIDFILE=/var/run/redis_{REDISPORT}.pid改為自己環境下的配置(redis.conf裡的:pidfile /var/run/redis_6379.pid)
7).在$EXEC $CONF後面加上& $EXEC $CONF &
修改後的檔案

#!/bin/sh#chkconfig: 2345 80 90## Simple Redis init.d script conceived to work on Linux systems# as it does use of the /proc filesystem.REDISPORT=6377EXEC=/home/software/redis/src/redis-serverCLIEXEC=/home/software/redis/src/redis-cliPIDFILE=/home/data/redis/run/redis.pidCONF="/home/software/redis/redis.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

3.註冊服務:
chkconfig --add redis
[4].防火牆配置
添加配置:echo '-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT' >> /etc/sysconfig/iptables
重啟:service iptables restart
[5].啟動服務
service redis start
[6].測試
reboot
ps -ef | grep redis

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.