centos8平台安裝redis6.0.1


一,redis的官網:

https://redis.io/

 

redis6於5月3日正式發布,它的新增功能:

acl

多線程io

cluster proxy

resp3協議

本文演示redis6.0.1的安裝

 

說明:劉宏締的架構森林是一個專注架構的博客,地址:https://www.cnblogs.com/architectforest

         對應的源碼可以訪問這里獲取: https://github.com/liuhongdi/

說明:作者:劉宏締 郵箱: 371125307@qq.com

 

二,檢查gcc的版本

[root@centos8 liuhongdi]# gcc --version
gcc (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4)
Copyright © 2018 Free Software Foundation, Inc.
本程序是自由軟件;請參看源代碼的版權聲明。本軟件沒有任何擔保;
包括沒有適銷性和某一專用目的下的適用性擔保。

如果提示找不到gcc程序,說明沒有安裝,

可以用dnf命令安裝

[root@centos8 liuhongdi]# dnf install gcc

 

說明:gcc版本不宜過低,應該在gcc 5.3以上

如版本過低則建議先升級gcc

 

三,下載redis6並解壓縮

下載

[root@centos8 source]# wget http://download.redis.io/releases/redis-6.0.1.tar.gz

 

解壓縮

[root@centos8 source]# tar -zxvf redis-6.0.1.tar.gz 

 

四,安裝redis6.0.1

1,安裝redis

#PREFIX=/usr/local/soft/redis6 :用來指定安裝目錄,這里我們指定安裝到/usr/local/soft/redis6

[root@centos8 source]# cd redis-6.0.1/
[root@centos8 redis-6.0.1]# make PREFIX=/usr/local/soft/redis6 install

 

2,生成配置文件

創建安裝目錄

[root@centos8 redis-6.0.1]# mkdir /usr/local/soft/redis6/conf

把源碼目錄下的redis.conf復制到安裝目錄

[root@centos8 redis-6.0.1]# cp redis.conf /usr/local/soft/redis6/conf/

 

五,創建供redis運行的目錄

分別用來存放redis的日志和數據

logs:存放日志

data:存放快照數據

[root@centos8 data]# mkdir -p /data/redis6
[root@centos8 data]# cd /data/redis6/
[root@centos8 redis6]# mkdir logs
[root@centos8 redis6]# mkdir data

 

六,修改redis的配置文件:

[root@centos8 conf]# vi redis.conf 

 

配置項:

#綁定訪問的ip

bind 192.168.1.7

 

#使以daemon方式運行

daemonize yes

 

#日志保存目錄

logfile "/data/redis6/logs/redis.log"

 

#數據保存目錄

dir /data/redis6/data/

 

#使用的最大內存數量

maxmemory 128MB 

 

#io線程數

#系統建議設置為cpu核心數量的3/4,我的機器是4核,所以這里設置為3

io-threads 3

附redis.conf中的原說明:

# So for instance if you have a four cores boxes, try to use 2 or 3 I/O
# threads, if you have a 8 cores, try to use 6 threads. In order to
# enable I/O threads use the following configuration directive:

 

如何查看核心數量:

[root@centos8 ~]# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
...
CPU(s)顯示是4個核心

 

七,生成供systemd使用的service文件

[root@centos8 ~]# vi /lib/systemd/system/redis6.service

 

內容:

[Unit]
Description=Redis
After=network.target

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

[Install]
WantedBy=multi-user.target

 

重新加載service文件

[root@centos8 ~]# systemctl daemon-reload 

 

七,測試啟動redis6:

啟動:

[root@centos8 ~]# systemctl start redis6

 

停止:

[root@centos8 ~]# systemctl stop redis6

 

八,測試從本地連接訪問:

[root@centos8 conf]# /usr/local/soft/redis6/bin/redis-cli -h 192.168.1.7
192.168.1.7:6379> set a aaaa
OK
192.168.1.7:6379> get a
"aaaa"

 

九,查看已安裝redis的版本

[root@centos8 conf]# /usr/local/soft/redis6/bin/redis-server -v
Redis server v=6.0.1 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=0

 

十,查看centos的版本

[root@centos8 conf]# cat /etc/redhat-release 
CentOS Linux release 8.1.1911 (Core) 

 


免責聲明!

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



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