四.编写启动脚本
1.根据情况填写对应变量
vim man-redis
#!/bin/bash
install_dir=/usr/local
server_dir=redis
log_dir=/var/log
port=6379
if
[[
"$1"
==
"start"
]];then
netstat -unltp |grep :${port}
&>
/dev/null
-
if
[ $?
-eq 0
];then
echo "redis Already started"
exit
fi
nohup ${install_dir}/${server_dir}/bin/redis-server ${install_dir}/${server_dir}
&> ${log_dir}/${server_dir}/redis.log &
elif
[[
"$1"
==
"stop"
]];then
netstat -unltp |grep :${port}
&>
/dev/null
-
if
[ $?
-eq 0
];then
pid=`netstat -unltp | grep :${port}
| head -1
|awk '{print $7}'
| awk -F'/'
'{print $1}'`
kill -9 $pid
fi
else
echo "start | stop"
fi
2.添加权限,并加入到bin目录下,后面就可以当命令一样使用
mv man-redis /usr/local/bin
chmod x /usr/local/bin/man-redis
man-redis start