谷动谷力

 找回密码
 立即注册
查看: 1433|回复: 0
打印 上一主题 下一主题
收起左侧

linux自启动的几种方式

[复制链接]
跳转到指定楼层
楼主
发表于 2020-12-26 18:47:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 sunsili 于 2022-3-6 00:39 编辑

linux自启动的几种方式

RedHat4 自启动方式

一 通过服务的方式自启动

1.在/etc/init.d 下建立相关程序的启动脚本
  1. ln -s /etc/init.d/服务名 /etc/rc.d/rc3.d/S100服务名 //S:开机自启动 100:启动顺序
复制代码

2.chkconfig --add 服务名
3.chkconfig 服务名 on 开机自启动
chkconfig 服务名 off 关闭自启动
4.service 服务名 start 手动启动服务
5.service 服务名 stop 手动关闭服务

二 自定义开机程序

1.vi /etc/rc.d/rc.local
2.末尾添加启动命令
3 /usr/src/tomcat/bin/startup.sh /*自动启动tomcat*/

三 定时启动脚本

1. /root下写好启动的shell文件
  1. #! /bin/sh

  2. A=`netstat -anp | grep ":8080" | grep "LISTEN" | wc -l`

  3. echo $A

  4. if [ $A -eq 0 ]

  5. then

  6. /etc/init.d/tomcat start

  7. echo "tomcat重启中"

  8. else

  9. echo "tomcat正在运行中"

  10. fi
复制代码


2. crontab -e
3. 设置好定时时间
4. 设置为每分钟检查一次 //*/1 * * * * 脚本目录**********************************************************************

Centos7 自启动方式

一 通过(init.d)服务的方式自启动

1.在/etc/init.d 下建立相关程序的启动脚本

  1. ln -s /etc/init.d/服务名 /etc/rc.d/rc3.d/S100服务名 //S:开机自启动 100:启动顺序
复制代码

2.chkconfig --add 服务名
3.chkconfig 服务名 on 开机自启动
chkconfig 服务名 off 关闭自启动
4.service 服务名 start 手动启动服务
5.service 服务名 stop 手动关闭服务

二 通过systemctl 服务的方式自启动

1.cd /usr/lib/systemd/system/
2.vi 服务名.service
  1. # Systemd unit file for default tomcat

  2. #

  3. # To create clones of this service:

  4. # DO NOTHING, use tomcat@.service instead.


  5. [Unit]

  6. Description=Apache Tomcat Web Application Container

  7. After=syslog.target network.target


  8. [Service]

  9. Type=simple

  10. EnvironmentFile=/etc/tomcat/tomcat.conf

  11. Environment="NAME="

  12. EnvironmentFile=-/etc/sysconfig/tomcat

  13. ExecStart=/usr/libexec/tomcat/server start

  14. SuccessExitStatus=143

  15. User=tomcat


  16. [Install]

  17. WantedBy=multi-user.target
复制代码


3.systemctl enable 服务名.service //设置自启动服务
4.systemctl start 服务名.service //启动服务
5.systemctl stop 服务名.service //停止服务
6.service 服务名 start //启动服务
7.service 服务名 stop //停止服务


1

2

3

4

5

6

7

8

任务              旧指令             新指令

使某服务自动启动      chkconfig httpd on       systemctl enable httpd.service

使服务不自动启动    chkconfig httpd off     systemctl disable httpd.service

检查服务状态    service httpd status      systemctl status httpd.service (服务详细信息) systemctl is-active httpd.service (仅显示是否 Active)

已启动的服务      chkconfig --list        systemctl list-units --type=service

启动某服务     service httpd start        systemctl start httpd.service

停止某服务          service httpd stop        systemctl stop httpd.service

重启某服务     service httpd restart        systemctl restart httpd.service



+10
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|深圳市光明谷科技有限公司|光明谷商城|Sunshine Silicon Corpporation ( 粤ICP备14060730号|Sitemap

GMT+8, 2024-6-1 04:03 , Processed in 0.110230 second(s), 34 queries .

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表