Centos7各种服务的开机自启动(持续更新)

centos7各种服务的开机自启动,偶尔会断电涉及到要开的服务就很多,所以这里统一写了一些,后续会不断更新。

1.nginx自启动

进入centos的启动目录,编写启动脚本

vim /usr/lib/systemd/system/nginx.service
#nginx 启动脚本
[Unit]
Description=nginx
After=network.target
  
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target
#设置开机自启动
systemctl enable nginx

#查看服务状态
systemctl status nginx

2.jenkins自启动

直接输入命令即可

systemctl enable jenkins.service

3.tomcat自启动

进入tomcat的bin目录编辑catalina.sh文件,在这个位置加入这个语句(搜索就是esc后,按/后面输入搜索的内容)

vim catalina.sh
CATALINA_PID="$CATALINA_BASE/tomcat.pid"

Centos7各种服务的开机自启动(持续更新)_第1张图片

编辑自启动脚本

vim /usr/lib/systemd/system/tomcat.service

注意environment的位置是电脑java环境的位置,tomcat的位置也要替换

#tomcat自启动脚本
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking

Environment="JAVA_HOME=/usr/java/jdk1.8.0_11"

PIDFile=/opt/tomcat/apache-tomcat-8.5.69/tomcat.pid
ExecStart=/opt/tomcat/apache-tomcat-8.5.69/bin/startup.sh
ExecStop=/bin/kill -s QUIT $MAINPID
ExecReload=/bin/kill -s HUP $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
#设置生效
systemctl daemon-reload
#开机自启
systemctl enable tomcat.service
#查看状态
systemctl status tomcat.service
#启动服务
systemctl start tomcat.service

4.oracle自启动

找到这个路径/xxx/product/11.2.0/db_1/bin/,编写启动脚本(附在后面),然后修改为可执行,再创建软连接

#编写开机启动脚本(xxx表示自己的路径)
vim oracledb

#修改脚本为可执行
chmod a+x oracledb

#创建软链接(一定要用绝对路径)
ln -s xxx/oracledb /etc/rc.d/init.d/oracledb

#授权
chmod 755 /etc/rc.d/init.d/

#添加服务
chkconfig --add oracledb

#修改oracle启动配置(N改Y)
vim /etc/oratab
orcl:xxx/product/11.2.0/dbhome_1:Y

#开关
service oracledb stop
service oracledb start
#!/bin/sh
# chkconfig: 35 80 10
# description: Oracle auto start-stop script.

#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
ORA_HOME=/data/oracle/product/11.2.0/db_1
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
  echo "Oracle startup: cannot start"
  exit
fi
case "$1" in
'start')
# Start the Oracle databases:
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracle
echo "Done"

# Start the Listener:
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle
echo "Done."
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;

'stop')
# Stop the Oracle Listener:
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle

# Stop the Oracle Database:
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
;;

'restart')
$0 stop
$0 start
;;
esac

你可能感兴趣的:(服务器运维,jenkins,linux,centos)