1. 程式人生 > >軍哥lnmp安裝使用redis

軍哥lnmp安裝使用redis

cd
cd lnmp1.5
#執行
./addons.sh install redis
#直接回車安裝最新穩定版本

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/
Add to auto startup...
Add redis service at system startup...
Restarting php-fpm......
Gracefully shutting down php-fpm . done
Starting php-fpm  done
Starting Redis server...24003:C 26 Nov 07:52:19.875 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
24003:C 26 Nov 07:52:19.875 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=24003, just started
24003:C 26 Nov 07:52:19.875 # Configuration loaded
 done
====== Redis install completed ======
Redis installed successfully, enjoy it!

以上安裝成功,並加入開機啟動,因為一臺伺服器後續要用到,所以先安裝一下redis

安裝完成後,預設無密碼,只允許本機訪問:127.0.0.1 埠6379

如果你需要使用密碼

vi /usr/local/redis/etc/redis.conf

#到500行左右,將requirepass註釋去掉,後面修改為你想要的密碼
    487 ################################## SECURITY ###################################
    488 
    489 # Require clients to issue AUTH <PASSWORD> before processing any other
    490 # commands.  This might be useful in environments in which you do not trust
    491 # others with access to the host running redis-server.
    492 #
    493 # This should stay commented out for backward compatibility and because most
    494 # people do not need auth (e.g. they run their own servers).
    495 #
    496 # Warning: since Redis is pretty fast an outside user can try up to
    497 # 150k passwords per second against a good box. This means that you should
    498 # use a very strong password otherwise it will be very easy to break.
    499 #
    500 # requirepass foobared

啟動指令碼就無法stop了,提示(error) NOAUTH Authentication required,因為redis自啟動命令沒有密碼連線設定

     vi /etc/init.d/redis
    #搜尋shudown
     42         if [ ! -f "$PIDFILE" ]; then
     43             echo "$PIDFILE does not exist, process is not running"
     44         else
     45             PID=$(cat $PIDFILE)
     46             echo "Stopping  Redis server..."
     47             $REDIS_CLI -p $REDISPORT -a password shutdown
     48             if [ "$?"="0" ]; then
     49                 echo " done"
     50             else
     51                 echo " failed"
     52             fi
     53         fi

#設定密碼後必須有密碼才能在cli下進行操作
#編輯  /etc/init.d/redis 查詢shutdown在前面加上 -a 密碼 ,-a前面和密碼後面都有空格

如果需要外網訪問:

除了要修改 /usr/local/redis/etc/redis.conf 裡將bind 127.0.0.1 改成 bind 0.0.0.0 重啟redis 
還需要將防火牆裡redis的埠 6379的禁止訪問規則去掉,參考iptables教程:https://www.vpser.net/security/linux-iptables.html
允許外網訪問一定要做好相關安全措施!!!!!!!!!!