2.17 新手必看的Linux服务器管理和维护注意事项

本节介绍有关服务器管理和维护过程中的一些注意事项,都是笔者的经验之谈,相信对新手会有一定的启发和帮助。 很多初学者接触Linux 时间不长,还未完整地学习一遍 Linux,理解本节内容可能有些困难,可以先跳过本节,阅读完整套教程后再回过头来阅读。

为什么远程服务器无法关闭?原因很简单,远程服务器不在本地,关机后谁来帮你按电源按钮启动服务器?虽然计算机技术日新月异,但接通电源、打开计算机等任务仍然需要手工完成。如果服务器是远程的,一旦关闭,您只能向托管室的管理员打开它。

[En]

Why can’t the remote server shut down? The reason is very simple, the remote server is not placed locally, who will help you press the power button to start the server after shutdown? Although computer technology is changing with each passing day, tasks such as plugging in power and turning on the computer still need to be done by hand. If the server is remote, once it is turned off, you can only turn it on to the administrator in the hosting room.

当远程服务器重新启动时,需要注意两件事。

[En]

There are two things to be aware of when the remote server is restarted.

电脑硬盘在高速存储过程中最怕断电或重启,极易造成硬盘损坏。因此,请在重新启动之前停止您的服务,甚至考虑暂时断开提供服务的网络。

[En]

The computer’s hard disk is most afraid of power outage or reboot during high-speed storage, which is very easy to cause hard disk damage. So, stop your service before restarting, or even consider temporarily disconnecting the network that provides services.

也许你觉得服务器太精致了?我的笔记本电脑经常被强制关机,但我没有发现硬盘驱动器损坏。这是因为您的个人计算机不会被很多人访问,并且硬盘在强制停电期间不会交换数据。小心驶得万年船!

[En]

Maybe you think the server is so delicate? My laptop is often forcibly shut down, but I don’t find that the hard drive is damaged. This is because your personal computer is not accessed by many people, and the hard disk does not exchange data during a forced power outage. Caution is the parent of safety!

Linux 可以识别的重启命令有很多条,但是建议大家使用 “shutdown-r now” 命令重启。这条命令在重启时会正常保存和中止服务器中正在运行的程序,是安全命令。

最好在重启前执行几次 “sync” 命令,这条命令是数据同步命令,可以让暂时保存在内存中的数据同步到硬盘上。

重启和关机也是服务器需要注意的操作规范,错误的重启和关机会导致服务器故障。

[En]

Restart and shutdown are also operating specifications that servers need to pay attention to, and incorrect restarts and shutdowns cause server failures.

在服务器访问高峰期,如果使用一些对服务器压力很大的命令,可能会导致服务器响应缓慢,甚至崩溃。

[En]

At the peak of server access, if you use some commands that are under great pressure on the server, it may cause the server to respond slowly or even crash.

哪些命令是高负载命令呢?如果大家使用过 Windows 操作系统,则也会留意一些操作会给计算机带来较大的运算压力,道理都是一样的,如复制大量的数据、压缩或者解压缩大文件、大范围的硬盘搜索等。

服务器访问高峰一般认为在17:00至24:00之间。当然,每台服务器提供的具体服务各不相同,访问高峰期有时也各不相同。例如,如果服务器主要由美国人访问,则要考虑时差;或者服务器提供的服务非常特殊,访问高峰期可能不同。

[En]

The peak of server access is generally considered to be between 17:00 and 24:00. Of course, the specific services provided by each server are different, and the peak periods of access sometimes vary. For example, if the server is mainly accessed by the American people, you have to consider the jet lag; or the service provided by the server is very special, and the peak periods of access may be different.

重载命令一般建议在凌晨4点到5点之间执行。那么,这是不是意味着我们需要在凌晨工作?当然不是。谁能忍受得了呢?我们可以使用系统的计划任务来允许在指定的时间段内自动执行操作。

[En]

Heavy load commands are generally recommended to be executed between 4:00 and 5:00 in the morning. So, does that mean we need to work in the wee hours of the morning? Of course not. Who can stand that? We can use the scheduled tasks of the system to allow the operation to be performed automatically within a specified period of time.

防火墙是指将内网和外网分开,并依照数据包的 IP 地址、端口号和数据包中的数据来判断是否允许数据包通过的网络设备。

防火墙可以是安装在服务器上的硬件防火墙设备或防火墙软件。

[En]

Firewalls can be hardware firewall devices or firewall software installed on the server.

简单地说,防火墙是根据自己的参数来确定是否允许数据包通过的网络设备。如果我们的服务器要在公共网络中安全使用,我们需要使用防火墙来过滤有害的数据包。

[En]

To put it simply, a firewall is a network device that determines whether a packet is allowed to pass through according to its own parameters. If our server is to be used safely in the public network, we need to use a firewall to filter harmful packets.

但在配置防火墙时,如果管理员对防火墙不是很熟悉,就有可能把自己的正常访问数据包和有害数据包全部过滤掉,导致自己也无法正常登录服务器。比如说,防火墙关闭了远程连接的 SSH 服务的端口。

防火墙配置完全靠人工命令完成,配置规则和配置命令也比较复杂,万一设置不慎,就会发生一场悲剧。这种情况如何才能避免呢?

[En]

Firewall configuration is completed entirely by manual commands, configuration rules and configuration commands are also relatively complex, in case the setting is absent-minded, a tragedy occurs. How can this situation be avoided?

当然,最好的方法是在服务器上本地配置防火墙,这样即使您的远程登录被过滤,您也可以通过本地登录来恢复它。如果服务器已经远程登录,并且您想要配置防火墙,最好在本地测试完成后再上传,这样可以将失败的概率降到最低。

