在CentOS上配置Redis并设置日志级别的指南如下:
sudo yum update -y
sudo yum install epel-release -y
sudo yum install redis -y
/etc/redis.conf
。vi
或 nano
)打开它:sudo vi /etc/redis.conf
daemonize
参数设置为 yes
:daemonize yes
requirepass
行并设置一个密码:requirepass your_password
bind
为 127.0.0.1
。0.0.0.0
:# bind 127.0.0.1
protected-mode
改为 no
,以允许公网访问:protected-mode no
debug
、verbose
、notice
、warning
。notice
级别足够满足日常需求。如果需要更详细的信息,可以设置为 verbose
或 debug
,但要注意日志量会显著增加。例如:loglevel notice
logfile /var/log/redis/redis-server.log
sudo systemctl start redis
sudo vi /etc/systemd/system/redis.service
文件内容如下:
[Unit]
Description=Redis Server
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis.pid
ExecStart=/usr/local/bin/redis-server /etc/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable redis
tail -f
命令实时查看日志文件:tail -f /var/log/redis/redis-server.log
CONFIG
命令查看日志级别redis-cli CONFIG GET loglevel
CONFIG
命令设置日志级别redis-cli CONFIG SET loglevel "verbose"