centos 下Redis 安裝+遠端存取+開機自啟,centosredis

來源:互聯網
上載者:User

centos 下Redis 安裝+遠端存取+開機自啟,centosredis

一.安裝redis

1、下載redis安裝包

可去官網http://redis.io ,也可通過wget命令

cd /usr/local/soft/wget http://download.redis.io/releases/redis-4.0.6.tar.gz

2、解壓

tar xzf redis-4.0.6.tar.gz

3、編譯、安裝

cd redis-4.0.6 make

二.遠端存取

1、將redis設定檔拷貝到etc下

cp /usr/local/soft/redis-4.0.6/src/redis.conf /etc/ 

2、修改設定檔

#bind 127.0.0.1 注釋掉使所有的ip訪問redisprotected-mode yes

3、關閉防火牆

service iptables statuschkconfig iptables off

4、關機重啟

reboot


三.開機自啟

1、設定redis.conf中daemonize為yes,確保守護進程開啟。

2、編寫開機自啟動指令碼

vi /etc/init.d/redis
指令碼如下:
 chkconfig: 2345 10 90  # description: Start and Stop redis     PATH=/usr/local/bin:/sbin:/usr/bin:/bin   REDISPORT=6379  EXEC=/usr/local/soft/redis-4.0.6/src/redis-server   REDIS_CLI=/usr/local/soft/redis-4.0.6/src/redis-cli    PIDFILE=/var/run/redis.pid   CONF="/etc/redis.conf"  AUTH="1234"  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                   if [ "$?"="0" ]                   then                           echo "Redis is running..."                  fi                   ;;           stop)                   if [ ! -f $PIDFILE ]                   then                           echo "$PIDFILE exists, process is not running."                  else                          PID=$(cat $PIDFILE)                           echo "Stopping..."                         $REDIS_CLI -p $REDISPORT  SHUTDOWN                            sleep 2                         while [ -x $PIDFILE ]                          do                                  echo "Waiting for Redis to shutdown..."                                 sleep 1                          done                           echo "Redis stopped"                  fi                   ;;           restart|force-reload)                   ${0} stop                   ${0} start                   ;;           *)                  echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2                  exit 1  esac

3、寫完後儲存退出VI

4、設定許可權

chmod 755 redis

5、啟動測試

/etc/init.d/redis start

啟動成功會提示如下資訊:

Starting Redis server...Redis is running...

使用redis-cli測試:

[root@rk ~]# /usr/redisbin/redis-cli127.0.0.1:6379> set foo barOK127.0.0.1:6379> get foo"bar"127.0.0.1:6379> exit

6、設定開機自啟動

chkconfig redis on

7、關機重啟測試

reboot

然後在用redis-cli測試即可。


查看評論

相關文章

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.