Redis系列(一)、CentOS7下安裝Redis6.0.3穩定版

目錄

簡介

特點

下載

環境準備

編譯安裝

配置啓動

開機自啓

使用Redis Desktop Manager連接Redis


簡介

Redis,全稱 Remote Dictionary Server(遠程字典服務器) ,全開源基於C語言開發,是高性能的(key/value)分佈式內存數據庫,基於內存運行並支持持久化的NoSQL數據庫,是當前最熱門的NoSQL數據庫之一,也被人們稱爲數據結構服務器。

在線測試:http://try.redis.io/ 

使用文檔:http://doc.redisfans.com/

特點

1、Redis支持數據的持久化,可以將內存中的數據保存在磁盤中,重啓的時候可以再次加載進行使用。
2、Redis不僅僅支持簡單的key - value類型的數據,同時還提供list、set、zset、hash等數據結構的存儲。
3、Redis支持數據的備份,即master - slave模式的數據備份。
 

大部分企業可能還在使用redis4的版本,今年redis也迎來了6的版本更新,這次更新最大的改變應該就是支持了多線程,性能相較於上一代有大幅提升 ,那本篇就介紹如何在CentOS7下安裝Redis6.0.3 最新穩定版。

下載

歷史版本:http://download.redis.io/releases/

redis6.0.3:http://download.redis.io/releases/redis-6.0.3.tar.gz

環境準備

編譯安裝需要gcc5.3以上,可以用gcc -v 命令查看當前版本號,使用下面的命令升級到gcc9.1:

yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
#scl命令啓用只是臨時的,新開的會話默認還是原gcc版本。

#如果要長期使用gcc 9.1的話執行下面的命令即可:
echo -e "\nsource /opt/rh/devtoolset-9/enable" >>/etc/profile

編譯安裝

使用命令解壓下載好的redis源碼並編譯安裝:

#解壓
tar -zxvf redis-6.0.3.tar.gz -C .

#編譯
cd redis-6.0.3/
make
make install PREFIX=/opt/app/redis6

#如果編譯出錯之後再編譯可以先執行命令刪除之前的編譯文件
make distclean

編譯完了可以執行命令測試:

#測試需要依賴tcl
yum install tcl -y

#測試
make test

配置啓動

進入到安裝的目錄/opt/app/redis6下 將源碼中的redis.conf文件 複製到redis6的bin目錄下並修改配置:

mkdir /opt/app/redis6/data

cp /home/wyk/redis-6.0.3/redis.conf /opt/app/redis6/bin/

vim /opt/app/redis6/bin/redis.conf

修改以下幾個參數:

#daemonize no 改爲yes,開啓後臺運行,默認是前臺運行
daemonize yes

#把這一行註釋,監聽所有IP
#bind 127.0.0.1


#protected-mode yes 如果改爲no,則是關閉保護模式,這種模式下不能配置系統服務,建議還是開啓
protected-mode yes

#requirpass,保護模式開啓的時候要配置密碼或者bind ip
requirepass 123456

#修改本參數,指定數據目錄
dir /opt/app/redis6/data

#修改本參數,指定日誌目錄
logfile /opt/app/redis6/redis_6379.log

執行下面的命令後臺啓動redis(建議配置環境變量$REDIS_HOME):

cd /opt/app/redis6/bin
./redis-server redis.conf

開機自啓

註冊服務:

vim /lib/systemd/system/redis.service

[Unit]
Description=Redis
After=network.target

[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/opt/app/redis6/bin/redis-server /opt/app/redis6/bin/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 使用systemctl命令:

# 重載服務
systemctl daemon-reload

# 開機自啓
systemctl enable redis

# 啓動
systemctl start redis
 
# 重啓
systemctl restart redis     
 
# 停止
systemctl stop redis

# 查看狀態
systemctl status redis
 
# 關閉開機啓動
systemctl disable redis

使用Redis Desktop Manager連接Redis

下載安裝redis desktop manager:

Github: https://github.com/uglide/RedisDesktopManager

官網: https://redisdesktop.com/

配置防火牆,嫌麻煩直接關閉即可:

#查看防火牆狀態
systemctl status firewalld

#關閉防火牆
service firewalld stop

#開啓防火牆
service firewalld start

#單獨開6379端口
firewall-cmd --permanent --add-port=6379
tcpfirewall-cmd --reload

由於上面的配置我們已經開啓了所有IP的監聽,因此可以直接連接:

關閉保護模式且無密碼模式:

開啓保護模式設置密碼,以systemctl命令啓動和開機自啓:

 

希望本文對你有幫助,請點個贊鼓勵一下作者吧~ 謝謝!

 

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