一般情况应用服务在linux中都是以普通用户安装运行,安装过程可以参照前面一篇文章
假设普通用户为test
- redis配置文件
$ cat /etc/redis.conf
daemonize yes
pidfile /usr/local/redis/run/redis.pid
port 6379
tcp-backlog 511
timeout 300
tcp-keepalive 0
loglevel notice
logfile "/usr/local/redis/log/redis.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /www/redisdata
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
requirepass 123456 //建议开启认证,开启认证的时候,要注意启动脚本需要注意添加-a
2.启动脚本/etc/init.d/redis,解压软件里面有自带脚本:
cd redis-stable
cp utils/redis_init_script /etc/init.d/redis
编辑/etc/init.d/redis注意pid,配置文件的路径,以及如果开启认证,关闭服务参数需要修改:
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
### BEGIN INIT INFO
# Provides: redis_6379
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Redis data structure server
# Description: Redis data structure server. See https://redis.io
### END INIT INFO
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server //以实际为主,看是默认安装,还是安装到指定路径
CLIEXEC=/usr/local/redis/bin/redis-cli //以实际为主
PASSWD=123456 //开启认证,添加这个变量,停止的时候需要加-a参数
PIDFILE=/usr/local/redis/run/redis.pid
CONF="/etc/redis.conf" //redis.conf配置文件
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -a $PASSWD -p $REDISPORT shutdown &> /dev/null
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac
3.编辑配置文件/etc/rc.d/rc.local,在末尾添加
source /etc/profile
su - test -c "/etc/init.d/redis start" >> /var/log/redisboot.log
chmod x /etc/rc.d/rc.local //注意要执行该命令,
4.检测
netstat -natp | grep 6379
ps -ef | grep reids //查看该用户是否普通用户
reboot //启动后进入系统,查看redis是否普通用户启动
总结:某应用要以普通用户启动,主要注意如下三点:
a.安装应用的目录,最好所属该普通用户;
b.应用所产生的数据目录,一般是建议用单独的数据盘挂载,并且所属该普通用户;
c.应用所产生的日志文件,pid文件等所属该普通用户。