redis基礎4-redis服務,redis基礎4-redis

來源:互聯網
上載者:User

redis基礎4-redis服務,redis基礎4-redis

redis設定檔

主要遇到的問題是:redis.pid沒有找到

下面是我的設定檔

# By default Redis does not run as a daemon. Use 'yes' if you need it.# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.daemonize yes# When running daemonized, Redis writes a pid file in /var/run/redis.pid by# default. You can specify a custom pid file location here.

var/run的執行許可權

lrwxrwxrwx  1 root root        4 Feb 24 06:57 run -> /run

然後我用sudo touch redis.pid

root@ubuntu:/home/fuhui/redis-2.8.19/utils# pwd/home/fuhui/redis-2.8.19/utilsroot@ubuntu:/home/fuhui/redis-2.8.19/utils# sh redis_init_script stop/var/run/redis_6379.pid does not exist, process is not running

不知道是不是許可權的問題,修改o許可權

fuhui@ubuntu:/var/run$ sudo chmod o+wx redis.pid-rw-r--rwx 1 root       root          0 Jun 22 08:39 redis.pid

難道是服務並沒有重啟?

fuhui@ubuntu:/var/run$ ps -ef | grep 'redis'fuhui     2452     1  0 07:55 ?        00:00:04 redis-2.8.19/src/redis-server *:6379                 fuhui     2908  2756  0 08:46 pts/13   00:00:00 grep --color=auto redisfuhui@ubuntu:/var/run$ kill -9 2452fuhui@ubuntu:/var/run$ ps -ef | grep 'redis'fuhui     2910  2756  0 08:46 pts/13   00:00:00 grep --color=auto redis

重啟一下試試:
搞定,redis.pid裡有了pid號

關閉redis服務

root@ubuntu:/home/fuhui/redis-2.8.19/utils# sh redis_init_script stop/var/run/redis_6379.pid does not exist, process is not running

修改shell檔案
下面的是原檔案,我們要做的其實很簡單,只是把路徑修改成實際存放的就可以

#!/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

修改如下:

root@ubuntu:/home/fuhui/redis-2.8.19/utils# cp redis_init_script ../redis_script

看一下proc下是否存在pid

fuhui@ubuntu:/proc$ cd /proc/fuhui@ubuntu:/proc$ ls -lh | grep 2912dr-xr-xr-x  9 root       root          0 Jun 22 08:47 2912

關閉redis服務測試

fuhui@ubuntu:~/redis-2.8.19$ src/redis-cli127.0.0.1:6379> shutdownnot connected> 
#!/bin/sh## Simple Redis init.d script conceived to work on Linux systems# as it does use of the /proc filesystem.#REDISPORT=6379EXEC=/home/fuhui/redis-2.8.19/src/redis-serverCLIEXEC=/home/fuhui/redis-2.8.19/src/redis-cliPIDFILE=/var/run/redis.pidCONF="/home/fuhui/redis-2.8.19/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  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

執行結果

root@ubuntu:/home/fuhui/redis-2.8.19# sh redis_script  startStarting Redis server...
root@ubuntu:/home/fuhui/redis-2.8.19# ps -ef | grep 'redis'root      2972     1  0 09:08 ?        00:00:00 /home/fuhui/redis-2.8.19/src/redis-server *:6379                             root      2993  2720  0 09:09 pts/6    00:00:00 grep --color=auto redis
root@ubuntu:/home/fuhui/redis-2.8.19# sh redis_script  stopStopping ...Redis stopped
root@ubuntu:/home/fuhui/redis-2.8.19# ps -ef | grep 'redis'root      2998  2720  0 09:10 pts/6    00:00:00 grep --color=auto 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.