Linux Service Management

Source: Internet
Author: User
Tags rsync

Introduction and classification system operating level
Run Level meaning
0 Shutdown
1 Single-user mode, which can be imagined as a safe mode for Windows, primarily for system repair
2 Incomplete command-line mode with no NFS service
3 Full command-line mode, which is the standard character interface
4 System retention
5 Graphics mode
6 Restart

Note:
Single-user mode: Start the smallest service, redundant service does not open, only to ensure that the system can operate properly. Mainly used for system repair.
File sharing service between Nfs:linux and Linux

View and modify system operating levels
// 查看系统运行级别// N:NULL。当前级别为3即字符界面,其上一个级别为N即为空,表示系统开机直接进入字符界面#runlevel3             // 修改系统运行级别// 进入图形级别,前提是安装图形界面#init 5 // 若未安装图形界面则会报错#runlevel35     // 仍然进入了5级别// 不建议使用下面命令关机和重启,不一定正确结束系统正在运行的服务;建议使用shutdown命令// 关机#init 0// 重启#init 6 
View and modify the system default RunLevel
// /etc/inittab文件现在没有那么重要,它的功能已经被其他配置文件所代替#vim /etc/inittabid:3:initdefault:

Note: Do not set the boot level to 0 or 6 levels.

Classification of services

RPM Package and source package difference: mainly in the installation location is not the same.

RPM packages are installed in the system default location, generally do not specify the installation location, the installation package author determines the location of the installation.
Source package Manually Specify the installation location, generally installed in the/usr/local/directory.

The difference between a standalone service and a xinetd-based service:

Standalone Service: The service runs in memory independently, and the service responds faster, but consumes more memory.
based on the XINETD service: xinetd Service is one of the super daemon processes. The XINETD service itself exists independently and manages some services. The user requests some of the services it manages through the XINETD service, and then xinetd returns the reply of the requesting service to the user, xinetd the same role as the proxy. xinetd Services are phased out and most services are independent services.

//查看服务自启动服务// 通过chkconfig查看的服务都是rpm包安装且都是独立的服务#chkconfig --list...0123456:off //在不同系统运行级别时服务的自动开启状态即是否自启动...// 查看基于xinetd服务// xinetd#yum -y install xinetd// 查看服务#chkconfig --list // 会多一组显示基于inetd服务的服务
Startup and self-booting

Service start-up: is to let the service run in the current system and provide the function.
Service self-booting: self-booting means having five blessings start the service automatically as the system starts or restarts after the system is powered on or restarted.

Note: When chkconfig–list checks to see if the service is on at different operating levels, the service is turned on and is not sure whether the service is turned on now.

Query installed services RPM package installed Services

Chkconfig–list command to view the service self-boot status, you can see all the RPM package installed services

Source Package Installation Services

View the service installation location, usually under the/usr/local/directory
Service, Chkconfig, NTSYSV can not find the source package installed services.

The difference between the RPM package installation service and the source package installation service is that the installation location is different

The source package is generally installed in the/usr/local/directory
RPM Package Default installation location

Service and port viewing system open (already running) service

1 ps aux command, which shows that all processes executed include the service process, but this is not useful
2 netstat -tlun Displays the service that the system is running (listening on), and other features can be man netstat viewed

Port corresponds to service

viewing /etc/services files, displaying common ports and services

RPM Package Service Management

General RPM Package File installation location:
-/etc/init.d/: Start Script location
-/etc/sysconfig/: Initialize the environment configuration file location
-/etc/: Configuration file location
-/ETC/XINETD.CONF:XINETD configuration file
-/etc/xinetd.d/: Startup script based on XINETD service
-/var/lib/: The data generated by the service is put here
-/var/log/: Log

Standalone Service-managed standalone service start-up

1/etc/init.d/Standalone Service name start|stop|status|restart|

// 查看apache http服务的状态,其中httpd为一个shell脚本文件#/etc/init.d/httpd status// 启动apache服务#/etc/init.d/httpd start// 早期Linux版本服务管理脚本放在/etc/rc.d/init.d/目录#/etc/rc.d/init.d/httpd status

2 Service Standalone name start|stop|restart|status|

#service httpd status

Note 1:redhat series of Linux to use service commands
Note 2: The above two methods generally do not manage the source package startup script, but you can put the source package startup script in the/etc/init.d/directory unified Management

Self-priming for standalone services

1 chkconfig [–level Run level] [standalone service name] [On|off]

