如果你想拥有你从未拥有过的东西,那么你必须去做你从未做过的事情
1、查看系统版本
两种方法
1、使用命令查看
[root@localhost ~]#hostnamectl
Static hostname: localhost.localdomain
Icon name: computer-vm
Chassis: vm
Machine ID: 372f0bb3bfcd4bd09688fd725b9a0855
Boot ID: 378e73aa96074e289ab88283a99719ff
Virtualization: vmware
Operating System: Kylin Linux Advanced Server V10 (Lance)
Kernel: Linux 4.19.90-52.15.v2207.ky10.x86_64
Architecture: x86-64
2、如果只想看系统版本,不想看其他的东西,可以单独查看系统配置文件来查看系统配置文件
[root@localhost ~]#cat /etc/kylin-release
Kylin Linux Advanced Server release V10 (Lance)
2、查看系统内核版本
依然有两种方法
1、显示所有的内核信息
[root@localhost ~]#uname -a
Linux localhost.localdomain 4.19.90-52.15.v2207.ky10.x86_64 #1 SMP Thu Nov 24 21:50:03 CST 2022 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]#
2、只显示内核版本号
[root@localhost ~]#uname -r
4.19.90-52.15.v2207.ky10.x86_64
[root@localhost ~]#
3、系统时间同步
有的时候会需要准确的时间,为什么呢,像是日志采集,系统监控,服务器定时任务,包括搭建K8s集群的时候,集群内所有服务器都需要同步时间
服务器有两种时间,一个是硬件时间,一个是系统时间
硬件时间 BIOS时间
系统时间 操作系统可以看到的时间
1、查看系统时间
[root@localhost ~]#date
2024年 11月 22日 星期五 16:45:39 CST
[root@localhost ~]#
2、查看硬件时间
[root@localhost ~]#clock
2024-11-22 16:46:40.909654+08:00
3、同步系统时间
从阿里云时间服务器同步时间
[root@localhost ~]#ntpdate ntp1.aliyun.com
22 Nov 16:48:17 ntpdate[1672800]: adjust time server 120.25.115.20 offset +0.003922 sec
将系统时间同步给硬件时间
[root@localhost ~]#hwclock -w
4、关闭selinux
为什么一定要关闭selinux呢?
1、selinux会限制root管理员的操作
2、某些应用程序在 SELinux 开启的情况下可能无法正常运行。
3、SELinux 的策略管理比较复杂。
4、在一些性能要求较高的场景中,SELinux 可能会对系统性能产生一定的影响。
5、当系统出现问题时,SELinux 可能会增加故障排查的难度。
在搭建K8s集群之前是一定要关闭selinux的
1、查看selinux的状态
[root@localhost ~]#getenforce
Enforcing #现在是开启的状态,如何关闭呢?
[root@localhost ~]#
关闭
[root@localhost ~]#setenforce 0
setenforce: SELinux is disabled
[root@localhost ~]#getenforce
Permissive
但是这样操作服务器重新启动,selinux还会跟着一起重新启动,直接禁止开机自启,搭建k8s必须关闭
[root@localhost ~]#cat -n /etc/selinux/config
1
2 # This file controls the state of SELinux on the system.
3 # SELINUX= can take one of these three values:
4 # enforcing - SELinux security policy is enforced.
5 # permissive - SELinux prints warnings instead of enforcing.
6 # disabled - No SELinux policy is loaded.
7 SELINUX=disabled
8 #SELINUX=enforcing
9 # SELINUXTYPE= can take one of these three values:
10 # targeted - Targeted processes are protected,
11 # minimum - Modification of targeted policy. Only selected processes are protected.
12 # ukmls - Multi Level Security protection.
13 # ukmcs -ukmcs variants of the SELinux policy.
14 #SELINUXTYPE=targeted
15 SELINUXTYPE=targeted
16
17 # SETLOCALDEFS= Check local definition changes
18 SETLOCALDEFS=0
19
20
[root@localhost ~]#
直接将SELINUX=enforcing替换成SELINUX=disabled
5、关闭防火墙
Contos7开始默认使用firewalld防火墙,但是很多人更习惯于使用iptables作为防火墙,我也是,所以就把firewalld防火墙给关闭了采用iptables作为防火墙,当然了如果你是大佬,特别擅长firewalld防火墙,随自己的习惯就好
1、临时关闭防火墙
[root@localhost ~]# systemctl stop firewalld
2、禁止开机自动运行
[root@localhost ~]# systemctl disable firewalld
想知道这个systemctl stop firewalld的作用吗?
来给你刨析一下systemctl的用法:
systemctl 动作 服务名称
服务: NetworkManager
network
firewalld
动作:
systemctl stop 服务
# 停止服务
systemctl start 服务 # 启动服务
systemctl restart 服务 # 重启服务
systemctl enable 服务 # 开机自动启动此服务
systemctl disable 服务 # 开机禁止启动此服务
systemctl status 服务 # 查看服务的状态
systemctl reload 服务 # 重新加载服务 热加载
什么情况下需要开启防火墙?
1.在公网需要开启
2.用户可以直接访问的服务的服务器 NAT转换 DMZ映射
3.有公网的云服务器
什么情况下需要关闭防火墙?
1.在局域网中不需要开启 教室内 公司内
2.没有公网IP地址
3.内部测试服务器
4.高并发场景需要关闭firewalld 导致服务速度慢 解决方法 部署硬件防火墙
高并发:
很多人同一时间访问我们的服务器
双11 上亿人访问某东 某宝
6、yum仓库优化
优化yum仓库,那么yum仓库是干啥的呢?安装软件的链接的地址,安装软件需要去YUM仓库下载
yum仓库类似 华为应用商店
Linux操作系统默认给我们随机的YUM仓库地址
YUM仓库|YUN源
官方仓库(美国)
阿里云
腾讯云
清华
北大
北邮
华为
亚马逊
这里给你们看一下我自己使用的yum源
[root@localhost ~]#cat /etc/yum.repos.d/kylin_x86_64.repo
###Kylin Linux Advanced Server 10 - os repo###
[ks10-adv-os]
name = Kylin Linux Advanced Server 10 - Os
baseurl = https://update.cs2c.com.cn/NS/V10/V10SP3/os/adv/lic/base/$basearch/
gpgcheck = 1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-kylin
enabled = 1
[ks10-adv-updates]
name = Kylin Linux Advanced Server 10 - Updates
baseurl = https://update.cs2c.com.cn/NS/V10/V10SP3/os/adv/lic/updates/$basearch/
gpgcheck = 1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-kylin
enabled = 1
[ks10-adv-addons]
name = Kylin Linux Advanced Server 10 - Addons
baseurl = https://update.cs2c.com.cn/NS/V10/V10SP3/os/adv/lic/addons/$basearch/
gpgcheck = 1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-kylin
enabled = 0
[Kylin]
name=Kylin Official Repository
baseurl=https://update.cs2c.com.cn/NS/V10/V10SP3/EPKL/x86_64/
enabled=1
gpgcheck=0
这其实就是麒麟官方的仓库,6月的时候还可以和contos仓库通用,但是现在拉取不下来了
我之前有发过搭建本地yum仓库和yum源的方法,可以去看一下我之前的博客
7、不要关闭NetworkManager!!!!!
contos7.9系统内置了NetworkManager服务和network服务,在contos中network 默认使用的;有这个服务才能正常使用网卡,NetworkManager默认是开启的;必须关闭,同时禁止开机运行,若不关闭NetworkManager,会争抢网络管理的控制权,我们没有对NetworkManager配置过任何IP地址,使用服务器过程中,IP地址会变为空
在使用过程中,手动配置10.0.0.200,由200变为xx.xx.xx.111
但是麒麟不一样,只有NetworkManager服务,没有network服务,只有NetworkManager作为服务作为网卡支撑的服务
[root@localhost ~]#systemctl status network
Unit network.service could not be found.
[root@localhost ~]#
想要重启网卡,需要使用ifdown ens33&&ifup ens33才可以做到重启,无法使用systemctl控制重启网卡,你也可以自己写使用systemctl启动的脚本,这个我后面会写教程。
8、优化ssh服务
能够让我们使用远程连接服务器,默认开启,优化远程连接的速度。
[root@localhost ~]#grep UseDNS /etc/ssh/sshd_config
#UseDNS no
UseDNS no
[root@localhost ~]#
[root@localhost ~]#systemctl restart sshd
赠送知识:如何查看你的出网IP?
[root@localhost ~]#curl cip.cc
IP : 124.65.47.106
地址 : 中国 北京
运营商 : 联通
数据二 : 中国北京北京 | 联通
数据三 : 中国北京北京市 | 联通
URL : http://www.cip.cc/124.65.47.106
今天的操作系统优化教程就到这里了,想成为大佬,就要从小白开始,从0开始,一点一点的积累,慢慢成长,终有一日可以成为令别人仰望的大佬,关注小屁,带你了解更多的麒麟操作系统运维的知识!!!