Configurez rc.local pour qu'il démarre automatiquement au démarrage

1. Description

Certains systèmes Linux n'ont pas /etc/rc.localde fichiers. Ce fichier est principalement utilisé pour définir certains paramètres initiaux personnalisés après le démarrage du système. En cas d'absence, vous pouvez l'ajouter et le configurer vous-même si nécessaire.

2.Configuration

1. Créez le fichier rc.local

/etc/Créez un fichier dans le répertoire rc.localavec le contenu suivant :

#!/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.

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

exit 0

Ajoutez ensuite /etc/rc.localles autorisations exécutables :

chmod 755 /etc/rc.local

(1) Configurez toutes les cartes réseau pour qu'elles démarrent automatiquement

Vous pouvez ajouter une logique de démarrage dans rc.local, [Script] [Linux] Démarrez toutes les cartes réseau

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

(2) Configurer le DHCP de la carte réseau

Référence : méthode de configuration DHCP dans Configuration réseau sous Linux .

2. Créez le fichier de service rc-local.service

/etc/systemd/system/Créez un fichier de service dans le répertoire avec le rc-local.servicecontenu suivant :

#  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. Configurez le service pour qu'il démarre automatiquement au démarrage

  • systemctl enable rc-local
  • systemctl daemon-reload

4. Démarrez le service

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

Je suppose que tu aimes

Origine blog.csdn.net/hezhanran/article/details/131242863
conseillé
Classement