#chkconfig--list |grep httpdhttpd0: Off 1: Off 2: Off 3: Off 4: Off 5: Off 6: Off #chkconfig--level 2345 httpd on#chkconfig--list |grep httpdhttpd0: Off 1: Off 2: on 3: on 4: on 5: on 6: Off #chkconfig httpd off#chkconfig--list|grep httpdhttpd0: Off 1: Off 2: Off 3: Off 4: Off 5: Off 6: Off 

2 Modify/etc/rc.d/rc.local File
The/etc/rc.d/rc.local file is when the system starts, all services are started, and the user logs on to the last file executed before the system, so the system executes the commands in this file.

#vim /etc/rc.d/rc.localtouch /var/lock/subsys/local/etc/init.// 添加开机启动apache服务的命令

Note 1: By modifying the/etc/rc.d/rc.local file to add the boot service can not be displayed in the Chkconfig–list, the two management methods do not want to close, choose one.
Note 2: You can also modify the/etc/rc.local file, the/etc/rc.local file is a soft connection to the/etc/rc.d/rc.local file

3 managing self-booting with the NTSYSV command
The NTSYSV command and the Chkconfig command are related, that is, by which modification, the other person can see the changes.
Note: NTSYSV is a Linux command for the Redhat series.

XINETD Service-based Management 1 installation XINETD service
#yum -y install xinetd
2 start of xinetd service
// 显示rsync服务的端口#grep rsync /etc/services#vim /etc/xinetd.d/rsyncservice rsync{    flags = REUSE // 设置TCP/IP socket可重用    socket_type = stream    wait = no     // 允许多个连接同时连接    user = root   // 启动服务的用户为root    server = /usr/bin/rsync    server_args = --daemon    log_on_failure += USERID // 登录失败后,记录用户的ID    // 开启rsync服务,开启:no 关闭:yes}// 重启动xinetd服务#service xinetd restart
3 self-booting of the XINETD service

Only standalone services have RunLevel, XINETD-based services do not have runlevel, xinetd level can be self-booting, and rsync service can start from

//cannot add run level   #chkconfig rsync on   #netstat-tlun|grep 873  TCP Span class= "Hljs-number" >0  0 ::: 873 :::* Listen #chkconfig rsync off  //see if the rsync service is off,   #netstat-tlun|grep 873//No display, Rync service closed   #vim/etc/xinetd.d/rsync//Set up Disable=no  for rsync services  #service xinetd restart   #netstat-tlun|grep 873  tcp 0  0 ::: 873 :::* listen// Use the graphical interface ntsysv to find the rsync service enabled   #ntsysv   

Note: The above operation shows that the start and start-up of the XINETD service is consistent, that is, the startup and shutdown services are the same as the start and turn off.

Source Package Service Management

The installation instructions in the installation directory of the source package typically have a boot command tutorial in the documentation. The installation instructions for the Apache server are install.

Startup of the source package installation Service

Use an absolute path to invoke the startup script to start. Different two dollars. Package startup scripts are different. You can view the installation instructions for the source package and see how to start the script.

// 源码包服务启动#/usr/local/apache2/bin/apachectl start|stop// 源码包中apache2服务首页的修改#vim /usr/local/apache2/htdocs/index.html 
Self-booting of the source package service

You can only add a start command by modifying the/etc/rc.d/rc.local file

#vim /etc/rc.d/rc.local// 加入/usr/local/apache2/bin/apachectl start即可
Let the source package service be recognized by the Service Management command

Allow the Apache service of the source bundle to be started by service command management

#ln -s /usr/local/apache2/bin/apachectl /etc/init.d/apache#service apache start

Allow the Apache service of the source package to be chkconfig and NTSYSV command Management self-initiated

#vim /etc/init.d/apache // 在apache启动脚本中添加  358676// 格式:chkconfig : 运行级别 启动顺序 关闭顺序  #description: source package apache// 把源码包apache加入chkconfig 命令#chkconfig --add apache#chkconfig --list |grep apache01:关闭  23456:关闭// 这时,ntsysv命令也可以管理apache#ntsysv 

Note:

// 格式:chkconfig : 运行级别 启动顺序 关闭顺序#chkconfig: 35 86 76#cd /etc/rc3.d/ // 3代表系统纯字符界面#ls// 显示以k和s开头文件文件// k开头的为kill,s开头的为start,// 系统进入3级别的时要把以s开头的文件执行一遍,同理系统退出3级别时执行一遍k开头的文件// 启动顺序号和关闭顺序号可以为随意数字,但启动顺序号不能与/etc/rc3.d/目录下已存在的s开头文件的顺序号重复,同理关闭顺序号也不能与k开头文件的顺序号重复
Reference

Linux service Management in MU-class network

Linux Service Management

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.