Centos7.9最小化安装与初始化环境配置
镜像源下载地址:http://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/
(CentOS-7.9.2009-x86_64-minimal.iso )
最小化安装过程省略,使用VM虚拟机安装和Xshell7映射连接
1.关闭防火墙
systemctl disable --now firewalld
2.关闭SELinux
- vi /etc/selinux/config
- 找到并编辑:SELINUX=disabled
3.查看内核版本
uname -r
4.查看系统发行版本
cat /etc/redhat-release
5.创建yum仓库配置文件
1.设置光盘挂载目录
- rpm -q autofs || yum -y install autofs
- systemctl enable --now autofs
2.设置阿里云为yum仓库
(1)创建备份文件 :
- mkdir /etc/yum.repos.d/backup
- mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
(2)创建并编辑仓库:
vi /etc/yum.repos.d/ base.repo
[base]
name=base
baseurl=http://mirrors.aliyun.com/centos/7.9.2009/os/x86_64/
gpgcheck=0
enable=1
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
gpgcheck=0
enable=1
[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/7.9.2009/extras/x86_64/
gpgcheck=0
enable=1
(3):启用仓库
- yum repolist
- yum clean all && yum makecache
6.安装常用软件
yum -y install gcc make autoconf gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel zlib-devel vim lrzsz tree tmux lsof tcpdump wget net-tools iotop bc bzip2 zip unzip nfs-utils man-pages
7.实现邮件通信
yum -y install postfix mailx
systemctl enable --now postfix
8.设置主机名(永久生效)
hostnamectl set-hostname centos7.9
9.定义别名(永久生效)
vim ~/.bashrc
-
alias scandisk=‘echo - - - > /sys/class/scsi_host/host0/scan;echo - - - > /sys/class/scsi_host/host1/scan;echo - - - > /sys/class/scsi_host/host2/scan’
-
alias cdnet=‘cd /etc/sysconfig/network-scripts/’
(重启生效)
11:修改提示符颜色(永久生效)
vim /etc/profile.d/env.sh
PS1="\e[1;33m][\u@\h \w]\e[0m]"
(重启生效)
12.系统时间与网络时间同步
(1).安装ntpdate工具
yum -y install ntp ntpdate
(2).设置系统时间与网络时间同步
ntpdate cn.pool.ntp.org
(3).将系统时间写入硬件时间
hwclock --systohc
13.修改网卡名称
- 编辑网卡配置文件
vim /etc/sysconfig/grub
GRUB_CMDLINE_LINUX=“net.ifnames=0 biosdevname=0”
- 生成grub配置文件
grub2-mkconfig -o /etc/grub2.cfg
-
重命名
cdnet进人目录 ls找网卡配置文件
mv ifcfg-ens33 ifcfg-eth0
14.设置静态IP、网关
(1).修改网卡配置文件
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=10.0.0.152
PREFIX=24
ONBOOT=yeS
DNS1=10.0.0.2
DNS2= 180.76.76.76
2.关掉 NetworkManager
systemctl stop NetworkManager
systemctl disable NetworkManager
3.重启网卡
service network restart
(Xshell 重配虚拟机IP以连接)
15.时间同步
1.服务器端配置
-
hostname -I
查看本地IP 10.0.0.155
-
yum -y install chrony
-
vim /etc/chrony.conf
server ntp.aliyun.com iburst
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
#allow 192.168.0.0/16
allow 0.0.0.0/0 #加此行,指定允许同步的网段
#Serve time even if not synchronized to a time source.
local stratum 10 #删除此行注释,当互联网无法连接,仍然可以为客户端提供时间同步服务
- systemctl restart chronyd
服务启动后会打开端口123/udp
- ss -ntlu
2.客户端配置
-
vim /etc/chrony.conf
server 10.0.0.155 iburst
-
systemctl restart chronyd.service
重启校准时间服务
#确认同步成功
- chronyc sources -v
10.0.0.155是服务器的IP地址,前面*号表示已同步