linux非root用戶安裝4.0.14版本redis

  先到官網https://redis.io/download下安裝包,如今最新是5.0.5版本,惋惜點擊下載後被windows禁了,那就下4版本的,往下看Other versions的Old(4.0),點4版本最新4.0.14:html

 

   redis的優勢之一就是安裝包特別小,很快就能下好,點個贊。接下來進入linux的wlf用戶,經過rz上傳至soft目錄,開始執行安裝操做:linux

$ tar xzvf soft/redis-4.0.14.tar.gz $ cd redis-4.0.14 $ make

  make構建結束後,也就安裝結束了:redis

LINK redis-server INSTALL redis-sentinel CC redis-cli.o LINK redis-cli CC redis-benchmark.o LINK redis-benchmark INSTALL redis-check-rdb INSTALL redis-check-aof Hint: It's a good idea to run 'make test' ;)
 make[1]: Leaving directory `/home/wlf/redis-4.0.14/src'

  啓動redis前咱們用vi改下配置文件redis.conf:windows

# By default, if no "bind" configuration directive is specified, Redis listens # for connections from all the network interfaces available on the server. # It is possible to listen to just one or multiple selected interfaces using # the "bind" configuration directive, followed by one or more IP addresses. # # Examples: # # bind 192.168.1.100 10.0.0.1 # bind 127.0.0.1 ::1 # # ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the # internet, binding to all the interfaces is dangerous and will expose the # instance to everybody on the internet. So by default we uncomment the # following bind directive, that will force Redis to listen only into # the IPv4 lookback interface address (this means Redis will be able to # accept connections only from clients running into the same computer it # is running). # # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES # JUST COMMENT THE FOLLOWING LINE. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bind 127.0.0.1 # Protected mode is a layer of security protection, in order to avoid that # Redis instances left open on the internet are accessed and exploited. # # When protected mode is on and if: # # 1) The server is not binding explicitly to a set of addresses using the # "bind" directive. # 2) No password is configured. # # The server only accepts connections from clients connecting from the # IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain # sockets. # # By default protected mode is enabled. You should disable it only if # you are sure you want clients from other hosts to connect to Redis # even if no authentication is configured, nor a specific set of interfaces # are explicitly listed using the "bind" directive. protected-mode yes

  在bind 127.0.0.1加#注掉,將protected-mode yes改成protected-mode no去掉保護策略,這樣就能支持遠程鏈接了。安全

# 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 no  # If a pid file is specified, Redis writes it where specified at startup # and removes it at exit. # # When the server runs non daemonized, no pid file is created if none is # specified in the configuration. When the server is daemonized, the pid file # is used even if not specified, defaulting to "/var/run/redis.pid". # # Creating a pid file is best effort: if Redis is not able to create it # nothing bad happens, the server will start and run normally. pidfile /var/run/redis_6379.pid

   默認redis不是在後臺運行的,將daemonize no改成daemonize yes,另外當後臺運行時默認生成的pid文件是在/var/run目錄下,咱們能夠指定爲本身的目錄,如改成/home/wlf/redis-4.0.14/run/redis_6379.pidapp

   保存好後啓動redis:dom

$ src/redis-server redis.conf 10702:C 23 Sep 15:08:56.153 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 10702:C 23 Sep 15:08:56.153 # Redis version=4.0.14, bits=64, commit=00000000, modified=0, pid=10702, just started 10702:C 23 Sep 15:08:56.153 # Configuration loaded

  看下進程,已經起來了:socket

$ netstat -nlp | grep 6379 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp 0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      10703/src/redis-ser tcp6 0      0 :::6379                 :::*                    LISTEN      10703/src/redis-ser

  咱們克隆會話打開另外一個窗口,進入wlf用戶開啓客戶端:tcp

$ cd redis-4.0.14/ $ src/redis-cli 127.0.0.1:6379> set wlf wumanshu OK 127.0.0.1:6379> get wlf "wumanshu"

   若是咱們想從客戶端遠程鏈接服務端,只需指定服務端ip便可,假如redis服務端ip是10.110.1.11,那麼我在客戶端機器使用命令須要加參數h(默認端口也是6379):ide

$ src/redis-cli -h 10.110.1.11

  關閉客戶端,同時也將關閉服務端:

$ src/redis-cli shutdown $ netstat -nlp | grep 6379 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.)

   或者使用telnet也能夠從遠程機器鏈接到redis。不過由於以上設置,redis自己的安全機制已經蕩然無存,此時很容被入侵,具體方法和安全防禦措施參見redis支持遠程接入的安全防禦問題

相關文章
相關標籤/搜索