最近内部风险整改, 各类进程使用root身份进行启动不符合要求, redis
因而各路神仙各施其法,为的就是让 某进程不以root 启动:bash
先以 redis 为例: 测试
原有进程以下:spa
#超一流标准的执行文件位置及配置文件位置日志
root 9602 1 0 23:25 ? 00:00:00 /usr/bin/redis-server /etc/redis/redis.conf server
因而有了如下操做:进程
一 、简单直接类ip
# kill -9 9602get
# su redisit
This account is currently not available
# usermod -s /bin/bash
# su redis
# /usr/bin/redis-server /etc/redis/redis.conf
因而redis由一个非登陆用户变成了一个登录用户,并且下次开机仍是要手动启动一次进程。。
2、开机启动类
# 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用户启动了,是否是很高大上?