当前位置: 首页 > article >正文

编译安装redis,systemtcl配置redis自启动,系统并发调优

编译安装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 Store
   Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2025-03-20 11:34:43 CST; 19min ago
 Main PID: 898 (redis-server)
   CGroup: /system.slice/redis.service
           └─898 /usr/local/bin/redis-server 0.0.0.0:6379

Mar 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 Store
   Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2025-03-20 12:05:30 CST; 1min 12s ago
  Process: 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:6379

Mar 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 Store
   Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Thu 2025-03-20 12:23:14 CST; 5s ago
  Process: 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 Store
   Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2025-03-20 12:23:31 CST; 4s ago
  Process: 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:6379

Mar 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 文件:

  1. 打开 /etc/sysctl.conf 文件:
sudo vi /etc/sysctl.conf
  1. 在文件末尾添加以下内容:
vm.overcommit_memory = 1
  1. 保存并退出编辑器。

  2. 应用更改:

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 或超时错误。
:::

永久设置
  1. 编辑 /etc/sysctl.conf 文件:
sudo nano /etc/sysctl.conf
  1. 添加或修改以下行:
net.core.somaxconn=1024
  1. 保存并退出,然后应用更改:
sudo sysctl -p
  1. 验证修改:
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 Store
   Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2025-03-20 11:34:43 CST; 19min ago
 Main PID: 898 (redis-server)
   CGroup: /system.slice/redis.service
           └─898 /usr/local/bin/redis-server 0.0.0.0:6379

Mar 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 Store
   Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2025-03-20 12:05:30 CST; 1min 12s ago
  Process: 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:6379

Mar 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 Store
   Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Thu 2025-03-20 12:23:14 CST; 5s ago
  Process: 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 Store
   Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2025-03-20 12:23:31 CST; 4s ago
  Process: 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:6379

Mar 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 ~]#


http://www.kler.cn/a/598566.html

相关文章:

  • IMX8MP Android 10系统编译SDK
  • elasticsearch+sentencetransformer检索样例
  • 开源链动2+1模式、AI智能名片与S2B2C商城小程序源码在社交电商渠道拓宽中的协同应用研究
  • 石家庄 10 年 PHP 开发者转岗分析
  • Python 用户账户(让用户拥有自己的数据)
  • Java EE(13)——网络编程——UDP/TCP回显服务器
  • 【系统架构设计师】调用/返回体系结构风格
  • 如何在 Linux 中递归解压所有子目录下的 `.tar.gz` 文件
  • 前端面试:[React] scheduler 调度机制原理?
  • -PHP 应用文件管理模块包含上传遍历写入删除下载安全
  • 关于kafka的一些知识总结
  • 25届春招奇安信2面。。。
  • 【YOLO项目】毕设大作业之车道线检测
  • Super Logic Region (SLR) 在Xilinx FPGA架构
  • SQL Server Management Studio(SSMS)安装教程
  • 分布式算法:Paxos Raft 两种共识算法
  • 【MySQL】MySQL登录,访问,退出操作
  • Visual Studio(VS)的 Release 配置中生成程序数据库(PDB)文件
  • PostgreSQL_实例项目总述
  • 推荐算法分析