El contenido no se encuentra disponible en el idioma seleccionado. Estamos trabajando continuamente para agregar más idiomas. Gracias por su apoyo.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Elastic Cloud Server/ Troubleshooting/ Linux ECS Issues/ How Can I Make /etc/rc.local Run at Startup in CentOS 7?

How Can I Make /etc/rc.local Run at Startup in CentOS 7?

Updated on 2024-08-15 GMT+08:00

Symptom

The /etc/rc.local startup script does not run at startup of ECSs running CentOS 7 or EulerOS.

This section uses CentOS 7 as an example.

Possible Cause

The possible causes are as follows:

  • The /etc/rc.d/rc.local file is not executable in CentOS 7. For detailed measures, see Solution 1.
    NOTE:

    /etc/rc.local is a symbolic link to /etc/rc.d/rc.local.

  • The route command in /etc/rc.local becomes invalid after CentOS 7 restart. This is because the network service is not started when the kernel reads /etc/rc.local to add a route during CentOS 7 startup. For detailed measures, see Solution 2.

Solution 1

The solution for non-executable /etc/rc.d/rc.local is as follows:

NOTE:

In CentOS 7, the /etc/rc.d/rc.local file is not executable by default.

  1. Run the following command to check whether file /etc/rc.d/rc.local is executable:

    ls -l /etc/rc.d/rc.local

    -rw-r--r-- 1 root root 473 Sep 14 02:19 /etc/rc.d/rc.local

    As shown in the command output, the file is not executable.

  2. Run the following command to make /etc/rc.d/rc.local executable:

    chmod +x /etc/rc.d/rc.local

Solution 2

The solutions for invalid route command in the /etc/rc.local after CentOS 7 reboot are as follows:

Method 1: Write the route into a static route configuration file. The route will not be lost even if the NIC is restarted.

  1. Go to the /etc/sysconfig/network-scripts/ directory and check if there is the file route-<interface>, where <interface> is the name of the interface related to the route.

    If there is, add the following content to the file.

    If not, create one and add the following content to the file:
    <network/prefix> via <gateway>

    where <network/prefix> is a remote network with prefix, and <gateway> is the next-hop IP address.

    For example, add a route to point to 10.20.30.0/24 from 192.168.100.10 to enable eth0 at system startup.

    cat /etc/sysconfig/network-scripts/route-eth0

    10.20.30.0/24 via 192.168.100.10  
  2. Run the following command for the modifications to take effect:

    ifup eth0

Method 2: The /etc/rc.d/rc.local file is controlled by the rc-local service. You can configure the rc-local service to start after network-online.target is started.

  1. Run the following command to view rc-local configuration file located in /usr/lib/systemd/system/rc-local.service:

    cat /usr/lib/systemd/system/rc-local.service |grep -v "^#"

    Check if there are parameters Requires and After in the [Unit] area.

    If there are, change their values to network-online.target.

    If not, add these two parameters and set their values to network-online.target.

    [Unit]
    Description=/etc/rc.d/rc.local Compatibility
    ConditionFileIsExecutable=/etc/rc.d/rc.local
    Requires=network-online.target
    After=network-online.target
    
    [Service]
    Type=forking
    ExecStart=/etc/rc.d/rc.local start
    TimeoutSec=0
    RemainAfterExit=yes
    NOTE:

    network-online.target is a target that actively waits until the network is up, where the definition of up is defined by the network management software. Usually it indicates a configured, routable IP address of some kind. Its primary purpose is to actively delay activation of services until the network is set up.

  2. Run the following command to check whether file /etc/rc.d/rc.local is executable:

    ls -l /etc/rc.d/rc.local

    If the output indicates that the file is not executable, make it executable by following the instructions provided in Solution 1.

  3. Run the following command to notify systemd to reload the configuration file:

    systemctl daemon-reload

  4. Run the following command to restart rc-local.service to execute the /etc/rc.d/rc.local file:

    systemctl restart rc-local.service

Utilizamos cookies para mejorar nuestro sitio y tu experiencia. Al continuar navegando en nuestro sitio, tú aceptas nuestra política de cookies. Descubre más

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback