Linux服务管理---系统运行级别、rpm启动与自启动、源码包的启动

简介: 版权声明:本文为博主原创文章,转载请注明出处。 https://blog.
版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/twilight_karl/article/details/76714066

系统运行级别

  • runlevel 查看运行级别
  • init num 设置运行级别
运行级别 含义
0 关机
1 单用户模式,可以想象为安全模式,主要用户系统修复
2 不完全的命令行模式
3 完全的命令行模式,标准字符界面
4 系统保留
5 图形模式
6 重启动


[root@localhost ~]# init 3
[root@localhost ~]# runlevel
5 3

修改默认运行级别传统方式是更改/etc/inittab文件。但是在Centos7中,该文件的内容:

# 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

表示该文件已经不起作用,可以使用命令方式修改:

  • multi-user.target: runlevel 3
  • graphical.target: runlevel 5

使用 systemctl get-default 获取默认级别。使用 systemctl set-default TARGET.target 设置默认级别

获得默认运行级别

[root@localhost etc]# systemctl get-default
graphical.target

设置默认运行级别为字符界面:

[root@localhost etc]# systemctl set-default multi-user.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.

查看自启动状态

chkconfig –list
查看服务自启动状态,可以看到所有RPM包安装的服务

[root@localhost rc.d]# chkconfig --list
NetworkManager  0:关闭    1:关闭    2:启用    3:启用    4:启用    5:启用    6:关闭
abrt-ccpp       0:关闭    1:关闭    2:关闭    3:启用    4:关闭    5:启用    6:关闭
abrtd           0:关闭    1:关闭    2:关闭    3:启用    4:关闭    5:启用    6:关闭
acpid           0:关闭    1:关闭    2:启用    3:启用    4:启用    5:启用    6:关闭
atd             0:关闭    1:关闭    2:关闭    3:启用    4:启用    5:启用    6:关闭
auditd          0:关闭    1:关闭    2:启用    3:启用    4:启用    5:启用    6:关闭
autofs          0:关闭    1:关闭    2:关闭    3:启用    4:启用    5:启用    6:关闭

查看已启动的软件

  • netstat -an 查看所有端口,查看已连接端口
  • netstat -tulnp 查看已开启的监听状态的端口

rpm如何启动软件

  • 通过绝对路径启动(标准启动方式)

    /etc/init.d/httpd start
    /etc/rc.d/init.d/httpd start

  • service 命令启动(rethat系统专有命令)
    service httpd start|stop|restart|status

设置自启动状态

  • chkconfig [–level] [独立服务名] [on|off]
[root@localhost rc.d]# chkconfig --level 2345  httpd on
[root@localhost rc.d]# chkconfig --list | grep httpd
httpd           0:关闭    1:关闭    2:启用    3:启用    4:启用    5:启用    6:关闭
  • 修改/etc/rc.d/rc.local 文件,系统启动时会最后执行文件中的内容,可以加上启动特定服务的命令。最后执行的文件。
#!/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

# 自启动命令
/etc/init.d/httpd start
  • ntsysv [级别号] 图形化工具,作用和chkconfig相同。

chkconfig 和 ntsysv 做出的更改会同步,但是在rc.local文件中做出的修改,在chkconfig中无法查看到

源码包的自启动

更改 /etc/rc.d/rc.local 文件,将启动命令追加到文件末尾即可。 chkconfig 命令不能识别源码包服务。

让源码包被service识别

将源码包的启动脚本复制到init.d目录下,改脚本需要能接受相关参数,比如start|stop等

让源码包的服务能被chkconfig 与ntsysv命令管理

  • 在init.d 目录下的脚本中起始处添加 # chkconfig: 35 86 76

    chkconfig: 运行级别 启动顺序 关闭顺序 (/etc/rc3.d/)

  • 在脚本中添加 # description: ..

    说明, 内容随意

  • chkconfig --add 脚本名称 将init.d下的启动脚本加入chkconfig到命令中

相关资料

Tony老师的Linux服务列表

相关文章
|
2天前
|
Ubuntu Linux 编译器
【Linux】详解动静态库的制作和使用&&动静态库在系统中的配置步骤
【Linux】详解动静态库的制作和使用&&动静态库在系统中的配置步骤
|
2天前
|
Linux Windows
虚拟机添加新硬盘之linux系统篇
虚拟机添加新硬盘之linux系统篇
|
4天前
|
负载均衡 Linux 应用服务中间件
Linux系统中前后端分离项目部署指南
Linux系统中前后端分离项目部署指南
|
22小时前
|
IDE Linux 开发工具
Linux 系统上安装
在Linux和Mac上安装Lua 5.3.0只需下载源码,解压,编译和安装。Windows用户可选择SciTE IDE或通过LuaForWindows在Github或Google Code下载安装。创建 HelloWorld.lua,使用`lua HelloWorld.lua`运行显示"Hello World!"。另可参考LuaDist官方推荐方式安装。
|
1天前
|
编解码 Ubuntu Linux
|
2天前
|
Linux
|
2天前
|
Linux
请问如何在Linux系统中删除一个磁盘分区
请问如何在Linux系统中删除一个磁盘分区
|
2天前
|
Linux
Linux系统的磁盘管理
Linux系统的磁盘管理
|
2天前
|
Unix Linux Shell
Linux系统使用超详细(一)
Linux系统是一种开源的、类Unix操作系统内核的实现,它基于Unix的设计原理和思想,并在全球范围内广泛应用。以下是对Linux系统的详细描述:
|
3天前
|
Linux 编译器 调度
xenomai内核解析--双核系统调用(二)--应用如何区分xenomai/linux系统调用或服务
本文介绍了如何将POSIX应用程序编译为在Xenomai实时内核上运行的程序。
19 1
xenomai内核解析--双核系统调用(二)--应用如何区分xenomai/linux系统调用或服务