2
0
mirror of https://github.com/LCTT/TranslateProject.git synced 2025-03-24 02:20:09 +08:00

Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu.Wang 2018-10-31 21:48:00 +08:00
commit d3e12bbf2c
4 changed files with 369 additions and 442 deletions

View File

@ -0,0 +1,277 @@
重启和关闭 Linux 系统的 6 个终端命令
======
在 Linux 管理员的日程当中,有很多需要执行的任务,其中就有系统的重启和关闭。
对于 Linux 管理员来说,重启和关闭系统是其诸多风险操作中的一例,有时候,由于某些原因,这些操作可能无法挽回,他们需要更多的时间来排查问题。
在 Linux 命令行模式下我们可以执行这些任务。很多时候由于熟悉命令行Linux 管理员更倾向于在命令行下完成这些任务。
重启和关闭系统的 Linux 命令并不多,用户需要根据需要,选择合适的命令来完成任务。
以下所有命令都有其自身特点,并允许被 Linux 管理员使用.
**建议阅读:**
- [查看系统/服务器正常运行时间的 11 个方法][1]
- [Tuptime 一款为 Linux 系统保存历史记录、统计运行时间工具][2]
系统重启和关闭之始,会通知所有已登录的用户和进程。当然,如果使用了时间参数,系统将拒绝新的用户登入。
执行此类操作之前,我建议您坚持复查,因为您只能得到很少的提示来确保这一切顺利。
下面陈列了一些步骤:
* 确保您拥有一个可以处理故障的控制台,以防之后可能会发生的问题。 VMWare 可以访问虚拟机,而 IPMI、iLO 和 iDRAC 可以访问物理服务器。
* 您需要通过公司的流程,申请修改或故障的执行权直到得到许可。
* 为安全着想,备份重要的配置文件,并保存到其他服务器上.
* 验证日志文件(提前检查)
* 和相关团队交流,比如数据库管理团队,应用团队等。
* 通知数据库和应用服务人员关闭服务,并得到确定答复。
* 使用适当的命令复盘操作,验证工作。
* 最后,重启系统。
* 验证日志文件,如果一切顺利,执行下一步操作,如果发现任何问题,对症排查。
* 无论是回退版本还是运行程序,通知相关团队提出申请。
* 对操作做适当守候,并将预期的一切正常的反馈给团队
使用下列命令执行这项任务。
* `shutdown`、`halt`、`poweroff`、`reboot` 命令:用来停机、重启或切断电源
* `init` 命令:是 “initialization” 的简称,是系统启动的第一个进程。
* `systemctl` 命令systemd 是 Linux 系统和服务器的管理程序。
### 方案 1如何使用 shutdown 命令关闭和重启 Linux 系统
`shutdown` 命令用于断电或重启本地和远程的 Linux 机器。它为高效完成作业提供多个选项。如果使用了时间参数,系统关闭的 5 分钟之前,会创建 `/run/nologin` 文件,以确保后续的登录会被拒绝。
通用语法如下:
```
# shutdown [OPTION] [TIME] [MESSAGE]
```
运行下面的命令来立即关闭 Linux 机器。它会立刻杀死所有进程,并关闭系统。
```
# shutdown -h now
```
* `-h`:如果不特指 `-halt` 选项,这等价于 `-poweroff` 选项。
另外我们可以使用带有 `-halt` 选项的 `shutdown` 命令来立即关闭设备。
```
# shutdown --halt now
或者
# shutdown -H now
```
* `-H, --halt`:停止设备运行
另外我们可以使用带有 `poweroff` 选项的 `shutdown` 命令来立即关闭设备。
```
# shutdown --poweroff now
或者
# shutdown -P now
```
* `-P, --poweroff`:切断电源(默认)。
如果您没有使用时间选项运行下面的命令,它将会在一分钟后执行给出的命令。
```
# shutdown -h
Shutdown scheduled for Mon 2018-10-08 06:42:31 EDT, use 'shutdown -c' to cancel.
root@2daygeek.com#
Broadcast message from root@vps.2daygeek.com (Mon 2018-10-08 06:41:31 EDT):
The system is going down for power-off at Mon 2018-10-08 06:42:31 EDT!
```
其他的登录用户都能在中断中看到如下的广播消息:
```
[daygeek@2daygeek.com ~]$
Broadcast message from root@2daygeek.com (Mon 2018-10-08 06:41:31 EDT):
The system is going down for power-off at Mon 2018-10-08 06:42:31 EDT!
```
对于使用了 `-halt` 选项:
```
# shutdown -H
Shutdown scheduled for Mon 2018-10-08 06:37:53 EDT, use 'shutdown -c' to cancel.
root@2daygeek.com#
Broadcast message from root@vps.2daygeek.com (Mon 2018-10-08 06:36:53 EDT):
The system is going down for system halt at Mon 2018-10-08 06:37:53 EDT!
```
对于使用了 `-poweroff` 选项:
```
# shutdown -P
Shutdown scheduled for Mon 2018-10-08 06:40:07 EDT, use 'shutdown -c' to cancel.
root@2daygeek.com#
Broadcast message from root@vps.2daygeek.com (Mon 2018-10-08 06:39:07 EDT):
The system is going down for power-off at Mon 2018-10-08 06:40:07 EDT!
```
可以在您的终端上敲击 `shutdown -c` 选项取消操作。
```
# shutdown -c
Broadcast message from root@vps.2daygeek.com (Mon 2018-10-08 06:39:09 EDT):
The system shutdown has been cancelled at Mon 2018-10-08 06:40:09 EDT!
```
其他的登录用户都能在中断中看到如下的广播消息:
```
[daygeek@2daygeek.com ~]$
Broadcast message from root@vps.2daygeek.com (Mon 2018-10-08 06:41:35 EDT):
The system shutdown has been cancelled at Mon 2018-10-08 06:42:35 EDT!
```
添加时间参数,如果你想在 `N` 秒之后执行关闭或重启操作。这里,您可以为所有登录用户添加自定义广播消息。例如,我们将在五分钟后重启设备。
```
# shutdown -r +5 "To activate the latest Kernel"
Shutdown scheduled for Mon 2018-10-08 07:13:16 EDT, use 'shutdown -c' to cancel.
[root@vps138235 ~]#
Broadcast message from root@vps.2daygeek.com (Mon 2018-10-08 07:08:16 EDT):
To activate the latest Kernel
The system is going down for reboot at Mon 2018-10-08 07:13:16 EDT!
```
运行下面的命令立即重启 Linux 机器。它会立即杀死所有进程并且重新启动系统。
```
# shutdown -r now
```
* `-r, --reboot` 重启设备。
### 方案 2如何通过 reboot 命令关闭和重启 Linux 系统
`reboot` 命令用于关闭和重启本地或远程设备。`reboot` 命令拥有两个实用的选项。
它能够优雅的关闭和重启设备(就好像在系统菜单中惦记重启选项一样简单)。
执行不带任何参数的 `reboot` 命令来重启 Linux 机器。
```
# reboot
```
执行带 `-p` 参数的 `reboot` 命令来关闭 Linux 机器电源。
```
# reboot -p
```
* `-p, --poweroff`:调用 `halt``poweroff` 命令,切断设备电源。
执行带 `-f` 参数的 `reboot` 命令来强制重启 Linux 设备(这类似按压机器上的电源键)。
```
# reboot -f
```
* `-f, --force`:立刻强制中断,切断电源或重启。
### 方案 3如何通过 init 命令关闭和重启 Linux 系统
`init`“initialization” 的简写)是系统启动的第一个进程。
它将会检查 `/etc/inittab` 文件并决定 linux 运行级别。同时,允许用户在 Linux 设备上执行关机或重启操作. 这里存在从 `0``6` 的七个运行等级。
**建议阅读:**
- [如何检查 Linux 上所有运行的服务][3]
执行以下 `init` 命令关闭系统。
```
# init 0
```
* `0` 停机 关闭系统。
运行下面的 `init` 命令重启设备:
```
# init 6
```
* `6`:重启 重启设备。
### 方案 4如何通过 halt 命令关闭和重启 Linux 系统
`halt` 命令用来切断电源或关闭远程 Linux 机器或本地主机。
中断所有进程并关闭 cpu。
```
# halt
```
### 方案 5如何通过 poweroff 命令关闭和重启 Linux 系统
`poweroff` 命令用来切断电源或关闭远程 Linux 机器或本地主机。 `poweroff` 很像 `halt`,但是它可以关闭设备硬件(灯和其他 PC 上的其它东西)。它会给主板发送 ACPI 指令,然后信号发送到电源,切断电源。
```
# poweroff
```
### 方案 6如何通过 systemctl 命令关闭和重启 Linux 系统
systemd 是一款适用于所有主流 Linux 发型版的全新 init 系统和系统管理器,而不是传统的 SysV init 系统。
systemd 兼容与 SysV 和 LSB 初始化脚本。它能够替代 SysV init 系统。systemd 是内核启动的第一个进程,并持有序号为 1 的进程 PID。
**建议阅读:**
- [chkservice 一款终端下系统单元管理工具][4]
它是一切进程的父进程Fedora 15 是第一个适配安装 systemd (替代了 upstart的发行版。
`systemctl` 是命令行下管理 systemd 守护进程和服务的主要工具(如 `start`、`restart`、`stop`、`enable`、`disable`、`reload` & `status`)。
systemd 使用 .service 文件而不是 SysV init 使用的 bash 脚本。 systemd 将所有守护进程归与自身的 Linux cgroups 用户组下,您可以浏览 `/cgroup/systemd` 文件查看该系统层次等级。
```
# systemctl halt
# systemctl poweroff
# systemctl reboot
# systemctl suspend
# systemctl hibernate
```
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/6-commands-to-shutdown-halt-poweroff-reboot-the-linux-system/
作者:[Prakash Subramanian][a]
选题:[lujun9972][b]
译者:[cyleft](https://github.com/cyleft)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.2daygeek.com/author/prakash/
[b]: https://github.com/lujun9972
[1]: https://www.2daygeek.com/11-methods-to-find-check-system-server-uptime-in-linux/
[2]: https://www.2daygeek.com/tuptime-a-tool-to-report-the-historical-and-statistical-running-time-of-linux-system/
[3]: https://www.2daygeek.com/how-to-check-all-running-services-in-linux/
[4]: https://www.2daygeek.com/chkservice-a-tool-for-managing-systemd-units-from-linux-terminal/

View File

@ -1,135 +0,0 @@
Translating by Felix
20 questions DevOps job candidates should be prepared to answer
======
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/hire-job-career.png?itok=SrZo0QJ3)
Hiring the wrong person is [expensive][1]. Recruiting, hiring, and onboarding a new employee can cost a company as much as $240,000, according to Jörgen Sundberg, CEO of Link Humans. When you make the wrong hire:
* You lose what they know.
* You lose who they know.
* Your team could go into the [storming][2] phase of group development.
* Your company risks disorganization.
When you lose an employee, you lose a piece of the fabric of the company. It's also worth mentioning the pain on the other end. The person hired into the wrong job may experience stress, feelings of overall dissatisfaction, and even health issues.
On the other hand, when you get it right, your new hire will:
* Enhance the existing culture, making your organization an even a better place to work. Studies show that a positive work culture helps [drive long-term financial performance][3] and that if you work in a happy environment, youre more likely to do better in life.
* Love working with your organization. When people love what they do, they tend to do it well.
Hiring to fit or enhance your existing culture is essential in DevOps and agile teams. That means hiring someone who can encourage effective collaboration so that individual contributors from varying backgrounds, and teams with different goals and working styles, can work together productively. Your new hire should help teams collaborate to maximize their value while also increasing employee satisfaction and balancing conflicting organizational goals. He or she should be able to choose tools and workflows wisely to complement your organization. Culture is everything.
As a follow-up to our November 2017 post, [20 questions DevOps hiring managers should be prepared to answer][4], this article will focus on how to hire for the best mutual fit.
### Why hiring goes wrong
The typical hiring strategy many companies use today is based on a talent surplus:
* Post on job boards.
* Focus on candidates with the skills they need.
* Find as many candidates as possible.
* Interview to weed out the weak.
* Conduct formal interviews to do more weeding.
* Assess, vote, and select.
* Close on compensation.
![](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/images/life-uploads/hiring_graphic.png?itok=1udGbkhB)
Job boards were invented during the Great Depression when millions of people were out of work and there was a talent surplus. There is no talent surplus in today's job market, yet were still using a hiring strategy that's based on one.
![](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/images/life-uploads/732px-unemployed_men_queued_outside_a_depression_soup_kitchen_opened_in_chicago_by_al_capone_02-1931_-_nara_-_541927.jpg?itok=HSs4NjCN)
### Hire for mutual fit: Use culture and emotions
The idea behind the talent surplus hiring strategy is to design jobs and then slot people into them.
Instead, do the opposite: Find talented people who will positively add to your business culture, then find the best fit for them in a job theyll love. To do this, you must be open to creating jobs around their passions.
**Who is looking for a job?** According to a 2016 survey of more than 50,000 U.S. developers, [85.7% of respondents][5] were either not interested in new opportunities or were not actively looking for them. And of those who were looking, a whopping [28.3% of job discoveries][5] came from referrals by friends. If youre searching only for people who are looking for jobs, youre missing out on top talent.
**Use your team to find and vet potential recruits**. For example, if Diane is a developer on your team, chances are she has [been coding for years][6] and has met fellow developers along the way who also love what they do. Wouldnt you think her chances of vetting potential recruits for skills, knowledge, and intelligence would be higher than having someone from HR find and vet potential recruits? And before asking Diane to share her knowledge of fellow recruits, inform her of the upcoming mission, explain your desire to hire a diverse team of passionate explorers, and describe some of the areas where help will be needed in the future.
**What do employees want?** A comprehensive study comparing the wants and needs of Millennials, GenXers, and Baby Boomers shows that within two percentage points, we all [want the same things][7]:
1. To make a positive impact on the organization
2. To help solve social and/or environmental challenges
3. To work with a diverse group of people
### The interview challenge
The interview should be a two-way conversation for finding a mutual fit between the person hiring and the person interviewing. Focus your interview on CQ ([Cultural Quotient][7]) and EQ ([Emotional Quotient][8]): Will this person reinforce and add to your culture and love working with you? Can you help make them successful at their job?
**For the hiring manager:** Every interview is an opportunity to learn how your organization could become more irresistible to prospective team members, and every positive interview can be your best opportunity to finding talent, even if you dont hire that person. Everyone remembers being interviewed if it is a positive experience. Even if they dont get hired, they will talk about the experience with their friends, and you may get a referral as a result. There is a big upside to this: If youre not attracting this talent, you have the opportunity to learn the reason and fix it.
**For the interviewee** : Each interview experience is an opportunity to unlock your passions.
### 20 questions to help you unlock the passions of potential hires
1. What are you passionate about?
2. What makes you think, "I can't wait to get to work this morning!”
3. What is the most fun youve ever had?
4. What is your favorite example of a problem youve solved, and how did you solve it?
5. How do you feel about paired learning?
6. Whats at the top of your mind when you arrive at, and leave, the office?
7. If you could have changed one thing in your previous/current job, what would it be?
8. What are you excited to learn while working here?
9. What do you aspire to in life, and how are you pursuing it?
10. What do you want, or feel you need, to learn to achieve these aspirations?
11. What values do you hold?
12. How do you live those values?
13. What does balance mean in your life?
14. What work interactions are you are most proud of? Why?
15. What type of environment do you like to create?
16. How do you like to be treated?
17. What do you trust vs. verify?
18. Tell me about a recent learning you had when working on a project.
19. What else should we know about you?
20. If you were hiring me, what questions would you ask me?
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/3/questions-devops-employees-should-answer
作者:[Catherine Louis][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://opensource.com/users/catherinelouis
[1]:https://www.shrm.org/resourcesandtools/hr-topics/employee-relations/pages/cost-of-bad-hires.aspx
[2]:https://en.wikipedia.org/wiki/Tuckman%27s_stages_of_group_development
[3]:http://www.forbes.com/sites/johnkotter/2011/02/10/does-corporate-culture-drive-financial-performance/
[4]:https://opensource.com/article/17/11/inclusive-workforce-takes-work
[5]:https://insights.stackoverflow.com/survey/2016#work-job-discovery
[6]:https://research.hackerrank.com/developer-skills/2018/
[7]:http://www-935.ibm.com/services/us/gbs/thoughtleadership/millennialworkplace/
[8]:https://en.wikipedia.org/wiki/Emotional_intelligence

View File

@ -0,0 +1,92 @@
DevOps应聘者应该准备回答的20个问题
======
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/hire-job-career.png?itok=SrZo0QJ3)
聘请一个不合适的人代价是很高的。根据Link人力资源的首席执行官Jörgen Sundberg的统计招聘雇佣一名新员工将会花费公司$240,000之多当你进行了一次不合适的招聘
* 你失去了他们所知道的。
* 你失去了他们认识的人
* 你的团队将可能进入到一个组织发展的震荡阶段
* 你的公司将会面临组织破裂的风险
当你失去一名员工的时候,你就像丢失了公司图谱中的一块。同样值得一提的是另一端的疼痛。应聘到一个错误工作岗位的员工会感受到很大的压力以及整个身心的不满意,甚至是健康问题。
另外一方面,当你招聘到合适的人时,新的员工将会:
* 丰富公司现有的文化,使你的组织成为一个更好的工作场所。研究表明一个积极的工作文化能够帮助驱动一个更长久的财务业绩,而且如果你在一个欢快的环境中工 作,你更有可能在生活中做的更好。
* 热爱和你的组织在一起工作。当人们热爱他们所在做的,他们会趋向于做的更好。
招聘适合的或者加强现有的文化在DevOps和敏捷团多中是必不可少的。也就是说雇佣到一个能够鼓励积极合作的人以便来自不同背景有着不同目标和工作方式的团队能够在一起有效的工作。你新雇佣的员工因应该能够帮助团队合作来充分发挥放大他们的价值同时也能够增加员工的满意度以及平衡组织目标的冲突。他或者她应该能够通过明智的选择工具和工作流来促进你的组织文化就是一切。
作为我们2017年11月发布的一篇文章[DevOps的招聘经理应该准备回答的20个问题][4],这篇文章将会重点关注在如何招聘最适合的人。
### 为什么招聘走错了方向
很多公司现在在用的典型的雇佣策略是基于人才过剩的基础上:
* 职位公告栏。
* 关注和所需才能符合的应聘者。
* 尽可能找多的候选者。
* 通过面试淘汰弱者。
* 通过正式的面试淘汰更多的弱者。
* 评估,投票,选择。
* 渐渐接近补偿。
![](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/images/life-uploads/hiring_graphic.png?itok=1udGbkhB)
职位公告栏是有成千上万失业者人才过剩的经济大萧条时期发明的。在今天的求职市场上已经没有人才过剩了,然而我们仍然在使用基于此的招聘策略。
![](https://opensource.com/sites/default/files/styles/panopoly_image_original/public/images/life-uploads/732px-unemployed_men_queued_outside_a_depression_soup_kitchen_opened_in_chicago_by_al_capone_02-1931_-_nara_-_541927.jpg?itok=HSs4NjCN)
### 雇佣最合适的人员:运用文化和情感
在人才过剩雇佣策略背后的思想是去设计工作岗位然后将人员安排进去。
相反,做相反的事情:寻找将会积极融入你的商业文化的人才,然后为他们寻找他们热爱的最合适的岗位。要想如此实现,你必须能够围绕他们热情为他们创造工作岗位。
**谁正在寻找一份工作?** 根据一份2016年对美国50000名开发者的调查显示[85.7%的受访对象][5]要么对新的机会不感兴趣,要么对于寻找新工作没有积极性。在寻找工作的那部分中,有将近[28.3%的求职者][5]来自于朋友的推荐。如果你只是在那些在找工作的人中寻找人才,你将会错过高端的人才。
**运用团队力量去发现和寻找潜力的雇员**。列如戴安娜是你的团队中的一名开发者她所提供的机会即使她已经从事编程很多年而且在期间已经结识了很多从事热爱他们所从事的工作的人。难道你不认为她所推荐的潜在员工在技能知识和智慧上要比HR所寻找的要优秀吗在要求戴安娜分享她同伴之前通知她即将到来的使命任务向她阐明你要雇佣潜在有探索精神的团队描述在将来会需要的知识领域。
**雇员想要什么?**一份来自千禧年婴儿潮实时期出生的人的对比综合性研究显示20% 的人所想要的是相同的:
1. 对组织产生积极的影响
2. 帮助解决社交或者环境上的挑战
3. 和一群有动力的人一起工作
### 面试的挑战
面试应该是招聘者和应聘者双方为了寻找最合适的人才进行的一次双方之间的对话。将面试聚焦在企业文化和情感对话两个问题上:这个应聘者将会丰富你的企业文化并且会热爱和你在一起工作吗?你能够在工作中帮他们取得成功吗?
**对于招聘经理来说:** 每一次的面试都是你学习如何将自己的组织变得对未来的团队成员更有吸引力,并且每次积极的面试多都可能是你发现人才(即使你不会雇佣)的机会。每个人都将会记得积极有效的面试的经历。即使他们不会被雇佣,他们将会和他们的朋友谈论这次经历,你竟会得到一个被推荐的机会。这又很大的好处:如果你无法吸引到这个人才,你也将会从中学习吸取经验并且改善。
**对面试者来说**:每次的面试都是你释放激情的机会
### 助你释放潜在雇员激情的20个问题
1. 你热爱什么?
2. “今天早晨我已经迫不及待的要去工作”你怎么看待这句话?
3. 你曾经最快乐的是什么?
4. 你曾经解决问题的最典型的例子是什么,你是如何解决的?
5. 你如何看待配对学习?
6. 你到达办公室和离开办公室心里最先想到的是什么?
7. 你如果你有一次改变你之前或者现在的共工作的一件事的机会,将会是什么事?
8. 当你在这工作的时候,你最兴奋去学习什么?
9. 你的梦想是什么,你如何去实现?
10. 你在学会如何去实现你的追求的时候想要或者需要什么?
11. 你的价值观是什么?
12. 你是如何坚守自己的价值观的?
13. 平衡在你的生活中意味着什么?
14. 你最引以为傲的工作交流能力是什么?为什么?
15. 你最喜欢营造什么样的环境?
16. 你喜欢别人怎样对待你?
17. 你信任我们什么,如何验证?
18. 告诉我们你在最近的一个项目中学习到什么?
19. 我们还能知道你的其他方面的什么?
20. 如果你正在雇佣我,你将会问我什么问题?
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/3/questions-devops-employees-should-answer
作者:[Catherine Louis][a]
译者:[FelixYFZ](https://github.com/FelixYFZ)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://opensource.com/users/catherinelouis
[1]:https://www.shrm.org/resourcesandtools/hr-topics/employee-relations/pages/cost-of-bad-hires.aspx
[2]:https://en.wikipedia.org/wiki/Tuckman%27s_stages_of_group_development
[3]:http://www.forbes.com/sites/johnkotter/2011/02/10/does-corporate-culture-drive-financial-performance/
[4]:https://opensource.com/article/17/11/inclusive-workforce-takes-work
[5]:https://insights.stackoverflow.com/survey/2016#work-job-discovery
[6]:https://research.hackerrank.com/developer-skills/2018/
[7]:http://www-935.ibm.com/services/us/gbs/thoughtleadership/millennialworkplace/
[8]:https://en.wikipedia.org/wiki/Emotional_intelligence

View File

@ -1,307 +0,0 @@
重启和关闭 Linux 系统的 6 个终端命令
======
在 Linux 管理员的日程当中, 有很多需要执行的任务, 系统的重启和关闭就被包含其中.
对于 Linux 管理员来说, 重启和关闭系统是其诸多风险操作中的一例, 有时候, 由于某些原因, 这些操作可能无法挽回, 他们需要更多的时间来排查问题.
在 Linux 命令行模式下我们可以执行这些任务. 很多时候, 由于熟悉命令行, Linux 管理员更倾向于在命令行下完成这些任务.
重启和关闭系统的 Linux 命令并不多, 用户需要根据需要, 选择合适的命令来完成任务.
以下所有命令都有其自身特点, 并允许被 Linux 管理员使用.
**建议阅读 :**
**(#)** [查看系统/服务器正常运行时间的 11 个方法][1]
**(#)** [Tuptime 一款为 Linux 系统保存历史记录, 统计运行时间工具][2]
系统重启和关闭之始, 会通知所有已登录的用户和已注册的进程. 当然, 如果会造成冲突, 系统不会允许新的用户登入.
执行此类操作之前, 我建议您坚持复查, 因为您只能得到很少的提示来确保这一切顺利.
下面陈列了一些步骤.
* 确保您拥有一个可以处理故障的终端, 以防之后可能会发生的问题. VMWare 可以访问物理服务器的虚拟机, IPMI, iLO 和 iDRAC.
* 您需要通过公司的流程, 申请修改或故障的执行权直到得到许可.
* 为安全着想, 备份重要的配置文件, 并保存到其他服务器上.
* 验证日志文件(提前检查)
* 和相关团队交流, 比如数据库管理团队, 应用团队等.
* 通知数据库和应用服务人员关闭服务, 并得到确定.
* 使用适当的命令复盘操作, 验证工作.
* 最后, 重启系统
* 验证日志文件, 如果一切顺利, 执行下一步操作, 如果发现任何问题, 对症排查.
* 无论是回退版本还是运行程序, 通知相关团队提出申请.
* 对操作做适当守候, 并将预期的一切正常的反馈给团队
使用下列命令执行这项任务.
* **`shutdown 命令:`** shutdown 命令用来为中止, 重启或切断电源
* **`halt 命令:`** halt 命令用来为中止, 重启或切断电源
* **`poweroff 命令:`** poweroff 命令用来为中止, 重启或切断电源
* **`reboot 命令:`** reboot 命令用来为中止, 重启或切断电源
* **`init 命令:`** init(initialization 的简称) 是系统启动的第一个进程.
* **`systemctl 命令:`** systemd 是 Linux 系统和服务器的管理程序.
### 方案 - 1: 如何使用 Shutdown 命令关闭和重启 Linux 系统
shutdown 命令用户关闭或重启本地和远程的 Linux 设备. 它为高效完成作业提供多个选项. 如果使用了 time 参数, 系统关闭的 5 分钟之前, /run/nologin 文件会被创建, 以确保后续的登录会被拒绝.
通用语法如下
```
# shutdown [OPTION] [TIME] [MESSAGE]
```
运行下面的命令来立即关闭 Linux 设备. 它会立刻杀死所有进程, 并关闭系统.
```
# shutdown -h now
```
* **`-h:`** 如果不特指 -halt 选项, 这等价于 -poweroff 选项.
另外我们可以使用带有 `poweroff` 选项的 `shutdown` 命令来立即关闭设备.
```
# shutdown --halt now
或者
# shutdown -H now
```
* **`-H, --halt:`** 停止设备运行
另外我们可以使用带有 `poweroff` 选项的 `shutdown` 命令来立即关闭设备.
```
# shutdown --poweroff now
或者
# shutdown -P now
```
* **`-P, --poweroff:`** 切断电源 (默认).
运行以下命令立即关闭 Linux 设备. 它将会立即杀死所有的进程并关闭系统.
```
# shutdown -h now
```
* **`-h:`** 如果不特指 -halt 选项, 这等价于 -poweroff 选项.
如果您没有使用 time 选项运行下面的命令, 它将会在一分钟后执行给出的命令
```
# shutdown -h
Shutdown scheduled for Mon 2018-10-08 06:42:31 EDT, use 'shutdown -c' to cancel.
[email protected]#
Broadcast message from [email protected] (Mon 2018-10-08 06:41:31 EDT):
The system is going down for power-off at Mon 2018-10-08 06:42:31 EDT!
```
其他的登录用户都能在中断中看到如下的广播消息:
```
[[email protected] ~]$
Broadcast message from [email protected] (Mon 2018-10-08 06:41:31 EDT):
The system is going down for power-off at Mon 2018-10-08 06:42:31 EDT!
```
对于使用了 Halt 选项.
```
# shutdown -H
Shutdown scheduled for Mon 2018-10-08 06:37:53 EDT, use 'shutdown -c' to cancel.
[email protected]#
Broadcast message from [email protected] (Mon 2018-10-08 06:36:53 EDT):
The system is going down for system halt at Mon 2018-10-08 06:37:53 EDT!
```
对于使用了 Poweroff 选项.
```
# shutdown -P
Shutdown scheduled for Mon 2018-10-08 06:40:07 EDT, use 'shutdown -c' to cancel.
[email protected]#
Broadcast message from [email protected] (Mon 2018-10-08 06:39:07 EDT):
The system is going down for power-off at Mon 2018-10-08 06:40:07 EDT!
```
可以在您的终端上敲击 `Shutdown -c` 选项取消操作.
```
# shutdown -c
Broadcast message from [email protected] (Mon 2018-10-08 06:39:09 EDT):
The system shutdown has been cancelled at Mon 2018-10-08 06:40:09 EDT!
```
其他的登录用户都能在中断中看到如下的广播消息:
```
[[email protected] ~]$
Broadcast message from [email protected] (Mon 2018-10-08 06:41:35 EDT):
The system shutdown has been cancelled at Mon 2018-10-08 06:42:35 EDT!
```
添加 time 参数, 如果你想在 `N` 秒之后执行关闭或重启操作. 这里, 您可以为所有登录用户添加自定义广播消息. 例如, 我们将在五分钟后重启设备.
```
# shutdown -r +5 "To activate the latest Kernel"
Shutdown scheduled for Mon 2018-10-08 07:13:16 EDT, use 'shutdown -c' to cancel.
[[email protected] ~]#
Broadcast message from [email protected] (Mon 2018-10-08 07:08:16 EDT):
To activate the latest Kernel
The system is going down for reboot at Mon 2018-10-08 07:13:16 EDT!
```
运行下面的命令立即重启 Linux 设备. 它会立即杀死所有进程并且重新启动系统.
```
# shutdown -r now
```
* **`-r, --reboot:`** 重启设备.
### 方案 - 2: 如何通过 reboot 命令关闭和重启 Linux 系统
reboot 命令用于关闭和重启本地或远程设备. Reboot 命令拥有两个实用的选项.
它能够优雅的关闭和重启设备(就好像在系统菜单中惦记重启选项一样简单).
执行不带任何参数的 `reboot` 命令来重启 Linux 设备
```
# reboot
```
执行带 `-p` 参数的 `reboot` 命令来关闭 Linux 设备或切断电源
```
# reboot -p
```
* **`-p, --poweroff:`** 调用 halt 或 poweroff 命令, 切断设备电源.
执行带 `-f` 参数的 `reboot` 命令来强制重启 Linux 设备(这类似按压 CPU 上的电源键)
```
# reboot -f
```
* **`-f, --force:`** 立刻强制中断, 切断电源或重启
### 方案 - 3: 如何通过 init 命令关闭和重启 Linux 系统
init(initialization 的简写) 是系统启动的第一个进程.
他将会检查 /etc/inittab 文件并决定 linux 运行级别. 同时, 授权用户在 Linux 设备上执行关机或重启 操作. 这里存在从 0 到 6 的七个运行等级.
**建议阅读 :**
**(#)** [如何检查 Linux 上所有运行的服务][3]
执行一下 init 命令关闭系统.
```
# init 0
```
* **`0:`** 中断 关闭系统.
运行下面的 init 命令重启设备
```
# init 6
```
* **`6:`** 重启 重启设备.
### 方案 - 4: 如何通过 halt 命令关闭和重启 Linux 系统
halt 命令用来切断电源或关闭远程 Linux 设备或本地主机.
中断所有进程并关闭 cpu
```
# halt
```
### 方案 - 5: 如何通过 poweroff 命令关闭和重启 Linux 系统
poweroff 命令用来切断电源或关闭远程 Linux 设备或本地主机. Poweroff 很像 halt, 但是它可以关闭设备自身的单元(等和其他 PC 上的任何事物). 它会为 PSU 发送 ACPI 指令, 切断电源.
```
# poweroff
```
### 方案 - 6: 如何通过 systemctl 命令关闭和重启 Linux 系统
Systemd 是一款适用于所有主流 Linux 发型版的全新 init 系统和系统管理器, 而不是传统的 SysV init 系统.
systemd 兼容与 SysV 和 LSB 脚本. 它能够替代 sysvinit 系统. systemd 是内核启动的第一个进程, 并持有序号为 1 的进程 PID.
**建议阅读 :**
**(#)** [chkservice 一款终端下系统单元管理工具][4]
它是一切进程的父进程, Fedora 15 是第一个适配安装 systemd 的发行版.
Its a parent process for everything and Fedora 15 is the first distribution which was adapted systemd instead of upstart.
systemctl 是命令行下管理系统, 守护进程, 开启服务(如 start, restart, stop, enable, disable, reload & status)的主要工具.
systemd 使用 .service 文件而不是 bash 脚本(SysVinit 用户使用的). systemd 将所有守护进程归与自身的 Linux cgroups 用户组下, 您可以浏览 /cgroup/systemd 文件查看系统层次等级
```
# systemctl halt
# systemctl poweroff
# systemctl reboot
# systemctl suspend
# systemctl hibernate
```
--------------------------------------------------------------------------------
via: https://www.2daygeek.com/6-commands-to-shutdown-halt-poweroff-reboot-the-linux-system/
作者:[Prakash Subramanian][a]
选题:[lujun9972][b]
译者:[cyleft](https://github.com/cyleft)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://www.2daygeek.com/author/prakash/
[b]: https://github.com/lujun9972
[1]: https://www.2daygeek.com/11-methods-to-find-check-system-server-uptime-in-linux/
[2]: https://www.2daygeek.com/tuptime-a-tool-to-report-the-historical-and-statistical-running-time-of-linux-system/
[3]: https://www.2daygeek.com/how-to-check-all-running-services-in-linux/
[4]: https://www.2daygeek.com/chkservice-a-tool-for-managing-systemd-units-from-linux-terminal/