当前位置: 移动技术网 > 科技>操作系统>Linux > redis 进程使用root用户启动 -- 整改方案

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

2019年08月02日  | 移动技术网科技  | 我要评论

 

 

最近内部风险整改, 各种进程使用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用户启动了,是不是很高大上?

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网