Linux各种服务配置开机自启
作者:互联网
一、Linux配置redis开机自启
(1)到redis配置文件中找到conf文件:vi redis.conf
(2)daemonize no 修改为:daemonize yes
(3)cd /etc/init.d,新建文件redis,可用该路径下:(/usr/local/redis/redis6.2.7/utils/redis_init_script)
(4)进行配置:
#!/bin/bash
#chkconfig: 22345 10 90
#description: Start and Stop redis
#端口
REDISPORT=6379
#server:/usr/local/redis/redis-6.2.7/src/redis-server
EXEC=/usr/local/redis/bin/redis-server
#/usr/local/redis/redis-6.2.7/src/redis-cli
CLIEXEC=/usr/local/redis/bin/redis-cli
#密码
REDISPWD=123456
#该文件路径可从conf文件中找
PIDFILE=/var/run/redis_6379.pid
#conf路径
CONF=/usr/local/redis/etc/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 -p $REDISPORT -a $REDISPWD shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart)
"$0" stop
sleep 3
"$0" start
;;
*)
echo "Please use start or stop or restart as first argument"
;;
esac
(5)修改文件权限:chmod 777 /etc/init.d/redis
(6)测试脚本
cd /etc/init.d
./redis start
./redis stop
ps -ef|grep redis
(7)配置开机自启
chkconfig --add /etc/init.d/redis
chkconfig redis on
二、Linux配置Oracle11g开机自启
(1)首先查看/etc路径下是否有oratab文件
如果没有root身份下执行以下命令
cd $ORACLE_HOME
./root.sh
(2)执行dbstart 数据库自带启动脚本
cd $ORACLE_HOME
cd bin/
#编辑dbstart以及dushut文件
ORACLE_HOME_LISTNER=$1修改成 ORACLE_HOME_LISTNER=$ORACLE_HOME,前提是$ORACLE_HOME环境设置正确:
(3)编辑oratab文件
vi /etc/oratab
将orcl:/u01/app/oracle/product/11.2.0/dbhome_1:N
修改成 orcl:/u01/app/oracle/product/11.2.0/dbhome_1:Y
注意:orcl为数据库实例名
(4)root用户编辑/etc/rc.d/rc.local启动文件,添加数据库启动脚本dbstart
vi /etc/rc.d/rc.local
#touch /var/lock/subsys/local下加入如下内容(修改成自己的oracle路径)
su oracle -lc "/home/oracle/app/oracle/product/11.2.0/dbhome_1/bin/lsnrctl start"
su oracle -lc /home/oracle/app/oracle/product/11.2.0/dbhome_1/bin/dbstart
(5)赋予权限
chmod 777 /etc/rc.d/rc.local
cd /etc/rc.d/
#看看rc.local变为绿色
ll
(6)重启
#重启
reboot
#连接
sqlplus / as sysdba
#查看状态
select status from v$instance;
#退出
quit
#查看监听状态
lsnrctl status
三、批处理启动服务
(1)创建.sh文件
#!/bin/bash
#chkconfig:2345 10 90
#description:resind
cd /home/sgxy/mpms
nohup ./01-startAdministratorLogic.sh > nohup01.out &
nohup ./02-startUapServerLogic.sh > nohup02.out &
port_status=`netstat -nlt|grep 9003|wc -l`
sleep 10
if [ $port_status -lt 1 ]; then
echo "succeed"
nohup ./03-startMpms.sh > nohup03.out &
nohup ./04-startDamr.sh > nohup04.out &
cd /home/sgxy/mpms/other_jar/dtu
nohup java -jar DtuDataServer.jar > catalina.out 2>&1 &
else
echo "filed"
fi
以下内容中必须填写
chkconfig:2345 10 90
description:resind
(2)配置开机自启动
然后把该文件放到/etc/rc.d/init.d目录下,redis开机自启动第七步再来一遍
(3)重启查看
reboot
ps -ef | grep 'java'
注意
通过shell脚本运行jar包报错运行如下命令,建立软连接
echo $JAVA_HOME
#复制路径:/home/local/java/jdk1.8.0_301
cd /usr/bin
ln -s -f /home/local/java/jdk1.8.0_301/bin/java
标签:bin,rc,redis,echo,etc,自启,Linux,开机,local 来源: https://www.cnblogs.com/hhs-5120/p/16656856.html