壁立千仞 无欲则刚
计算机中,一个正在执行的程序或命令,被叫做“进程”(process)。
启动之后一只存在、常驻内存的进程,一般被称作“服务”(service)。
service 服务名 start | stop | restart | status
查看服务的方法:/etc/init.d/服务名 ,发现只有两个服务保留在 servic
[root@centos7:101 init.d]# pwd
/etc/init.d
[root@centos7:101 init.d]# ls -al
drwxr-xr-x. 2 root root 4096 3 月 19 15:24 .
drwxr-xr-x. 10 root root 4096 3 月 19 15:24 ..
-rw-r--r--. 1 root root 18104 1 月 3 2018 functions
-rwxr-xr-x. 1 root root 4334 1 月 3 2018 netconsole
-rwxr-xr-x. 1 root root 7293 1 月 3 2018 network
-rw-r--r--. 1 root root 1160 4 月 11 2018 READ
[root@centos7:101 ~]# service network status
[root@centos7:101 ~]# service network stop
[root@centos7:101 ~]# service network start
[root@centos7:101 ~]# service network restart
chkconfig (功能描述:查看所有服务器自启配置)
chkconfig 服务名 off (功能描述:关掉指定服务的自动启动)
chkconfig 服务名 on (功能描述:开启指定服务的自动启动)
chkconfig 服务名 --list (功能描述:查看服务开机启动状态)
[root@centos7:101 ~]# chkconfig network on
[root@centos7:101 ~]# chkconfig network off
[root@centos7:101 ~]# chkconfig --level 指定级别 network on
[root@centos7:101 ~]# chkconfig --level 指定级别 network off
systemctl start | stop | restart | status 服务名
查看服务的方法:/usr/lib/systemd/system
[root@centos7:101 system]# pwd
/usr/lib/systemd/system
[root@centos7:101 init.d]# ls -al
-rw-r--r--. 1 root root 275 4 月 27 2018 abrt-ccpp.serv
-rw-r--r--. 1 root root 380 4 月 27 2018 abrtd.service
-rw-r--r--. 1 root root 361 4 月 27 2018 abrt-oops.service
-rw-r--r--. 1 root root 266 4 月 27 2018 abrt-pstoreoops.service
-rw-r--r--. 1 root root 262 4 月 27 2018 abrt-vmcore.service
-rw-r--r--. 1 root root 311 4 月 27 2018 abrt-xorg.service
-rw-r--r--. 1 root root 751 4 月 11 2018 accounts-daemon.service
-rw-r--r--. 1 root root 527 3 月 25 2017 alsa-restore.service
-rw-r--r--. 1 root root 486 3 月 25 2017 alsa-state.service
……
[root@centos7:101 ~]# systemctl status firewalld
[root@centos7:101 ~]# systemctl stop firewalld
[root@centos7:101 ~]# systemctl start firewalld
[root@centos7:101 ~]# systemctl restart firewalld
systemctl list-unit-files (功能描述:查看服务开机启动状态)
systemctl disable service_name (功能描述:关掉指定服务的自动启动)
systemctl enable service_name (功能描述:开启指定服务的自动启动)
[root@centos7:101 ~]# systemctl enable firewalld.service
[root@centos7:101 ~]# systemctl disable firewalld.service
[root@centos7-101 ~]# setup

multi-user.target 等价于原运行级别 3(多用户有网,无图形界面)
graphical.target 等价于原运行级别 5(多用户有网,有图形界面)
[root@centos7:101 ~]# systemctl get-default
[root@centos7:101 ~]# systemctl set-default TARGET.target
(这里 TARGET 取 multi-user 或者 graphical)
[root@centos7:101 ~]# systemctl status firewalld
[root@centos7:101 ~]# systemctl stop firewalld
[root@centos7:101 ~]# systemctl enable firewalld.service
[root@centos7:101 ~]# systemctl disable firewalld.service
在 linux 领域内大多用在服务器上,很少遇到关机的操作。毕竟服务器上跑一个服务是永无止境的,除非特殊情况下,不得已才会关机。
(1)sync (功能描述:将数据由内存同步到硬盘中)
(2)halt (功能描述:停机,关闭系统,但不断电)
(3)poweroff (功能描述:关机,断电)
(3)reboot (功能描述:就是重启,等同于 shutdown -r now)
(4)shutdown [选项] 时间
| 选项 | 功能 |
|---|---|
| -H | 相当于–halt,停机 |
| -r | -r=reboot 重启 |
| 参数 | 功能 |
|---|---|
| now | 立刻关机 |
| 时间 | 等待多久后关机(时间单位是分钟)。 |
Linux 系统中为了提高磁盘的读写效率,对磁盘采取了 “预读迟写”操作方式。当用户保存文件时,Linux 核心并不一定立即将保存数据写入物理磁盘中,而是将数据保存在缓冲区中,等缓冲区满时再写入磁盘,这种方式可以极大的提高磁盘写入数据的效率。但是,也带来了安全隐患,如果数据还未写入磁盘时,系统掉电或者其他严重问题出现,则将导致数据丢失。使用 sync 指令可以立即将缓冲区的数据写入磁盘。
[root@centos7:101 ~]#sync
[root@centos7:101 ~]# reboot
[root@centos7:101 ~]#halt
[root@centos7:101 ~]#shutdown -h 1 ‘This server will shutdown after 1 mins’
[root@centos7:101 ~]# shutdown -h now
[root@centos7:101 ~]# shutdown -r