CentOS install Redis

一、安裝gcc依賴

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

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

二、檢查版本

http://download.redis.io/releases/

三、安裝

如果要安裝最新的redis,需要安裝Remi的軟件源,官網地址:http://rpms.famillecollet.com/

yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

然後可以使用下面的命令安裝最新版本的redis:

yum --enablerepo=remi install redis

四、啓動redis服務

service redis start
或者
systemctl start redis

五、redis安裝完畢後,來查看下redis安裝時創建的相關文件,如下

1

2

rpm -qa |grep redis

rpm -ql redis

六、查看redis-cli版本

1

redis-cli --version

七、設置爲開機自動啓動

systemctl enable redis.service

八、Redis開啓遠程登錄連接,redis默認只能localhost訪問,所以需要開啓遠程登錄

解決方法如下:

在redis的配置文件/etc/redis.conf中

將bind 127.0.0.1 改成了 bind 0.0.0.0

然後要配置防火牆 開放端口6379

九、修改 redis.conf 文件,設置爲守護進程,把 daemonize no 改爲 daemonize yes

[root@localhost bin]# vi redis.conf

十、測試

[root@mysqlserver bin]# redis-cli
127.0.0.1:6379> set 123 "test"
OK
127.0.0.1:6379> get 123
"test"
127.0.0.1:6379>

 

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   #停止開機自啓動

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章