[En]

The best way, of course, is to configure a firewall locally on the server, so that even if your remote login is filtered, you can restore it through local login. If the server is already logged in remotely and you want to configure a firewall, it is best to upload it after the local test is complete, which will minimize the probability of failure.

虽然已经在本地进行了测试,但上载到远程服务器时仍会出现问题。于是笔者想到了一个愚蠢的办法,如果你需要远程配置防火墙,先写一个系统计时任务,让它每5分钟清除一次防火墙规则,即使写错了,还是有机会出尔反尔。等到测试没有问题,然后删除系统计时任务。

[En]

Although it has been tested locally, problems can still occur when uploading to the remote server. So the author thought of a stupid way, if you need to configure the firewall remotely, first write a system timing task and let it clear the firewall rules every 5 minutes, even if you write it wrong, there is still a chance to go back on your promise. Wait until there is no problem with the test, and then delete the system timing task.

简而言之,您可以使用多种方法,只要您在配置防火墙时小心不要将自己踢出服务器即可。

[En]

In short, you can use a variety of methods, as long as you are careful not to kick yourself off the server when configuring the firewall.

除了之前介绍的设置密码需要遵守复杂性、易记忆性和时效性三原则外,还需要注意密码的保存。

[En]

In addition to the previous introduction that setting passwords requires compliance with the three principles of complexity, easy memory and timeliness, we also need to pay attention to the preservation of passwords.

我们日常使用的最简单的原则是写下密码。可能有很多服务器,不可能所有服务器都使用相同的密码,最好是每个服务器都有不同的密码(但这在实际工作中是不现实的)。一般做法是对服务器进行分类,每种类型的服务器都有相同的密码,这可以有效减少密码的数量。但有了大量的服务器,密码的数量是可怕的。

[En]

Our simplest principle for daily use is to write down passwords. There may be many servers, it is not possible for all servers to use the same password, it is best to have different passwords for each server (but it is not realistic in actual work). The general practice is to classify the servers, and each type of server has the same password, which can effectively reduce the number of passwords. But with a large number of servers, the number of passwords is frightening.

例如,笔者在从事游戏运维时,有2000多台服务器,加上交换机、路由器等网络设备,虽然采取了对每一类服务器使用相同密码的方法,但密码总数仍超过100个。此时记住密码基本上是一项不可能完成的任务。那么,如何保存这些密码呢?只能通过文件保存,当然这些文件不能以明文保存,而是要加密。

[En]

For example, when the author was engaged in game operation and maintenance, there were more than 2000 servers, plus network equipment such as switches and routers, although the method of using the same password for each type of server was adopted, the total number of passwords was still more than 100. Memorizing the password at this time is basically an impossible task. So, how do you save these passwords? Can only be saved through documents, of course, these documents can not be saved in clear text, but to be encrypted.

简而言之,合理的密码需要以适当的方式保存,这是构建服务器体系结构时必须考虑的问题。

[En]

In short, a reasonable password needs to be saved in an appropriate way, which must be considered when building a server architecture.

管理服务器应遵循最基本的原则,即“授予用户最低权限”。

[En]

The management server should follow the most basic principle of “giving users minimum permissions”.

初次接触服务器的人会很迷惑,我们所有同事都使用管理员 root 账户登录多好,省得还要学习如何添加用户、设置权限。这样操作,如果是对个人计算机来讲问题不大,如日常使用的 Windows 桌面系统,但如果是服务器,就会出现重大的安全隐患。

在实际的工作中,因为给内部员工分配的权限不合理而导致数据泄密甚至触犯法律的情况屡见不鲜。所以,在服务器上,合理的权限规划必不可少!而且就算只有你是这台服务器的 root,我们也建议在管理服务器时,能使用普通用户完成的操作都使用普通用户,确实完成不了的操作要么进行授权,要么再切换到 root 执行。因为 Linux 上的 root 用户权限实在过大,一旦误操作,后果是严重的,下场是惨淡的。

在实际工作中,服务器越重要,权限管理就越严格。原则上,在工作能做的前提下,分配的权限越小越安全。当然,权限越小,需要执行的规划和权限分配任务就越多,但服务器越可靠。

[En]

In the actual work, the more important the server, the stricter the management of permissions. In principle, on the premise that the work can be done, the smaller the permissions assigned, the safer it is. Of course, the smaller the permissions, the more planning and permission allocation tasks you need to do, but the more reliable the server is.

如果没有备份服务器,那将是致命的!

[En]

If there is no backup server, it is killing!

我周围的人很多,手机坏了或死了,通讯录不见了;电脑硬盘坏了,上面的信息再也找不到了,我完全没有备份的感觉。个人损失通常是可以承受的,但企业服务器损失可能是惊人的。

[En]

There are a lot of people around me, the phone is broken or dead, the address book is gone; the hard drive of my computer is broken, the information above can no longer be found, and I have no sense of backup at all. Individual losses are often bearable, but corporate server losses can be staggering.

有些人知道备份很重要,但因为懒惰或健忘,后悔已经太晚了。很多事情知道起来容易做起来难,备份不是一丁点儿侥幸。如果公司的主要盈利项目是互联网上的业务,那么数据丢失可能会导致公司利润的直接损失。

[En]

Some people know that backup is important, but because they are lazy or forget, it is too late to regret. A lot of things are easier known than done, backup is not the slightest fluke. If the main profit item of the company is the business on the Internet, then the loss of data may result in the direct loss of profits of the company.

Original: https://www.cnblogs.com/qinlulu/p/16226615.html
Author: 开源Linux
Title: 2.17 新手必看的Linux服务器管理和维护注意事项

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/523690/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球