Centos7安裝Redis


https://www.cnblogs.com/heqiuyong/p/10463334.html

 

一、安裝gcc依賴

由於 redis 是用 C 語言開發,安裝之前必先確認是否安裝 gcc 環境(gcc -v),如果沒有安裝,執行以下命令進行安裝

 [root@localhost local]# yum install -y gcc 

 

二、下載並解壓安裝包

[root@localhost local]# wget http://download.redis.io/releases/redis-5.0.3.tar.gz

[root@localhost local]# tar -zxvf redis-5.0.3.tar.gz

 

三、cd切換到redis解壓目錄下,執行編譯

[root@localhost local]# cd redis-5.0.3

[root@localhost redis-5.0.3]# make

 

四、安裝並指定安裝目錄

[root@localhost redis-5.0.3]# make install PREFIX=/usr/local/redis

 

五、啟動服務

5.1前台啟動

[root@localhost redis-5.0.3]# cd /usr/local/redis/bin/

[root@localhost bin]# ./redis-server

 

5.2后台啟動

從 redis 的源碼目錄中復制 redis.conf 到 redis 的安裝目錄

[root@localhost bin]# cp /usr/local/redis-5.0.3/redis.conf /usr/local/redis/bin/

 

修改 redis.conf 文件,把 daemonize no 改為 daemonize yes

[root@localhost bin]# vi redis.conf

后台啟動

[root@localhost bin]# ./redis-server redis.conf

 

六、設置開機啟動

添加開機啟動服務

[root@localhost bin]# vi /etc/systemd/system/redis.service

復制粘貼以下內容:

復制代碼

[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

復制代碼

注意:ExecStart配置成自己的路徑 

 

設置開機啟動

[root@localhost bin]# systemctl daemon-reload

[root@localhost bin]# systemctl start redis.service

[root@localhost bin]# systemctl enable redis.service

 

創建 redis 命令軟鏈接

[root@localhost ~]# ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis

測試 redis

 

服務操作命令

systemctl start redis.service   #啟動redis服務

systemctl stop redis.service   #停止redis服務

systemctl restart redis.service   #重新啟動服務

systemctl status redis.service   #查看服務當前狀態

systemctl enable redis.service   #設置開機自啟動

systemctl disable redis.service   #停止開機自啟動

 

代碼改變一切!
 
 
 

redis本地能訪問外網不能訪問問題

1.確認配置文件bind的ip是否正確,一般想要外網能訪問,需要填寫為0.0.0.0,表示監聽任何ip

注意任何人都能訪問,一定要開啟密碼 requirepass 你的密碼

2.確認protected-mode 是否為 no

3.修改完配置文件后重啟Redis

service redis restart

4.確認防火牆是否開啟

service iptables status

5.如果是開啟狀態關閉,再進行嘗試

service iptables stop

如果可以連接,表示防護牆規則有問題

6.檢查防火牆規則(建議使用sftp)

vim /etc/sysconfig/iptables

注意這里的順序很重要

 

 

 

7.修改之后進行保存,然后重啟iptables

service iptables restart


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM