一、下載redis 6.2.4的包
官網地址:https://redis.io/
中國區維護的網址:http://redis.cn/
二、解壓縮
tar xf redis-6.2.4_\(2\).tar.gz
三、安裝
1、安裝gcc編譯器
yum install gcc -y
2、進入解壓的目錄
cd redis-6.2.4
3、安裝,並指定安裝目錄
make PREFIX=/apps/redis install
注釋:指定安裝路徑,不指定目錄會放在當前目錄,目錄不存在會自動創建
四、復制源碼包中的配置文件
1、在/apps/redis 下創建etc(可以不做)
mkdir /apps/redis/etc
2、復制文件到/apps/redis 下的etc下(也可也直接復制到對應的redis目錄下)
cp /data/redis-6.2.4/redis.conf /apps/redis/etc/
五、啟動redis 服務
/apps/redis/bin/redis-server
會顯示警告:短期使用不會有問題,但長期使用會出問題
警告如下:
6970:M 07 Jul 2021 18:23:53.111 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 6970:M 07 Jul 2021 18:23:53.111 # Server initialized 6970:M 07 Jul 2021 18:23:53.111 # 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. 6970:M 07 Jul 2021 18:23:53.111 * Ready to accept connections
1、 這個值要求511, 目前設置的是128
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
cklog backlog 參數控制的是 三次 握手 的時候 server serverserver 端收到 client ackclient ack client ackclient ackclient ack 確認 號之后 的隊列值
配置為511或者更高的值:
解決辦法:
vim /etc/sysctl.conf 添加大於511的值即可 net.core.somaxconn = 512
使其生效:
sysctl -p
2、
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.
0、表示內核將檢查是否有足夠的可用內存供應用進程使用;如果有足夠的可用內存,內存申請允許;否則,內存申請失敗,並把錯誤返回給應用進程。
1、表示內核允許分配所有的物理內存,而不管當前的內存狀態如何。
2、表示內核允許分配超過所有物理內存和交換空間總和的內存
解決辦法:
vim /etc/sysctl.conf
vm.overcommit_memory = 1
使其生效:
sysctl -p
五、以服務的方式啟用
vim /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/apps/redis/bin/redis-server /apps/redis/etc/redis.conf --supervised systemd
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
1、以Redis用戶啟動,創建Redis用戶
useradd redis -s /sbin/nologin
2、修改redis目錄的所有者所有組為redis
chown redis.redis /apps/redis/ -R
或者使用軟連接方式
ln -sv /apps/redis/bin/redis-* /usr/bin/
注釋,如果報錯的話,可能是gcc沒安裝哦