centos7模板机搭建
环境准备:
centos7镜像 CentOS-6.7-x86_64-minimal
虚拟化Oracle VM VirtualBox
一、安装虚拟机
1、打开VBox,点击新建
2、选择主机类型
3、设置参数
4、虚拟机设置
添加镜像文件
网络选择桥接本地网卡
5、开启虚拟机
6、选择时区
7、勾选语言支持
8、自定义分区
/boot分区 500M
SWAP 8G
剩下的全部给根
将根分区和/boot分区的文件类型都改为而ext4
9、修改主机名
10、开始安装
11、设置密码
12、reboot
二、更改配置网卡,使用crt连接
1、使用ip a 查看自己网卡设备名称
2、配置网卡
[root@centos7 ~]#vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
TYPE=Ethernet
BOOTPROTO=static
NAME=enp0s3
DEVICE=enp0s3
ONBOOT=yes
IPADDR=192.168.1.65
GATEWAY=192.168.1.1
DNS1=114.114.114.114
DNS2=8.8.8.8
[root@centos7 ~]# systemctl restart network #重启网卡
3、打开crt连接虚拟机
三、优化centos7
1、关闭防火墙
systemctl disable firewalld.service
systemctl disable iptables-services
2、关闭selinux
vi /etc/selinux/config
3、优化sshd服务
echo 'UseDNS no'>>/etc/ssh/sshd_config
echo 'PermitRootLogin yes'>>/etc/ssh/sshd_config
4、添加hosts
vi /etc/hosts
5、配置本地yum源,需要挂载iso镜像。
mkdir /iso
echo -e '/dev/sr0\t/iso\tiso9660\tdefaults\t0 0'>>/etc/fstab
mount -a
cd /etc/yum.repos.d/
rm -rf *
cat >/etc/yum.repos.d/p.repo<<EOF
[p]
name=p
baseurl=file:///iso/
enabled=1
gpgcheck=0
EOF
yum -y install wget
6、配置网络yum源
yum -y install wget
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 使用阿里云镜像站的网络yum源
yum clean all
yum makecache
yum -y install nc net-tools vim tree dstat ntpdate wget unzip
yum -y update
# 加装一些通用的软件,然后将系统各个软件升级到最新版本
7、还原/etc/rc.local的开机执行脚本的能力:
# 第7代系统将/etc/rc.local的执行权限去掉了
# 写入到该文件中的一些想要在开机启动执行的脚本就无法正常执行
# 还原方法就是把权限改回去即可
# 该文件 /etc/rc.local 是 /etc/rc.d/rc.local 文件的软连接
# 因此要修改 /etc/rc.d/rc.local 的权限
chmod +x /etc/rc.d/rc.local
8、配置ntp
ntpdate -u ntp1.aliyun.com
9、开机启动项目优化
systemctl disable dbus-org.freedesktop.NetworkManager.service
systemctl disable dbus-org.freedesktop.nm-dispatcher.service
systemctl disable NetworkManager-dispatcher.service
systemctl disable NetworkManager
systemctl disable postfix.service
# 关闭一些不需要的开机启动项
systemctl list-unit-files --type=service|grep 'enabled'
# 查看目前处于开机启动状态的系统服务
10、重启机器
reboot