Linux (eight) service

1. The concept of service

Operation The program that runs continuously in the background in the system does not have an operation interface itself, and needs to be accessed and operated through the port number. There is a big difference between the service management of CentOS 6 and CentOS 7, let’s look at them separately.

2, CentOS6 service

2.1 service Command

service service namestart< /span>

service Service namestop

service service namerestart

service service name reload

service Service namestatus

2.2 Service corresponding program files

/etc/init.d directory is all

2.3 chkconfig command< /strong>

View the list of services: chkconfig [–list]

Set the automatic startup status of specific services: chkconfig service name on/off

Thinking: You< strong>Can you distinguish these two states clearly?

Is the service running now

Service Whether to run automatically after booting

2.4 Run level of Linux

vim /etc/inittab to view the system configuration. The CentOS6 system uses the 7 numbers 0~6 to control the boot mode of the Linux system.

Run level 0: The system is stopped, the default run level of the system cannot be set to 0, otherwise it will not start normally

< p style="margin-left: 0pt;">Run level 1: Single user working status, root authority, used for system maintenance, remote login is prohibited

Run Level 2: Multi-user state (no NFS), no network service

Run level 3: Complete multi-user state (with NFS), enter the console after logging in Command line mode

Run level 4: The system is not used, keep it

Run level 5: X11 means the console, enter the graphical interface

Run level 6: The system shuts down and restarts normally, the default run level cannot be set to 6, otherwise it will not start normally

3 or 5 are commonly used.

The chkconfig command uses the –level parameter and a value to control a service in a certain Whether to start automatically for each run level.

2.5 firewall

Service name: iptables

Stop the firewall: service iptables stop

3, CentOS7 service

3.1 systemctl command

systemctl start service name (xxxx.service)

systemctl restart service Name(xxxx.service)

systemctl stop service name(xxxx.service)

systemctl reload service name (xxxx.service)

systemctl status service name (xxxx.service)

3.2 Service corresponding program files

/usr/lib/systemd/system directory The following are all

3.3 systemctl command instead of chkconfig command

View service status: systemctl list-unit-files

< p style="margin-left: 0pt;">Set or cancel the automatic startup of the service on startup:

  • Set the automatic startup on startup: systemctl enable Service name
  • Cancel auto-start at boot: systemctl disable service name

< strong>3.4 CentOS7 simplifies the run level

vim /etc/inittab

# inittab is no longer used when using systemd.

#

# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.

#

# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target

#

# systemd uses’targets’ instead of runlevels. By default, there are two main targets:

#

# multi-user.target: analogous to runlevel 3

# graphical.target: analogous to runlevel 5

#

# To view current default target, run:

# systemctl get-default

#

# To set a default target, run:

# systemctl set-default TARGET.target

systemctl set-default graphical.target

3.5 Turn off the firewall

systemctl disable firewalld.service

Systemctl stop firewalld.service Turn off the firewall

Leave a Comment

Your email address will not be published.