一、安装VMware虚拟机
版本:
VMware® Workstation 15 Pro
安装方式:
傻瓜式安装
许可证:
UY758-0RXEQ-M81WP-8ZM7Z-Y3HDA
VF750-4MX5Q-488DQ-9WZE9-ZY2D6
UU54R-FVD91-488PP-7NNGC-ZFAX6
YC74H-FGF92-081VZ-R5QNG-P6RY4
YC34H-6WWDK-085MQ-JYPNX-NZRA2
二、安装CentOS系统
系统版本:
CentOS-7-x86_64-DVD-1804.iso
安装方式:
最小安装
网络连接方式(双网卡,一个外网一个内网):
NAT模式,DHCP
三、系统优化
01、下载wget和curl
因为等下要更新yum源为阿里云的源,需要使用wget工具或curl工具下载
yum -y install wget curl
02.更换yum镜像源(默认源和epel源)
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
03.安装常用软件
yum makecache
yum install -y tree vim wget bash-completion bash-completion-extras lrzsz net-tools sysstat iotop iftop htop unzip ntpdate gcc make gcc-c++
04.关闭firewalld 和NetworkManager
systemctl stop firewalld NetworkManager
systemctl disable firewalld NetworkManager
05.关闭selinux
临时关闭
setenforce 0
永久关闭
vim /etc/selinux/config
...
SELINUX=disabled
...
06.Linux汉化
[root@~]# vim /etc/locale.conf
LANG="zh_CN.UTF-8"
07.扩展swap分区
1.查看swap分区大小
free -h
2.使用dd命令增加分区文件大小
dd if=/dev/zero of=/root/swap bs=1M count=1024
其中bs是每块的大小,count是块的数量;bscount,就是swap文件的大小:这里1M1024=1G。可以根据需要自行调整。
此外,swapfile是swap文件的路径,可以根据需求修改。
3.格式化交换分区文件
cd
mkswap swapfile
4.启用swap分区文件
swapon swapfile
5.添加开机启动
修改/etc/fstab文件,在下面添加
vim /etc/fstab
/root/swapswapfile swap swap defaults 0 0
注意,路径还是要对应,而且必须是全路径。最后两个是零,不是大写字母O。
此项不是必须的。如果不修改开机启动配置,重启之后的swap空间会重置,之前配置丢失。
==-脚本一键初始化-==
vi SystemInit.sh
#!/bin/bash
#前提:能正常上网
# 1.下载工具下载
yum -y install wget curl
# 2.更新yum源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# 3.安装常用软件
yum makecache
yum install -y tree vim wget bash-completion bash-completion-extras lrzsz net-tools sysstat iotop iftop htop unzip ntpdate gcc make gcc-c++
# 4.关闭firewalld和NetworkManager
systemctl stop firewalld NetworkManager
systemctl disable firewalld NetworkManager
# 5.关闭selinux
setenforce 0
sed -i s#SELINUX=enforcing#SELINUX=disabled#g /etc/sysconfig/selinux
# 6.添加swap分区
dd if=/dev/zero of=/root/swapfile bs=1M count=1024
cd
mkswap swapfile
swapon swapfile
cat >> /etc/fstab <<EOF
/root/swapfile swap swap defaults 0 0
EOF
sh SystemInit.sh
四、修改网络信息
将网络地址设置为静态的,先查看一下虚拟机的网络信息
image.png
在Linux系统里修改网卡配置
vim /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.66.88
PREFIX=24
GATEWAY=192.168.66.2
DNS1=192.168.66.2
ping一下百度看看能不能正常上网
systemctl restart network
ping www.baidu.com
PING www.a.shifen.com (183.232.231.174) 56(84) bytes of data.
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=1 ttl=128 time=10.6 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=2 ttl=128 time=10.1 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=3 ttl=128 time=12.0 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=4 ttl=128 time=10.0 ms
64 bytes from 183.232.231.174 (183.232.231.174): icmp_seq=5 ttl=128 time=10.6 ms
^C
--- www.a.shifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4012ms
rtt min/avg/max/mdev = 10.070/10.704/12.048/0.723 ms
五、修改网卡名称
建议在安装系统的时候修改
01.在系统安装的引导界面选择Install CentOS 7
选项
image.png
02.将光标选中Install CentOS 7
后,按下键盘的Tab
键进入系统配置,对齐第一行的顶格,输入以下信息
net.ifnames=0 biosdevname=0
image.png
03.按下回车键完成修改,进入系统安装界面。
修改主机名
hostnamectl set-hostname name
# 生效
su -