centos7设置自动开机
时间: 2023-11-20 22:56:25 浏览: 280
在CentOS7中,有多种方法可以设置开机自启动,其中包括使用systemd服务和使用init.d脚本。下面是两种方法的具体步骤:
1.使用init.d脚本
1.1 进入init.d目录并创建执行文件
```shell
cd /etc/init.d/
touch auto_start.sh
```
1.2 编辑auto_start.sh文件并添加需要在开机时自启动的命令
```shell
#!/bin/bash
# chkconfig: 2345 80 90
# description: auto start service
# processname: auto_start.sh
# Author: Your Name
# Date: 2021-01-01
# Add your startup script here
/usr/bin/python /opt/myscript.py start
```
1.3 将auto_start.sh文件添加到系统服务中并设置开机自启动
```shell
chmod +x auto_start.sh
chkconfig --add auto_start.sh
chkconfig auto_start.sh on
```
2.使用systemd服务
2.1 在/etc/systemd/system下创建auto_start.service文件
```shell
cd /etc/systemd/system/
touch auto_start.service
```
2.2 编辑auto_start.service文件并添加需要在开机时自启动的命令
```shell
[Unit]
Description=auto start service
[Service]
Type=forking
ExecStart=/usr/bin/python /opt/myscript.py start
[Install]
WantedBy=multi-user.target
```
2.3 重新加载systemd并设置开机自启动
```shell
systemctl daemon-reload
systemctl enable auto_start.service
systemctl start auto_start.service
```
阅读全文
相关推荐
















