編譯安裝redis,systemtcl配置redis自啟動,系統并發調優
1、編譯安裝redis
wget https://download.redis.io/releases/redis-7.4.2.tar.gz
tar -zxf redis-7.4.2.tar.gz
cd redis-7.4.2/
make
make install/usr/local/bin/redis-server -v
2、systemtcl配置redis自啟動
[Unit]
Description=Redis In-Memory Data Store
After=network.target[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli -a 1234qwer shutdown
Restart=always
Type=simple[Install]
WantedBy=multi-user.target
注意:
(1)如果在命令行里復制粘貼,可能會丟失前四個字母。
可通過systemd-analyze verify /etc/systemd/system/redis.service驗證語法是否正確
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl enable redis
Failed to execute operation: Bad message
# 檢驗/etc/systemd/system/redis.service文件格式
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemd-analyze verify /etc/systemd/system/redis.service
[/etc/systemd/system/redis.service:1] Assignment outside of section. Ignoring.
[/etc/systemd/system/redis.service:2] Assignment outside of section. Ignoring.
[/etc/systemd/system/redis.service:3] Assignment outside of section. Ignoring.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemd-analyze verify /etc/systemd/system/redis.service
[root@iZ8vb45ie77v5ybgcemxysZ ~]#
(2)如果redis配置了密碼,停止命令要加上redis-cli -a <密碼> [操作參數]
# 無密碼關閉
ExecStop=/usr/local/bin/redis-cli shutdown
# 有密碼關閉
ExecStop=/usr/local/bin/redis-cli -a 1234qwer shutdown
3、權限不足導致redis無法重啟的問題
配置完redis.service還沒有完,redis會操作三個系統文件或目錄:
/var/run/redis_6379.pid 存放當前redis進程的進程號,配置:pidfile /var/run/redis_6379.pid
/var/lib/redis/(目錄) 存放redis持久化數據庫,配置:dir /var/lib/redis
/var/log/redis/redis.log 存放redis運行日志,配置:logfile /var/log/redis/redis.log
需要將/var/run/redis_6379.pid/、/var/lib/redis/目錄和/var/log/redis/目錄賦予redis用戶操作權限
(1)解決redis_6379.pid文件寫權限問題
# 根據打印Failed to write PID file: Permission denied[root@iZ8vb45ie77v5ybgcemxysZ ~]# touch /var/run/redis_6379.pid
[root@iZ8vb45ie77v5ybgcemxysZ ~]# chown redis:redis /var/run/redis_6379.pid#
# #logfile ""
logfile /var/log/redis/redis.log
(2)解決log文件缺失問題
# 根據提示(error) ERR Errors trying to SHUTDOWN. Check logs.
# 先設置log目錄權限
chown redis:redis /var/log/redis
修改/etc/redis/redis.conf配置項
# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
#logfile ""logfile /var/log/redis/redis.log
(3)解決db文件寫權限問題
# 根據redis.log中的報錯
9518:M 20 Mar 2025 12:16:54.936 # Failed opening the temp RDB file temp-9518.rdb (in server root dir /) for saving: Permission denied
9518:M 20 Mar 2025 12:16:54.936 # Error trying to save the DB, can't exit.
9518:M 20 Mar 2025 12:16:54.936 # Errors trying to shut down the server. Check the logs for more information.# 創建相應路徑并賦予權限
chown redis:redis /var/lib/redis
修改/etc/redis/redis.conf配置項
# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
#dir ./dir /var/lib/redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# ps -ef|grep redis
redis 898 1 0 11:34 ? 00:00:03 /usr/local/bin/redis-server 0.0.0.0:6379
root 1502 1416 0 11:54 pts/0 00:00:00 grep --color=auto redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl status reids
Unit reids.service could not be found.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl status redis
● redis.service - Redis In-Memory Data StoreLoaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)Active: active (running) since Thu 2025-03-20 11:34:43 CST; 19min agoMain PID: 898 (redis-server)CGroup: /system.slice/redis.service└─898 /usr/local/bin/redis-server 0.0.0.0:6379Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:C 20 Mar 2025 11:34:43.508 * Configuration loaded
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.509 # You requested maxclients of 10000 requi...ptors.
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.509 # Server can't set maximum open files to ...itted.
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.509 # Current maximum open files is 4096. max...t -n'.
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.509 * monotonic clock: POSIX clock_gettime
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.511 # Failed to write PID file: Permission denied
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.511 * Running mode=standalone, port=6379.
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.511 # WARNING: The TCP backlog setting of 511...f 128.
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.514 * Server initialized
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.517 * Ready to accept connections tcp
Hint: Some lines were ellipsized, use -l to show in full.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# touch /var/run/redis_6379.pid
[root@iZ8vb45ie77v5ybgcemxysZ ~]# chown redis:redis /var/run/redis_6379 .pid
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl restart redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl status redis
● redis.service - Redis In-Memory Data StoreLoaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)Active: active (running) since Thu 2025-03-20 12:05:30 CST; 1min 12s agoProcess: 5032 ExecStop=/usr/local/bin/redis-cli shutdown (code=exited, status=0/SUCCESS)Main PID: 5575 (redis-server)CGroup: /system.slice/redis.service└─5575 /usr/local/bin/redis-server 0.0.0.0:6379Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:C 20 Mar 2025 12:05:30.760 * Redis version=7.4.2, bits=64, commit=0...arted
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:C 20 Mar 2025 12:05:30.760 * Configuration loaded
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:M 20 Mar 2025 12:05:30.760 # You requested maxclients of 10000 requ...tors.
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:M 20 Mar 2025 12:05:30.760 # Server can't set maximum open files to...tted.
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:M 20 Mar 2025 12:05:30.760 # Current maximum open files is 4096. ma... -n'.
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:M 20 Mar 2025 12:05:30.760 * monotonic clock: POSIX clock_gettime
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:M 20 Mar 2025 12:05:30.761 * Running mode=standalone, port=6379.
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:M 20 Mar 2025 12:05:30.761 # WARNING: The TCP backlog setting of 51... 128.
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:M 20 Mar 2025 12:05:30.761 * Server initialized
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:M 20 Mar 2025 12:05:30.761 * Ready to accept connections tcp
Hint: Some lines were ellipsized, use -l to show in full.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# ps -ef|grep redis
redis 5575 1 0 12:05 ? 00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root 6189 1416 0 12:07 pts/0 00:00:00 grep --color=auto redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# cat /var/run/redis_6379.pid
5575
[root@iZ8vb45ie77v5ybgcemxysZ ~]# redis-cli shutdown
(error) NOAUTH Authentication required.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# redis-cli -a 1234qwer shutdown
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
(error) ERR Errors trying to SHUTDOWN. Check logs.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# redis-cli -a 1234qwer ping
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
PONG
[root@iZ8vb45ie77v5ybgcemxysZ ~]# redis-cli
127.0.0.1:6379> auth
(error) ERR wrong number of arguments for 'auth' command
127.0.0.1:6379> auth 1234qwer
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> SHUTDOWN
(error) ERR Errors trying to SHUTDOWN. Check logs.
127.0.0.1:6379> kill -9 5575
(error) ERR unknown command 'kill', with args beginning with: '-9' '5575'
127.0.0.1:6379> quit
[root@iZ8vb45ie77v5ybgcemxysZ ~]# kill -9 5575
[root@iZ8vb45ie77v5ybgcemxysZ ~]# ps -ef|grep redis
redis 9518 1 0 12:16 ? 00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root 9549 1416 0 12:16 pts/0 00:00:00 grep --color=auto redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# cat /var/run/redis_6379.pid
9518
[root@iZ8vb45ie77v5ybgcemxysZ ~]# redis-cli -a 1234qwer shutdown
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
(error) ERR Errors trying to SHUTDOWN. Check logs.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# kill -9 9518
[root@iZ8vb45ie77v5ybgcemxysZ ~]# ps -ef|grep redis
redis 11057 1 0 12:20 ? 00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root 11094 1416 0 12:20 pts/0 00:00:00 grep --color=auto redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# cat /var/run/redis_6379.pid
11057
[root@iZ8vb45ie77v5ybgcemxysZ ~]# redis-cli shutdown
(error) NOAUTH Authentication required.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# redis-cli -a 1234qwer shutdown
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# ps -ef|grep redis
redis 11240 1 0 12:20 ? 00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root 11289 1416 0 12:21 pts/0 00:00:00 grep --color=auto redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl daemon-reload
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl stop redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl status redis
● redis.service - Redis In-Memory Data StoreLoaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)Active: inactive (dead) since Thu 2025-03-20 12:23:14 CST; 5s agoProcess: 12130 ExecStop=/usr/local/bin/redis-cli -a 1234qwer shutdown (code=exited, status=0/SUCCESS)Process: 11240 ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)Main PID: 11240 (code=exited, status=0/SUCCESS)Mar 20 12:20:54 iZ8vb45ie77v5ybgcemxysZ systemd[1]: Started Redis In-Memory Data Store.
Mar 20 12:23:14 iZ8vb45ie77v5ybgcemxysZ systemd[1]: Stopping Redis In-Memory Data Store...
Mar 20 12:23:14 iZ8vb45ie77v5ybgcemxysZ redis-cli[12130]: Warning: Using a password with '-a' or '-u' option on the command line in... safe.
Mar 20 12:23:14 iZ8vb45ie77v5ybgcemxysZ systemd[1]: Stopped Redis In-Memory Data Store.
Hint: Some lines were ellipsized, use -l to show in full.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# ps -ef|grep redis
root 12196 1416 0 12:23 pts/0 00:00:00 grep --color=auto redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl start redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl status redis
● redis.service - Redis In-Memory Data StoreLoaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)Active: active (running) since Thu 2025-03-20 12:23:31 CST; 4s agoProcess: 12130 ExecStop=/usr/local/bin/redis-cli -a 1234qwer shutdown (code=exited, status=0/SUCCESS)Main PID: 12239 (redis-server)CGroup: /system.slice/redis.service└─12239 /usr/local/bin/redis-server 0.0.0.0:6379Mar 20 12:23:31 iZ8vb45ie77v5ybgcemxysZ systemd[1]: Started Redis In-Memory Data Store.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl restart redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# ps -ef|grep redis
redis 12368 1 0 12:23 ? 00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root 12423 1416 0 12:23 pts/0 00:00:00 grep --color=auto redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl restart redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# ps -ef|grep redis
redis 12456 1 0 12:24 ? 00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root 12475 1416 0 12:24 pts/0 00:00:00 grep --color=auto redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]#
(4)解決內存過度分配(Memory Overcommit)未啟用問題
11057:C 20 Mar 2025 12:20:26.509 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. 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.
從日志信息來看,Redis 提示 內存過度分配(Memory Overcommit)未啟用,這可能會導致在低內存條件下后臺保存(RDB 快照)或復制失敗。Redis 建議啟用內存過度分配以避免此類問題。
什么是內存過度分配(Memory Overcommit)?
內存過度分配是 Linux 內核的一種機制,允許系統分配比實際物理內存更多的內存。Redis 依賴于這種機制來確保在內存不足時仍能正常工作(例如,執行 RDB 快照或復制操作)。
默認情況下,Linux 內核的內存過度分配策略可能是保守的(vm.overcommit_memory = 0
),這會導致 Redis 在某些情況下無法分配足夠的內存。
為了永久啟用內存過度分配,需要修改 /etc/sysctl.conf
文件:
- 打開
/etc/sysctl.conf
文件:
sudo vi /etc/sysctl.conf
- 在文件末尾添加以下內容:
vm.overcommit_memory = 1
-
保存并退出編輯器。
-
應用更改:
sudo sysctl -p
(5) TCP 連接隊列的最大長度(即 backlog
隊列)不足問題,提高系統并發性能
31867:M 20 Mar 2025 13:18:00.467 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
這個警告信息表明 Redis 在啟動時嘗試設置 TCP 連接的 backlog
參數為 511
,但操作系統內核的 /proc/sys/net/core/somaxconn
參數值被設置為 128
,低于 Redis 的配置值,因此 Redis 無法生效其配置。
:::
什么是 backlog
?
backlog
是 TCP 連接隊列的長度,用于存儲等待被 Redis 接受的客戶端連接。如果連接請求的數量超過了 backlog
的值,新的連接請求可能會被拒絕。
Redis 默認的 backlog
值是 511
。
操作系統內核的 somaxconn
參數限制了 backlog
的最大值。
:::
:::
什么是 **somaxconn**
?
net.core.somaxconn
是 Linux 內核參數,用于控制 TCP 連接隊列的最大長度(即 backlog
隊列)。當客戶端嘗試連接到服務器時,如果服務器正在處理其他連接,新的連接請求會被放入 backlog
隊列中,等待服務器接受。
默認值通常是 128
。
如果 backlog
隊列已滿,新的連接請求會被拒絕,客戶端可能會收到 Connection refused
或超時錯誤。
:::
永久設置
- 編輯
/etc/sysctl.conf
文件:
sudo nano /etc/sysctl.conf
- 添加或修改以下行:
net.core.somaxconn=1024
- 保存并退出,然后應用更改:
sudo sysctl -p
- 驗證修改:
cat /proc/sys/net/core/somaxconn
centos操作命令
[root@iZ8vb45ie77v5ybgcemxysZ ~]# ps -ef|grep redis
redis 898 1 0 11:34 ? 00:00:03 /usr/local/bin/redis-server 0.0.0.0:6379
root 1502 1416 0 11:54 pts/0 00:00:00 grep --color=auto redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl status reids
Unit reids.service could not be found.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl status redis
● redis.service - Redis In-Memory Data StoreLoaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)Active: active (running) since Thu 2025-03-20 11:34:43 CST; 19min agoMain PID: 898 (redis-server)CGroup: /system.slice/redis.service└─898 /usr/local/bin/redis-server 0.0.0.0:6379Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:C 20 Mar 2025 11:34:43.508 * Configuration loaded
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.509 # You requested maxclients of 10000 requi...ptors.
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.509 # Server can't set maximum open files to ...itted.
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.509 # Current maximum open files is 4096. max...t -n'.
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.509 * monotonic clock: POSIX clock_gettime
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.511 # Failed to write PID file: Permission denied
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.511 * Running mode=standalone, port=6379.
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.511 # WARNING: The TCP backlog setting of 511...f 128.
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.514 * Server initialized
Mar 20 11:34:43 iZ8vb45ie77v5ybgcemxysZ redis-server[898]: 898:M 20 Mar 2025 11:34:43.517 * Ready to accept connections tcp
Hint: Some lines were ellipsized, use -l to show in full.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# touch /var/run/redis_6379.pid
[root@iZ8vb45ie77v5ybgcemxysZ ~]# chown redis:redis /var/run/redis_6379 .pid
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl restart redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl status redis
● redis.service - Redis In-Memory Data StoreLoaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)Active: active (running) since Thu 2025-03-20 12:05:30 CST; 1min 12s agoProcess: 5032 ExecStop=/usr/local/bin/redis-cli shutdown (code=exited, status=0/SUCCESS)Main PID: 5575 (redis-server)CGroup: /system.slice/redis.service└─5575 /usr/local/bin/redis-server 0.0.0.0:6379Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:C 20 Mar 2025 12:05:30.760 * Redis version=7.4.2, bits=64, commit=0...arted
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:C 20 Mar 2025 12:05:30.760 * Configuration loaded
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:M 20 Mar 2025 12:05:30.760 # You requested maxclients of 10000 requ...tors.
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:M 20 Mar 2025 12:05:30.760 # Server can't set maximum open files to...tted.
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:M 20 Mar 2025 12:05:30.760 # Current maximum open files is 4096. ma... -n'.
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:M 20 Mar 2025 12:05:30.760 * monotonic clock: POSIX clock_gettime
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:M 20 Mar 2025 12:05:30.761 * Running mode=standalone, port=6379.
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:M 20 Mar 2025 12:05:30.761 # WARNING: The TCP backlog setting of 51... 128.
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:M 20 Mar 2025 12:05:30.761 * Server initialized
Mar 20 12:05:30 iZ8vb45ie77v5ybgcemxysZ redis-server[5575]: 5575:M 20 Mar 2025 12:05:30.761 * Ready to accept connections tcp
Hint: Some lines were ellipsized, use -l to show in full.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# ps -ef|grep redis
redis 5575 1 0 12:05 ? 00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root 6189 1416 0 12:07 pts/0 00:00:00 grep --color=auto redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# cat /var/run/redis_6379.pid
5575
[root@iZ8vb45ie77v5ybgcemxysZ ~]# redis-cli shutdown
(error) NOAUTH Authentication required.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# redis-cli -a 1234qwer shutdown
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
(error) ERR Errors trying to SHUTDOWN. Check logs.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# redis-cli -a 1234qwer ping
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
PONG
[root@iZ8vb45ie77v5ybgcemxysZ ~]# redis-cli
127.0.0.1:6379> auth
(error) ERR wrong number of arguments for 'auth' command
127.0.0.1:6379> auth 1234qwer
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> SHUTDOWN
(error) ERR Errors trying to SHUTDOWN. Check logs.
127.0.0.1:6379> kill -9 5575
(error) ERR unknown command 'kill', with args beginning with: '-9' '5575'
127.0.0.1:6379> quit
[root@iZ8vb45ie77v5ybgcemxysZ ~]# kill -9 5575
[root@iZ8vb45ie77v5ybgcemxysZ ~]# ps -ef|grep redis
redis 9518 1 0 12:16 ? 00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root 9549 1416 0 12:16 pts/0 00:00:00 grep --color=auto redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# cat /var/run/redis_6379.pid
9518
[root@iZ8vb45ie77v5ybgcemxysZ ~]# redis-cli -a 1234qwer shutdown
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
(error) ERR Errors trying to SHUTDOWN. Check logs.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# kill -9 9518
[root@iZ8vb45ie77v5ybgcemxysZ ~]# ps -ef|grep redis
redis 11057 1 0 12:20 ? 00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root 11094 1416 0 12:20 pts/0 00:00:00 grep --color=auto redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# cat /var/run/redis_6379.pid
11057
[root@iZ8vb45ie77v5ybgcemxysZ ~]# redis-cli shutdown
(error) NOAUTH Authentication required.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# redis-cli -a 1234qwer shutdown
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# ps -ef|grep redis
redis 11240 1 0 12:20 ? 00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root 11289 1416 0 12:21 pts/0 00:00:00 grep --color=auto redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl daemon-reload
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl stop redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl status redis
● redis.service - Redis In-Memory Data StoreLoaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)Active: inactive (dead) since Thu 2025-03-20 12:23:14 CST; 5s agoProcess: 12130 ExecStop=/usr/local/bin/redis-cli -a 1234qwer shutdown (code=exited, status=0/SUCCESS)Process: 11240 ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)Main PID: 11240 (code=exited, status=0/SUCCESS)Mar 20 12:20:54 iZ8vb45ie77v5ybgcemxysZ systemd[1]: Started Redis In-Memory Data Store.
Mar 20 12:23:14 iZ8vb45ie77v5ybgcemxysZ systemd[1]: Stopping Redis In-Memory Data Store...
Mar 20 12:23:14 iZ8vb45ie77v5ybgcemxysZ redis-cli[12130]: Warning: Using a password with '-a' or '-u' option on the command line in... safe.
Mar 20 12:23:14 iZ8vb45ie77v5ybgcemxysZ systemd[1]: Stopped Redis In-Memory Data Store.
Hint: Some lines were ellipsized, use -l to show in full.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# ps -ef|grep redis
root 12196 1416 0 12:23 pts/0 00:00:00 grep --color=auto redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl start redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl status redis
● redis.service - Redis In-Memory Data StoreLoaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)Active: active (running) since Thu 2025-03-20 12:23:31 CST; 4s agoProcess: 12130 ExecStop=/usr/local/bin/redis-cli -a 1234qwer shutdown (code=exited, status=0/SUCCESS)Main PID: 12239 (redis-server)CGroup: /system.slice/redis.service└─12239 /usr/local/bin/redis-server 0.0.0.0:6379Mar 20 12:23:31 iZ8vb45ie77v5ybgcemxysZ systemd[1]: Started Redis In-Memory Data Store.
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl restart redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# ps -ef|grep redis
redis 12368 1 0 12:23 ? 00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root 12423 1416 0 12:23 pts/0 00:00:00 grep --color=auto redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl restart redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# ps -ef|grep redis
redis 12456 1 0 12:24 ? 00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root 12475 1416 0 12:24 pts/0 00:00:00 grep --color=auto redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# sysctl -p
vm.swappiness = 0
kernel.sysrq = 1
net.ipv4.neigh.default.gc_stale_time = 120
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_announce = 2
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 1024
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_slow_start_after_idle = 0
vm.overcommit_memory = 1
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl restart redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]# sysctl -p
vm.swappiness = 0
kernel.sysrq = 1
net.ipv4.neigh.default.gc_stale_time = 120
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_announce = 2
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 1024
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_slow_start_after_idle = 0
vm.overcommit_memory = 1
net.core.somaxconn = 1024
[root@iZ8vb45ie77v5ybgcemxysZ ~]# cat /proc/sys/net/core/somaxconn
1024
[root@iZ8vb45ie77v5ybgcemxysZ ~]# systemctl restart redis
[root@iZ8vb45ie77v5ybgcemxysZ ~]#