您好,欢迎来到锐游网。
搜索
您的当前位置:首页设置开机自启rc.local

设置开机自启rc.local

来源:锐游网

一、说明

有的一些Linux没有/etc/rc.local文件,该文件主要是用于设置系统开机后的一些自定义初始设置。当缺失时若需要可以自行添加和配置。

二、配置

1、创建rc.local文件

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# 在此自行添加想开机启动就执行的脚本或逻辑

然后给/etc/rc.local添加可执行权限:

chmod 755 /etc/rc.local

(1)设置所有网卡自动启动

可以在rc.local添加开机启动逻辑,

# 启动所有网卡
/lib/ifupdown/ifup_ethernets.sh

(2)设置网卡DHCP

参考: 中的DHCP配置方法。

2、创建rc-local.service服务文件

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

3、设置服务开机自启

  • systemctl enable rc-local
  • systemctl daemon-reload

4、启动服务

  • systemctl start rc-local
  • systemctl status rc-local

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- ryyc.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务