一.查看系统版本信息内核信息
方法1: 通过查看文件 redhat-release 查看系统版本
[root@oldbweb ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
方法2:hostnamecatl 查看版本信息
[root@oldbweb ~]# hostnamectl
Static hostname: oldbweb #主机名称
Icon name: computer-vm
Chassis: vm
Machine ID: 06b0e0ff4c5d459b825b332cbd8d175e
Boot ID: 5fff087e92764b9fa1660270cb2ed7de
Virtualization: vmware # 虚拟平台用的是vmware
Operating System: CentOS Linux 7 (Core) #使用的centos 7.x
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1160.el7.x86_64 # 内核版本3.1.0必须知道版本号
Architecture: x86-64
# centos6.x操作系统内核版本 2.6.32
方法3:使用uname 了解
[root@oldbweb ~]# uname -a
Linux oldbweb 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@oldbweb ~]# uname -r
3.10.0-1160.el7.x86_64
二. 修改操作系统语言 了解
编码常用有两种:
1. UTF-8 万国码
2. GBK 国标
中文要在Linux系统中正常显示xshell必须和系统的编码一致
查看系统的语言:
方法1:通过LANG变量查看
[root@oldbweb ~]# echo $LANG
en_US.UTF-8
方法2:在文件中查看
[root@oldbweb ~]# cat /etc/locale.conf
LANG="en_US.UTF-8"
临时修改
[root@oldboyedu ~]# LANG=zh_CN.UTF-8
三. 关闭selinux
美国国家安全局研发(企业中不使用)
1.查看selinux 状态
[root@oldbweb ~]# getenforce
Enforcing # 默认为开启状态
关闭selinux
方法1: 修改配置文件重启生效 重启禁止启动selinux
[root@oldbweb ~]# vim /etc/selinux/config
SELINUX=disabled
reboot 重启生效
方法2: 在系统中关闭selinux
[root@oldboyedu ~]# setenforce
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@oldboyedu ~]# setenforce Enforcing # 开启selinux
[root@oldboyedu ~]# setenforce 1 # 开启selinux
[root@oldboyedu ~]#
[root@oldboyedu ~]# setenforce Permissive # 关闭selinux
[root@oldboyedu ~]# setenforce 0 # 关闭seilnux
[root@oldboyedu ~]#
[root@oldboyedu ~]# getenforce # 查看selinux
Permissive
小结: 关闭selinux时如果修改了配置文件可以重启 则不需要执行第二步
关闭selinux时如果当前无法重启系统 则执行第一步和第二步
四. 关闭防火墙(优化防火墙)
作用:保护操作系统(流量控制)
CentOS: iptables
CentOS7: firwealld
systemctl 动作 服务名称
systemctl restart network
systemctl status network
中间动作:
stop 停止
start 启动
restart 重启
status 查看状态
enable 开机自动运行此服务
1.查看防火墙的状态
[root@oldbweb ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled #开机自动运行; vendor preset: enabled)
Active: active (running)# 运行中 since Thu 2023-03-02 16:09:29 CST; 8s ago
Docs: man:firewalld(1)
Main PID: 2135 (firewalld)
CGroup: /system.slice/firewalld.service
└─2135 /usr/bin/python2 -Es /usr/sbin/firew...
Mar 02 16:09:29 oldbweb systemd[1]: Starting firewalld...
Mar 02 16:09:29 oldbweb systemd[1]: Started firewalld ...
Mar 02 16:09:29 oldbweb firewalld[2135]: WARNING: Allo...
Hint: Some lines were ellipsized, use -l to show in full..
2.关闭防火墙
[root@oldboyedu ~]# systemctl stop firewalld
3.开机禁止运行防火墙
[root@oldboyedu ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fe
doraproject.FirewallD1.service.
什么情况下开启防火墙:
1.在公网IP地址情况下
2.有对外提供服务的情况下
3.只要用户可以访问到服务器都需要开启防火墙
什么情况下关闭防火墙
1.局域网中的服务器
2.没有多外提供服务的服务器
3.有大流量访问服务器的情况下(安装硬件防火墙)
五. 修改默认YUM仓库
YUM仓库: 安装软件的商店
1.查看当前默认的软件仓库
[root@oldboyedu ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.bupt.edu.cn # 默认YUM仓库的地址
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
repo id repo name status
!base/7/x86_64 CentOS-7 - Base 10,072
!extras/7/x86_64 CentOS-7 - Extras 515
!updates/7/x86_64 CentOS-7 - Updates 4,724
repolist: 15,311 # 可用的软件数量
2. 修改默认的仓库为阿里云仓库
打开阿里云修改仓库的地址:
https://developer.aliyun.com/mirror/
第一步: 备份默认的YUM仓库
[root@oldboyedu ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
第二步: 使用curl命令下载新的YUM源到本地
[root@oldboyedu ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
第三步: 检查是否修改成功
[root@oldboyedu ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com # 修改成功
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
安装企业扩展的仓库:
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
[root@oldboyedu ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,747 # 额外的包
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 515
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 4,724
repolist: 29,058 # 扩展源安装后变为29K+
yum -y install sl # 安装小火车
yum -y install cowsay # 奶牛说话
六. 修改系统时间
1. 查看系统时间
[root@oldbweb ~]# date
Thu Mar 2 16:51:19 CST 2023
2. 修改系统时间
[root@oldbweb ~]# date -s 2222
Thu Mar 2 22:22:00 CST 2023
[root@oldbweb ~]# date
Thu Mar 2 22:22:09 CST 2023
3. 时间同步(使用命令同步时间服务器的时间) 必须掌握
需要提前安装ntpdate
[root@oldbweb ~]# yum -y install ntpdate
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
使用ntpdate ntp1.aliyun.com阿里云时间服务器
[root@oldbweb ~]# ntpdate ntp1.aliyun.com # 同步系统时间
2 Mar 16:59:32 ntpdate[2378]: step time server 120.25.115.20 offset -19808.170426 sec
[root@oldbweb ~]# date
Thu Mar 2 17:06:47 CST 2023
linux时间 服务器必须保证硬件和系统时间一致
一种是系统时间
一种是硬件时间
查看系统时间:
[root@oldbweb ~]# date
Thu Mar 2 17:13:33 CST 2023
查看硬件时间:
[root@oldbweb ~]# clock
Thu 02 Mar 2023 05:13:39 PM CST -0.889955 seconds
将系统时间同步到硬件时间
[root@oldbweb ~]# clock -w
同步流程:
1.安装ntpdate命令
2.使用ntpdate同步时间服务器ntp1.aliyun.com
3.clock -w 将系统时间同步给硬件时间
扩展:时间时区 Asia/ShangHai