如何控制服务的运行状态?如何切换不同的运行级别?


服务控制

ntsysv

  • 仿图形交互界面,集中配置各种服务启动状态

--level 35:同时对指定运行级别中的服务进行管理,不加仅管理当前运行级别中的服务。

[root@localhost ~]# ntsysv --level 35

systemctl

  • systemctl {选项} name.servive

start:启动

stop:停止

[root@localhost ~]# systemctl start httpd.service
[root@localhost ~]# systemctl stop httpd.service

restart:重启,先停止,再启动

reload:重新加载配置文件,不会完全停止和启动服务

[root@localhost ~]# systemctl restart httpd.service
[root@localhost ~]# systemctl reload httpd.service

status:状态

is-active:是否启动成功

is-failed:是否启动失败

[root@localhost ~]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2019-08-27 17:31:39 CST; 40s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 8833 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
Main PID: 8821 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
├─8821 /usr/sbin/httpd -DFOREGROUND
├─8835 /usr/sbin/httpd -DFOREGROUND
├─8836 /usr/sbin/httpd -DFOREGROUND
├─8837 /usr/sbin/httpd -DFOREGROUND
├─8838 /usr/sbin/httpd -DFOREGROUND
└─8839 /usr/sbin/httpd -DFOREGROUND Aug 27 17:31:39 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Aug 27 17:31:39 localhost.localdomain httpd[8821]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.l...s message
Aug 27 17:31:39 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Aug 27 17:31:45 localhost.localdomain httpd[8833]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.l...s message
Aug 27 17:31:45 localhost.localdomain systemd[1]: Reloaded The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]# systemctl is-active httpd.service
active
[root@localhost ~]# systemctl is-failed httpd.service
active

enable:开机自启

disable:关闭开机自启

is-enabled:是否开机自启

[root@localhost ~]# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl disable httpd.service
Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.
[root@localhost ~]# systemctl is-enabled httpd.service
disabled

list-dependencies:查看依赖关系

[root@localhost ~]# systemctl list-dependencies httpd.service
httpd.service
● ├─-.mount
● ├─system.slice
● └─basic.target
● ├─microcode.service
● ├─rhel-autorelabel-mark.service
● ├─rhel-autorelabel.service
● ├─rhel-configure.service
● ├─rhel-dmesg.service
● ├─rhel-loadmodules.service
● ├─selinux-policy-migrate-local-changes@targeted.service
● ├─paths.target
● ├─slices.target
● │ ├─-.slice
● │ └─system.slice
● ├─sockets.target
● │ ├─dbus.socket
● │ ├─dm-event.socket
● │ ├─systemd-initctl.socket
● │ ├─systemd-journald.socket
● │ ├─systemd-shutdownd.socket
● │ ├─systemd-udevd-control.socket
● │ └─systemd-udevd-kernel.socket
● ├─sysinit.target
● │ ├─dev-hugepages.mount
● │ ├─dev-mqueue.mount
● │ ├─kmod-static-nodes.service
● │ ├─lvm2-lvmetad.socket
● │ ├─lvm2-lvmpolld.socket
● │ ├─lvm2-monitor.service
● │ ├─plymouth-read-write.service
● │ ├─plymouth-start.service
● │ ├─proc-sys-fs-binfmt_misc.automount
● │ ├─sys-fs-fuse-connections.mount
● │ ├─sys-kernel-config.mount
● │ ├─sys-kernel-debug.mount
● │ ├─systemd-ask-password-console.path
● │ ├─systemd-binfmt.service
● │ ├─systemd-firstboot.service
● │ ├─systemd-hwdb-update.service
● │ ├─systemd-journal-catalog-update.service
● │ ├─systemd-journal-flush.service
● │ ├─systemd-journald.service
● │ ├─systemd-machine-id-commit.service
● │ ├─systemd-modules-load.service
● │ ├─systemd-random-seed.service
● │ ├─systemd-sysctl.service
● │ ├─systemd-tmpfiles-setup-dev.service
● │ ├─systemd-tmpfiles-setup.service
● │ ├─systemd-udev-trigger.service
● │ ├─systemd-udevd.service
● │ ├─systemd-update-done.service
● │ ├─systemd-update-utmp.service
● │ ├─systemd-vconsole-setup.service
● │ ├─cryptsetup.target
● │ ├─local-fs.target
● │ │ ├─-.mount
● │ │ ├─boot.mount
● │ │ ├─rhel-import-state.service
● │ │ ├─rhel-readonly.service
● │ │ └─systemd-remount-fs.service
● │ └─swap.target
● │ └─dev-mapper-centos\x2dswap.swap
● └─timers.target
● └─systemd-tmpfiles-clean.timer

mask:屏蔽服务

unmak:取消屏蔽

  • 主要使用于相互冲突的服务,屏蔽后,不会被其他的systemd单元启动,也无法被手动启动。例如iptablesfirewalld就是互相冲突的。
[root@localhost ~]# systemctl mask firewalld.service
Created symlink from /etc/systemd/system/firewalld.service to /dev/null.
[root@localhost ~]# systemctl unmask firewalld.service
Removed symlink /etc/systemd/system/firewalld.service.

运行级别

runlevel

  • 显示系统的运行级别
[root@localhost ~]# runlevel
N 5

切换多用户模式

两种方法:

[root@localhost ~]# init 3
[root@localhost ~]# systemctl isolate multi-user.target

切换图形化界面

两种方法:

[root@localhost ~]# init 5
[root@localhost ~]# systemctl isolate graphical.target

开机默认 target

1.查看默认启动target

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

2.切换默认启动target,两种方法:

[root@localhost ~]# 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.
[root@localhost ~]# ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target

3.查看默认启动target

