1. 程式人生 > 資料庫 >CentOS 安裝 Redis 6.0.9

CentOS 安裝 Redis 6.0.9

什麼是Redis?


 

Redis通常被稱為資料結構伺服器。這意味著Redis通過一組命令提供對可變資料結構的訪問,這些命令是使用帶有TCP套接字和簡單協議的伺服器-客戶端模型傳送的。因此,不同的程序可以以共享的方式查詢和修改相同的資料結構。

在Redis中實現的資料結構具有一些特殊屬性:

  • 即使始終為它們提供服務並將它們修改到伺服器記憶體中,Redis也會將它們儲存在磁碟上。這意味著Redis速度很快,但它也是非易失性的。
  • 資料結構的實現強調記憶體效率,因此與使用高階程式語言建模的相同資料結構相比,Redis內部的資料結構可能使用較少的記憶體。
  • Redis提供了許多自然可以在資料庫中找到的功能,例如複製,永續性的可調級別,叢集和高可用性。

另一個很好的例子是將Redis視為memcached的一個更復雜的版本,其中的操作不僅是SET和GET,而且還適用於諸如列表,集合,有序資料結構等複雜資料型別的操作。

 

Redis 6.0 新特性


Redis 6.0引入了SSL,新的RESP3協議,ACL,客戶端快取,無盤副本,I / O執行緒,更快的RDB載入,新的模組API以及許多其他改進。

 

安裝依賴包

[root@Mike-Node1 ~]#  yum -y install tcl gcc gcc-c++  make zlib zlib-devel

 

下載編譯安裝

[root@Mike-Node1 ~]# wget https://download.redis.io/releases/redis-6.0.9.tar.gz
[root@Mike-Node1 ~]# tar zxvf redis-6.0.9.tar.gz -C /usr/local/ && rm -rf redis-6.0.9.tar.gz
[root@Mike-Node1 ~]# cd /usr/local/redis-6.0.9/
[root@Mike-Node1 /usr/local/redis-6.0.9]# make && make install PREFIX=/usr/local/redis

遇到報錯

server.c: In function ‘allPersistenceDisabled’:
server.c:1484:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
server.c: In function ‘writeCommandsDeniedByDiskError’:
server.c:3934:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
server.c: In function ‘iAmMaster’:
server.c:5134:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
make[1]: *** [server.o] Error 1
make[1]: Leaving directory `/usr/local/redis-6.0.9/src'
make: *** [all] Error 2

出現這種錯誤是由於Redis6.0版本以上要求gcc需要5.3版本以上,升級gcc即可

預設gcc版本

[root@Mike-Node1 ~]# gcc -v
***********

gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
[root@Mike-Node1 ~]#

升級gcc版本

[root@Mike-Node1 ~]# yum -y install centos-release-scl
[root@Mike-Node1 ~]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
[root@Mike-Node1 ~]# echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
[root@Mike-Node1 ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-9/root/usr --mandir=/opt/rh/devtoolset-9/root/usr/share/man --infodir=/opt/rh/devtoolset-9/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-9.3.1-20200408/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC) 
[root@Mike-Node1 ~]# 

 

修改配置檔案

[root@Mike-Node1 /usr/local/redis-6.0.9]# cp -rf redis.conf /usr/local/redis/
[root@Mike-Node1 /usr/local/redis-6.0.9]# cd /usr/local/redis
[root@Mike-Node1 /usr/local/redis]# vim redis.conf

bind 127.0.0.1
daemonize yes
requirepass mike666
protected-mode no
logfile /usr/local/redis/logs/redis.log
dir /usr/local/redis/data

[root@Mike-Node1 /usr/local/redis]#
[root@Mike-Node1 /usr/local/redis]# mkdir logs data
[root@Mike-Node1 /usr/local/redis]# 

設定 redis密碼  mike666,日誌路徑和資料儲存路徑

 

啟動Redis

[root@Mike-Node1 /usr/local/redis]# vim /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/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

[root@Mike-Node1 /usr/local/redis]#
[root@Mike-Node1 /usr/local/redis]# systemctl daemon-reload
[root@Mike-Node1 /usr/local/redis]# systemctl start redis.service
[root@Mike-Node1 /usr/local/redis]# systemctl enable redis.service
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /etc/systemd/system/redis.service.
[root@Mike-Node1 /usr/local/redis]# 

 

設定軟連線

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

 

啟動警告解決

17468:M 16 Dec 2020 10:54:26.205 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
17468:M 16 Dec 2020 10:54:26.205 # Server initialized
17468:M 16 Dec 2020 10:54:26.205 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
17468:M 16 Dec 2020 10:54:26.205 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo madvise > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled (set to 'madvise' or 'never').
17468:M 16 Dec 2020 10:54:26.205 * Ready to accept connections

解決一

[root@Mike-Node1 ~]# vim /etc/sysctl.conf 

net.core.somaxconn = 1024
vm.overcommit_memory = 1


[root@Mike-Node1 ~]# sysctl -p

解決二

[root@Mike-Node1 ~]# vim /etc/rc.local

echo never > /sys/kernel/mm/transparent_hugepage/enabled


[root@Mike-Node1 ~]# source /etc/rc.local 
[root@Mike-Node1 ~]# systemctl restart 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   #停止開機自啟動

 

客戶端連線

[root@Mike-Node1 ~]# redis -h 127.0.0.1 -p 6379
127.0.0.1:6379> AUTH mike666
OK
127.0.0.1:6379> 

 

本文分享完畢,感謝支援點贊~~