7 control system services
In CentOS system, various system control script placed in the service of the default / usr / lib / systemd directory. Systemctl command tool can be achieved by control of the specified system services.
-
systemctl command
- Common formats
systemctl [control type] [service name]
- Control Type
start (start): run the specified system services to achieve service functions.
stop (stop): terminates the specified system services, deactivate features.
restart (restart): first exit and re-run the specified system services. (Caution)
reload (reload): Do not quit the service program, just refresh the configuration.
status (see status): Displays the operating status of system services and related information.
[root@localhost ~]# systemctl start httpd //启动httpd服务 [root@localhost ~]# systemctl status httpd //查看httpd服务运行状态及相关信息 ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: active (running) since 二 2019-08-27 14:18:52 CST; 32s ago Docs: man:httpd(8) man:apachectl(8) Main PID: 1896 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─1896 /usr/sbin/httpd -DFOREGROUND ├─1899 /usr/sbin/httpd -DFOREGROUND ├─1900 /usr/sbin/httpd -DFOREGROUND ├─1901 /usr/sbin/httpd -DFOREGROUND ├─1903 /usr/sbin/httpd -DFOREGROUND └─1905 /usr/sbin/httpd -DFOREGROUND 8月 27 14:18:52 localhost.localdomain systemd[1]: Starting The Apache HTTP Se... 8月 27 14:18:52 localhost.localdomain httpd[1896]: AH00558: httpd: Could not ... 8月 27 14:18:52 localhost.localdomain systemd[1]: Started The Apache HTTP Ser... Hint: Some lines were ellipsized, use -l to show in full. [root@localhost ~]# systemctl stop httpd //关闭httpd服务 [root@localhost ~]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: inactive (dead) //服务处于关闭状态 Docs: man:httpd(8) man:apachectl(8) 8月 27 14:18:52 localhost.localdomain systemd[1]: Starting The Apache HTTP Se... 8月 27 14:18:52 localhost.localdomain httpd[1896]: AH00558: httpd: Could not ... 8月 27 14:18:52 localhost.localdomain systemd[1]: Started The Apache HTTP Ser... 8月 27 14:20:06 localhost.localdomain systemd[1]: Stopping The Apache HTTP Se... 8月 27 14:20:07 localhost.localdomain systemd[1]: Stopped The Apache HTTP Ser... Hint: Some lines were ellipsized, use -l to show in full.
- Note: For servers running in a real production environment, do not easily stop or restart the implementation of the operation, so as to avoid interrupting client access, unnecessary loss.
Switching the operating level
Run-level operating system is currently running a functional level. It allows some programs start at one level, and the other level is not the time to start.
Effective Log Mode Linux system has a total of ten kinds of 0 to 9, but at most six kinds of limitations in use UNIX systems, generally only 1-6 effective. From 1 to 6, having different functions.
Run Level | Systemd的target | Explanation |
---|---|---|
0 | target | Off, when using this level will host closed |
1 | rescue.target | Single-user mode, no password is required to log verification system, used for system maintenance |
2 | multi-user.target | User-defined / domain-specific run level. The default is equivalent to 3 |
3 | multi-user.target | Full multi-user mode interface characters, most of the server host is running at this level |
4 | multi-user.target | User-defined / domain-specific run level. The default is equivalent to 3 |
5 | graphical.target | Multi-user mode graphical interface provides a graphical desktop environment |
6 | reboot.target | Reboot, reboot the host will use this level |
1, view the current system run level
- runlevel command
[root@localhost ~]# runlevel N 5
2, run-level switching system
When a user needs to switch to another operating system level, the init may be performed by conventional procedures, using the long run level corresponding to the number (0-6) as a command parameter can be, or use systemctl target switching command.
- init program switching
[root@localhost ~]# init 3
- systemctl tool switch
- systemctl isolate graphical.target switch to a graphical interface (inin 5)
- systemctl isolate multi-user.target switched to the character interface (inin 3)
-
Set boot automatically into the character interface.
ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
(Set boot character interface)
systemctl get-default: view the current boot level
[root @ localhost ~] # systemctl get-default // view the current start level state graphical.target // graphical interface [root @ localhost ~] # ln -sf /lib/systemd/system/multi-user.target / etc /systemd/system/default.target // set open start to character interface [root @ localhost ~] # systemctl get-default // view the current start level state multi-user.target // character interface
Optimization of the startup process
Linux operating system contains a large number of service programs, these services start or terminate the program according to a preset state when switching the operating level. Many of which system services may not be required by the user, but also run the default.
So, by default in the Linux operating system, which system includes a service? What is their role? How to control system services run automatically after boot, in order to reduce resource consumption and improve the efficiency of the system do?
1. Common system services
In CentOS system, the default installation of system services up to more than 100 species, these systems serve to provide users with a wealth of application services. Only understand the purpose of each system service, in order to selectively optimize operations, enable Linux-demand service.
CentOS some of the common system services:
service name | Introduction to use | Remark |
---|---|---|
etc | Postponed scheduled task | The proposed closure |
bluetooth | Found that certified Bluetooth related equipment | The proposed closure |
crond | Implementation plan tasks in a predetermined cycle | It recommended that you turn |
irqbalance | Scheduling support multi-core CPU processors | It recommended that you turn |
kdump | Memory information for the recording kernel panic | The proposed closure |
lvm2-monitor | LVM management and monitoring | It recommended that you turn |
netfs | Access to shared folders such as Network File System | It recommended that you turn |
network | Configure and use the card, network address | It recommended that you turn |
restorecond SELinux | File monitoring and restore security mechanism | The proposed closure |
rhnsd | Access Network, get notifications, submitted subscriptions | The proposed closure |
rpcgssd | NFS client access in the context of management | The proposed closure |
saslauthd | Text-based identity authentication | The proposed closure |
smartd | Monitor the status of the local hard disk and to send crash reports | It recommended that you turn |
smb | File sharing service | The proposed closure |
sshd | It provides remote login and manage Linux hosts | It recommended that you turn |
rsyslog | Kernel log messages, system | It recommended that you turn |
vsftpd | Provided by FTP file upload, download | The proposed closure |
- Note: it must be stressed that these services in the end is to select on or off, should be based on the actual functional requirements of the host, not mechanically.
2. Optimize boot automatically load service
Linux operating system after each boot will enter the default systemd running target (such as character-mode or graphics mode), and the default is set to start running a variety of system services that target. To disable some system services run automatically, use ntsysv or systemctl tool for optimization.
-
ntsysv tool
ntsysv tool can be run in a character mode, to provide users with an interactive graphical user interface a copy, specifically for centralized configuration starting state of various systems and services. When the need to set multiple startup status of the service, use ntsysv tool will be very convenient.
[Root @ localhost ~] # ntsysv // input command to enter an interactive graphical user interface imitation
Operation by ↑, ↓ arrow keys to select a different system services, by default startup state Space (space) key and services provided ([*] represents a promoter, [] represents a closed). If you want to see a description of the selected information service, press the F1 key to get help.
-
systemctl Tools
Systemctl ntsysv similar tools and functions, but systemctl not provide an interactive user interface, which is used to query or set the system service default startup state. When you need to set a default to start a service in the current running state of the target when using systemctl tools more efficient.
-
Command Format
- systemctl control options Service Name
- Common options
- enable: at startup.
- disable: turn off automatically.
- is-enable: Check boot status.
-
[root @ localhost ~] # systemctl enable httpd.service // set the automatic start-up service httpd Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to / usr / lib / systemd / system /httpd.service. [root @ localhost ~] # systemctl IS-Enabled httpd.service // View httpd start-up status Enabled [root @ localhost ~] # systemctl disable httpd.service // set the boot does not start httpd service Removed symlink / etc / systemd / System / Multi-user.target.wants / httpd.service. [the root @ localhost ~] # systemctl IS-Enabled View httpd.service //// httpd boot state disabled
to add on
Execution systemctl list-units in the current system --type = service command to see all currently active system service system.
[root@localhost ~]# systemctl list-units --type=service //查看当前系统中所有已激活的系统服务 UNIT LOAD ACTIVE SUB DESCRIPTION abrt-ccpp.service loaded active exited Install ABRT coredump hook abrt-oops.service loaded active running ABRT kernel log watcher abrt-xorg.service loaded active running ABRT Xorg log watcher abrtd.service loaded active running ABRT Automated Bug Reporting Tool accounts-daemon.service loaded active running Accounts Service alsa-state.service loaded active running Manage Sound Card State (restore and store) atd.service loaded active running Job spooling tools auditd.service loaded active running Security Auditing Service avahi-daemon.service loaded active running Avahi mDNS/DNS-SD Stack blk-availability.service loaded active exited Availability of block devices ...//省略部分内容...
Thank you for watching, I hope you can help us!