[root@localhost ~]# systemctl get-default
multi-user.target

Linux 服务控制与运行级别的更多相关文章

  1. Linux启动顺序、运行级别及开机启动

    一.启动顺序 当我们经过BIOS引导,并选择了Linux作为准备引导的操作系统后,接下来的执行顺序如下:1.加载并执行内核 第一个被加载的东西就是内核.然后把内核在内存中解压缩,就可以开始运行了.2. ...

  2. linux查看及改变运行级别

    Linux运行级别从0-6,共7个. 0:关机.不能将系统缺省运行级别设置为0,否则无法启动. 1:单用户模式,只允许root用户对系统进行维护. 2:多用户模式,但不能使用NFS(相当于Window ...

  3. linux的7种运行级别

    Linux有7个运行级别(runlevel)运行级别0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启动运行级别1:单用户工作状态,root权限,用于系统维护,禁止远程登陆运行级别2:多用户 ...

  4. Linux的七个运行级别原理概述

    所谓运行级别,简单点来说,运行级别就是操作系统当前正在运行的功能级别.级别是从0到6,具有不同的功能.这些级别定义在/ect/inittab文件中.这个文件是init程序寻找的主要文件,最先运行的服务 ...

  5. Linux远程连接工具和运行级别

    常用的Linux远程连接工具: xshell MobaXterm windows的命令行工具 Linux的运行级别 linux有七个运行级别 0----所有的服务都不开启,代表的式关机 1---代表的 ...

  6. NO13 Linux的基础优化-关闭SELinux功能-Linux的7种运行级别-防火墙设置-中文显示设置

    壹  安装Linux系统后调优及安全设置: 1 关闭SELinux功能: [root@localhost data]# sed 's#SELINUX=enforcing#SELINUX=disable ...

  7. Linux系统中的运行级别

    什么是运行级呢?简单的说,运行级就是操作系统当前正在运行的功能级别. 它让一些程序在一个级别启动,而另外一个级别的时候不启动. Linux系统的有效登录模式有0~9共十种,不过沿用UNIX系统的至多6 ...

  8. linux的7种运行级别<学习笔记>

    Linux系统有7个运行级别(runlevel) 运行级别0:系统停机状态,系统默认运行级别不能设为0,否则不能正常启动 运行级别1:单用户工作状态,root权限,用于系统维护,禁止远程登陆 运行级别 ...

  9. Linux系统7个运行级别(runlevel)(转)

    原文地址:http://www.cnblogs.com/dkblog/archive/2011/08/30/2160191.html Linux系统有7个运行级别(runlevel) 运行级别0:系统 ...

随机推荐

  1. 011-MySQL Query Cache 查询缓存设置操作

    一.概述 MySQL Query Cache 会缓存select 查询,安装时默认是开启的,但是如果对表进行INSERT, UPDATE, DELETE, TRUNCATE, ALTER TABLE, ...

  2. Jmeter通过SSHCommand测试获取Linux服务器资源文件信息

    有些时间我们想通过接口测试来获取服务器上面的某个资源文件信息,应该怎么办? 别急.... Jmeter通过ssh协议可以实现这个操作. 下面来看一下具体的实现吧. 需要提前安装好的工具: 1.按照好j ...

  3. SQL Server PARTITION FUNCTION(分区)

    分区并不影响Linq,sql查询 在MSSQL中,选中目标表,右键-存储-创建分区 根据提示完成分区,存储成sql 这里展示如何根据Id的数据范围分区 在执行前,可能需要设置日志文件大小为" ...

  4. [PHP] 浅谈 Laravel Authentication 的 guards 与 providers

    从文档的简单介绍上来讲,有一些抽象. 个人感觉,对于概念上的大多数不理解主要还是来自于 文档不是讲设计思路,而是实际操作. 查看英文文档,通常来说可以给你最准确的直觉,而本地翻译一般比较字面或者带有理 ...

  5. LVDS接口液晶屏点屏流程

    使用MStar的TSUM系列的芯片,主要是用来驱动LVDS的屏.在硬件设置无误的情况下(屏开关口.屏电压.PWM等),按照屏规格书上的参数配置屏参,就可以完成点屏了.大概分为几个步骤,确定屏供电电压, ...

  6. 在ensp中的acl控制

    原理 实验模拟 实验拓扑 相关参数 我们在每一台路由器上设置ospf服务,使其互相能通 下面我们配置基本ACL控制访问 配置完成后,尝试在R1上建立telent连接 但是这样设置是不安全的,只要是直连 ...

  7. PHP设计模式 - 命令模式

    命令模式:在软件系统中,“行为请求者”与“行为实现者”通常呈现一种“紧耦合”.但在某些场合,比如要对行为进行“记录.撤销/重做.事务”等处理,这种无法抵御变化的紧耦合是不合适的.在这种情况下,如何将“ ...

  8. 全网最详细的Windows里Git client客户端管理工具SourceTree的下载与安装(图文详解)

    不多说,直接上干货! 很多人用Git命令行不熟练,那么可以尝试使用SourceTree进行操作. 安装之前的必备    (1)Git的安装 Git学习系列之Windows上安装Git详细步骤(图文详解 ...

  9. 002 spring boot框架,引入mybatis-generator插件,自动生成Mapper和Entity

    1.创建一个springboot项目 2.创建项目的文件结构以及jdk的版本 3.选择项目所需要的依赖 点击next,直到项目构建完成. 4.项目初步结构 5.POM文件 <?xml versi ...

  10. Python中的高性能容器--collections

    集合模块 相对于 Python 中内置的称为链表.集合.字典和元组的默认容器类型来说,集合模块( collection module )提供了高性能的备选方案( alternative ). 简单地看 ...