centos7模板机制作
1. 环境说明
本文所使用镜像版本为CentOS-7-x86_64-DVD-1810,其他版本亦可参考。
VMware网络使用NAT模式,网段为10.100.1.0/24,网关为10.100.1.254
2. 部署模板
正常安装CentOS7系统, 过程略...
3. 配置模板
[root@centos7 ~]# history
1 yum install -y wget
2 cp /etc/yum.repos.d/CentOS-Base.repo{,.bak}
3 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
4 sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
5 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
6 yum repolist
7 ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
8 setenforce 0 && sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
9 systemctl stop firewalld && systemctl disable firewalld
10 yum install -y iptables-services
11 iptables -F && service iptables save
12 systemctl list-unit-files --type=service|grep 'enabled'
13 systemctl stop NetworkManager postfix && systemctl disable NetworkManager postfix
14 echo "unset MAILCHECK" >> /etc/profile && source /etc/profile
15 yum install -y ntp
16 systemctl start ntpd && systemctl enable ntpd
17 crontab -e
### update time ###
*/5 * * * * systemctl restart ntpd;/usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1
### clean cache ###
* */1 * * * yum clean all && rm -rf /var/cache/yum/* >/dev/null 2>&1
18 yum install -y vim lrzsz tree lsof tcpdump screen man unzip ansible
19 yum install -y bash-completion fping gcc-c++ deltarpm net-tools java-11-openjdk
20 rpm -ivh http://springdale.math.ias.edu/data/puias/unsupported/7/x86_64//iksemel-1.4-6.sdl7.x86_64.rpm
21 vim ~/.bashrc
PS1="\[\e[32;40m\][\u@\h \w]\\$ \[\e[0m\]"
22 source ~/.bashrc
23 vim /etc/ssh/sshd_config
UseDNS no
GSSAPIAuthentication no
24 vim /etc/ssh/ssh_config
StrictHostKeyChecking no
25 systemctl restart sshd 26 yum install -y git 27 git config --global user.name "niuyx";git config --global user.email "niuyx@niuyx.cc" 28 yum install -y yum-utils device-mapper-persistent-data lvm2 29 yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
30 yum install -y docker-ce 31 curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
32 vim /etc/docker/daemon.json
{"registry-mirrors": ["https://d15trfat.mirror.aliyuncs.com"]}
33 systemctl daemon-reload
34 systemctl start docker && systemctl enable docker
35 vim /etc/sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
36 sysctl -p
37 docker info
38 vim /etc/sysconfig/network-scripts/ifcfg-ens33
DEVICE=ens33
NAME=ens33
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
IPADDR=10.100.1.x
PREFIX=24
GATEWAY=10.100.1.254
DNS1=10.100.1.254
DNS2=223.5.5.5
39 vim ~/c7_modify_net.sh
read -p "Define your IP addrs:" ip
declare -i ip
if [[ $ip -le 1 || $ip -ge 254 ]];then
echo "It's a wrong number."
exit 1
else
sed -i "s/IPADDR=10.100.1.x/IPADDR=10.100.1.$ip/g" \
/etc/sysconfig/network-scripts/ifcfg-ens33
fi
read -p "Define your hostname:" h
hostnamectl set-hostname $h
sleep 1
echo "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"
echo "| Configuration Complete and Restart System |"
echo "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"
sleep 1
unlink $0
/usr/sbin/reboot
40 chmod 700 ~/c7_modify_net.sh
41 shutdown -h now
4. 导出模板
关机后选中该虚拟机,编辑虚拟机设置,将CD/DVD(IDE)移除挂载,然后导出OVF文件。
5. 导入模板
文件 --> 打开(O)... --> CentOS7模板机文件 -->定义节点名称-->导入虚拟机
开机后执行脚本,
./c7_modify_net.sh
输入IP和HOSTNAME变量后配置完成。