Debian-9-Ubuntu-17-添加rc.local开机自启的方法

技术文档网 2021-05-17

Debian 9/Ubuntu 17+添加rc.local开机自启的方法

说明:很多时候有些程序或者脚本都需要添加开机自启,最简单的方法就是使用rc.local自启,不过由于系统版本更替,很多新版本系统都没有rc.local文件了,比如Debian 9、Ubuntu 17.10、Ubuntu 18.04。这时候就需要我们手动设置下。

方法

1、添加rc-local.service

#以下为一整条命令,一起复制运行
cat > /etc/systemd/system/rc-local.service <<EOF
[Unit]
Description=/etc/rc.local
ConditionPathExists=/etc/rc.local

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

[Install]
WantedBy=multi-user.target
EOF

2、新建rc-local文件

#以下为一整条命令,一起复制运行
cat > /etc/rc.local <<EOF
#!/bin/sh
#
# 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.

exit 0
EOF

3、添加权限并设置开机自启

chmod +x /etc/rc.local
systemctl enable rc-local
systemctl start rc-local.service

检查状态:

systemctl status rc-local.service

返回Active:active信息,则成功。

最后我们就可以在/etc/rc.loacl里,添加开机的自启命令什么的了。记住添加在exit 0之前。

相关文章

  1. Linux iptables学习笔记

    最近工作需要跟firewall打交道,在这里写下自己的使用心得。 firewall主要的特性有: 1.支持区域设置 2.运行时跟持久化的配置是分离的 3.能够动态管理 iptables 不管是从

  2. Linux vim命令使用教程

    vim使用 参考链接 vim4种模式: 普通模式 插入模式 可视模式 命令行模式 进入vim,按下i或a进入插入模式 按ESC进入普通模式 在该模式下可以使用方向键 h向左 j向下 k向上

  3. 校准linux系统时间

    服务器的时间对于记录请求和数据库操作时间具有重要意义,对于一些如数据库备份的操作,时间尤为重要,需要避开白天业务繁忙时间进行。 修改时区 # cp /etc/localtime /etc/localt

  4. yum与rpm使用说明

    rpm 命令 rpm 命令是 RPM 软件包的管理工具。 语法 rpm (选项)(参数) 选项 -h:安装时列出标记;-i:安装时显示套件的相关信息;-v:安装时显示指令执行过程;-e:卸载已安

  5. service与chkconfig的替代者systemctl

    在安装 redis 时,看到将 redis 配置成 service 系统服务后,采用 service redisd start 命令启动;在安装 mariadb 时,看到利用 systemctl st

随机推荐

  1. Linux iptables学习笔记

    最近工作需要跟firewall打交道,在这里写下自己的使用心得。 firewall主要的特性有: 1.支持区域设置 2.运行时跟持久化的配置是分离的 3.能够动态管理 iptables 不管是从

  2. Linux vim命令使用教程

    vim使用 参考链接 vim4种模式: 普通模式 插入模式 可视模式 命令行模式 进入vim,按下i或a进入插入模式 按ESC进入普通模式 在该模式下可以使用方向键 h向左 j向下 k向上

  3. 校准linux系统时间

    服务器的时间对于记录请求和数据库操作时间具有重要意义,对于一些如数据库备份的操作,时间尤为重要,需要避开白天业务繁忙时间进行。 修改时区 # cp /etc/localtime /etc/localt

  4. yum与rpm使用说明

    rpm 命令 rpm 命令是 RPM 软件包的管理工具。 语法 rpm (选项)(参数) 选项 -h:安装时列出标记;-i:安装时显示套件的相关信息;-v:安装时显示指令执行过程;-e:卸载已安

  5. service与chkconfig的替代者systemctl

    在安装 redis 时,看到将 redis 配置成 service 系统服务后,采用 service redisd start 命令启动;在安装 mariadb 时,看到利用 systemctl st