How to Set auto-start and environment variables in centos

Source: Internet
Author: User
Tags etcd

1. Set auto-start

In centos, there are two main ways to set the startup of a self-installed program.
1. Add the Startup Program command to the/etc/rc. d/rc. Local file. For example, set httpd to be started upon startup.

#!/bin/sh## This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don‘t# want to do the full Sys V style init stuff. touch /var/lock/subsys/local/usr/local/apache/bin/apachectl start

2. Add the prepared STARTUP script to the/etc/rc. d/init. d/directory, and run the command chkconfig to set the startup.

Chkconfig Function Description: Check and set various services of the system.

Syntax: chkconfig [-- add] [-- del] [-- list] [System Service] Or chkconfig [-- level <level code>] [System Service] [ON/OFF/Reset]

-- Add Add add service

-- Del Delete Service

-- List to view the startup status of each Service

For example, we set the auto-start MYSQL:

1 # Put the MySQL STARTUP script into all the script running directories/etc/rc. d/init. d In 2 CP/lamp/mysql-5.0.41/support-files/MySQL. server/etc/rc. d/init. d/mysqld 3 4 # Change permission 5 chown root. root/etc/rc. d/init. d/mysqld 6 7 # All users can execute the command. Only root users can modify 8 chmod 755/etc/rc. d/init. d/mysqld 9 10 # Put mysqld into the Linux Startup Management System 11 chkconfig -- add mysqld12 13 # view all services in various running levels 14 chkconfig -- list mysqld15 16 # As long as the running level 3 start, all others disable 17 chkconfig -- levels 245 mysqld off

For example, we write the httpd script and put it in the/etc/rc. d/init. d/directory.

chkconfig --add httpdchkconfig httpd on

The command is set to boot.

 

3. Add the Startup Program command to the/etc/rc. d/rc. sysinit file.

 

Script/etc/rc. d/RC. sysinit is used to start system service programs, such as setting system environment variables, setting system clock, loading fonts, checking and loading file systems, and generating system startup information log files.

 

For example, we set self-starting Apache:

echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit

 

 

 

Set Environment Variables

The Linux environment variables are all configured in the/etc/profile file. Edit the profile

VI/etc/profile
1
Add the program directory at the end of the file that you want to set as an environment variable, such:
You can add multiple

Export Path = "$ path:/home/Consul"
Export Path = "$ path:/home/etcd/etcd-v3.0.6-linux-amd64"
1
2
Press ESC to exit and enter WQ in sequence! Save files
Run the following command to make the configuration take effect:

Source/etc/profile
1
OK.

How to Set auto-start and environment variables in centos

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.