Linux系统下需要自行创建系统服务,下面介绍一下具体步骤。
【一】修改Redis配置文件
在Redis配置文件中将daemonize no 修改为daemonize yes
另外可以通过 port 设置端口,loglevel 日志级别, logfile 设置文件路径,requirepass 设置密码,databases 设置数据库数量等...
daemonize yes ...... port 1989 loglevel notice logfile "/home/wwwlogs/redis.log" requirepass 8d1714af databases 4
【二】新建服务
vim /etc/systemd/system/redis.service
编辑服务内容
[Unit] Description=redis-server After=network.target [Service] Type=forking # 这行配置内容要根据redis的安装目录自定义路径 ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf PrivateTmp=true [Install] WantedBy=multi-user.target
【三】启用服务
载入服务
systemctl daemon-reload
实现开机自启
systemctl enable redis
查看服务状态
[root@wzxaini9 ~]# systemctl status redis ● redis.service - redis-server Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2024-01-04 10:21:08 CST; 1min 24s ago Process: 881 ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf (code=exited, status=0/SUCCESS) Main PID: 895 (redis-server) CGroup: /system.slice/redis.service └─895 /usr/local/redis/bin/redis-server *:6379 Jan 04 10:21:08 wzxaini9 systemd[1]: Starting redis-server... Jan 04 10:21:08 wzxaini9 systemd[1]: Started redis-server.
登录后可发表评论