redis 进程使用root用户启动 -- 整改方案

 

 

最近内部风险整改, 各种进程使用root身份进行启动不符合要求,

于是各路神仙各施其法,为的就是让 某进程不以root 启动:

 

先以 redis 为例: 

原有进程如下:

#超一流标准的执行文件位置及配置文件位置

root     9602      1  0 23:25 ?        00:00:00   /usr/bin/redis-server  /etc/redis/redis.conf   

 

于是有了以下操作:

一 、简单直接类

# kill -9 9602

# su   redis

This account is currently not available

# usermod -s /bin/bash

# su redis 

# /usr/bin/redis-server  /etc/redis/redis.conf   

于是redis由一个非登录用户变成了一个登陆用户,而且下次开机还是要手动启动一次进程。。 

 

二、开机启动类

# echo 'su -c "/usr/bin/redis-server  /etc/redis/redis.conf" redis ' >> /etc/rc.local

测试了一下

#  /bin/bash /etc/rc.local

This account is currently not available

# vi  /etc/rc.local  

把redis改为了 newuser

# useradd newuser

#  /bin/bash /etc/rc.local

于是服务开机启动设置成功,但redis被弃用了。。

 

三 、 服务设置类 (推荐)

# echo '

[Unit]
Description=redis daemon

[Service]

Type=forking

#这个是配置启动用户
User=redis
ExecStart= /usr/bin/redis-server  /etc/redis/redis.conf   
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

'  >  /usr/lib/systemd/system/redisd.service

# chown -R redis /var/log/redis/     (日志文件redis需要有读写权限,具体日志文件位置不细说 我的就当作放在这里)

# systemctl start redisd

# systemctl enable redisd 

Created symlink from /etc/systemd/system/multi-user.target.wants/redisd.service to /usr/lib/systemd/system/redisd.service

# ps -ef|grep redisd

redis     10175      1  0 23:52 ?        00:00:00 /usr/bin/redis-server *:6379

设置成了服务自启动,还是以redis用户启动了,是不是很高大上?

posted @ 2019-08-01 23:56  caya  阅读(4261)  评论(0编辑  收藏  举报