CentOS 安裝 Redis

1、寫在前面

官方網站:https://redis.io/
建議下載穩定版本,截止到2019年10月27日,官網最新穩定版本爲5.0.5
下載方式1:官網下載redis-5.0.5.tar.gz,上傳到服務器
下載方式2:wget http://download.redis.io/releases/redis-5.0.5.tar.gz

2、安裝

2.1、安裝gcc/c++依賴:

[root@opt ~]# yum install gcc
[root@opt ~]# yum install gcc-c++

2.2、解壓,安裝

[root@opt ~]# tar -zxvf redis-5.0.5.tar.gz
[root@opt ~]# cd redis-5.0.5/
[root@opt ~]# make
[root@opt ~]# make install

2.3、測試是否安裝成功

[root@opt ~]# cd src
[root@opt ~]# pwd
/opt/redis-5.0.5/src
[root@opt ~]# ./redis-server

默認情況下,退出console就會退出redis,所以我們退出(Ctrl + C)當前resis進程
修改配置,使redis可以後臺運行,類似於java的nohup

2.4、編輯redis.conf配置文件前,建議先備份

[root@opt ~]# cd /opt/redis-5.0.5
[[email protected] ~]# cp redis.conf redis.conf.backup 
[[email protected] ~]# vim redis.conf


修改如下參數:
daemonize yes		## 是否後臺運行,修改爲yes,啓動不佔用窗口,後臺啓動
protected-mode no   ## 安全模式,修改爲no,關閉,不然遠程連接會報錯誤
bind 0.0.0.0  		## 指定IP訪問,修改爲指定ip,或者0.0.0.0,或者整行註釋掉
requirepass 123456	## 配置訪問密碼,不使用密碼,可整行註釋掉

2.5、配置開機啓動
1、創建/etc/redis/目錄
2、複製redis.conf配置文件到新建的目錄中,並改名:6379.conf
3、將redis的啓動腳本複製到/etc/init.d 目錄中
4、切換到init.d目錄中,設置redis啓動腳本開機啓動

[root@opt ~]# mkdir -p /etc/redis
[root@opt ~]# cp redis.conf /etc/redis/6379.conf
[root@opt ~]# cp utils/redis_init_script /etc/init.d/redisd
[root@opt ~]# cd /etc/init.d/
[root@opt ~]# chkconfig redisd on

3、啓動、停止 命令

[root@opt ~]# service redisd start
[root@opt ~]# service redisd stop

4、客戶端連接

redis-cli 參數說明:
-h 服務端ip地址
-p 服務端端口號
-a redis設置的密碼

[root@opt ~]# redis-cli -h 127.0.0.1 -p 6379 -a 123456

5、結束

愉快的玩耍吧

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