一.硬件环境:
1.安装虚拟机vmware 10.
新建虚拟机,命名为实验母盘,删除不必要的设备,网卡模式设置为vnet1,并放入centos的光盘,安装centos6.5,选择最小化安装+开发工具+服务器平台开发。
2.安装完成后的设置:
1)安装必要的工具:
cd /etc/yum.repos.d/
rm -rf ./*
vi /etc/yum.repos.d/centos.repo
[local] name=cdroot baseurl=file:///mnt enabled=1 gpgcheck=0
:wq
mount /dev/cdrom /mnt
rpm --import /etc/pki/rpm-gpg/*
yum -y install wget lftp vim bind-utils man elinks ##安装常用的软件包
2)禁用防火墙和selinux:
chkconfig iptables off
chkconfig network on
vim /etc/selinux/config
SELINUX=disabled
:wq
history -c
poweroff
3)为虚拟机做好快照并起名为clear,克隆一个虚拟机并起名为“ftp+dns+dhcp”。
二.配置ftp+dns+dhcp虚拟机:
1)编辑克隆的虚拟机,设置双网卡:eth0(vnet1仅主机),eth1(桥接)
在真机上为vnet1设置ip地址为:192.168.100.1(网络设置中vmnet1),dns为:192.168.100.100
2).配置IP地址和基础设置:
[[email protected] ~]# vi /etc/udev/rules.d/70-persistent-net.rules ##删除eth0的行,将eth1改为eth0,eth2改为eth1
[[email protected] ~]# ip a ##查看MAC
[[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 ##编辑设置如下,mac地址必须和eth1的一致
DEVICE=eth0 HWADDR=00:0C:29:0c:b9:49 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=no BOOTPROTO=static IPADDR=192.168.100.100 NETMASK=255.255.255.0 DNS1=192.168.100.100
:wq
[[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1 ##新建文件,输入如下内保证mac地址必须和eth2一致
DEVICE=eth1 HWADDR=00:0C:29:0c:b9:53 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=no BOOTPROTO=dhcp
:wq
[[email protected] ~]# vi /etc/sysconfig/network
HOSTNAME=ns.linuxyy.cn
:wq
reboot ##重启
[[email protected] named]# vi /etc/hosts
192.168.100.100 ns ns.linuxyy.cn
:wq
3)配置dhcp:注意如果真机是windows环境,使用命令“services.msc”把vm开头的dhcp服务关闭
mount /dev/cdrom /mnt
yum -y install dhcp vsftpd bind bind-chroot
[[email protected] ~]# vim /etc/dhcp/dhcpd.conf
option domain-name "linuxyy.cn"; option domain-name-servers 192.168.100.100; default-lease-time 600; max-lease-time 7200; log-facility local7; subnet 192.168.100.0 netmask 255.255.255.0 { range 192.168.100.150 192.168.100.250; option routers 192.168.100.100; next-server 192.168.100.100; filename "pxelinux.0"; }
:wq
vi /etc/sysconfig/dhcpd
DHCPDARGS=eth0
:wq
/etc/init.d/dhcpd restart
chkconfig dhcpd on
netstat -utpln |grep 67
4)配置vsftpd:配置文件使用默认即可
/etc/init.d/vsftpd start
chkconfig vsftpd on
mkdir /var/ftp/tools
cd /var/ftp/tools
上传常用软件包
ls ##验证是否下载,如果已经下载到真机可以使用xshell上传
chmod 755 /var/ftp/tools ##注意以后有什么新软件也可以下载到这个目录中,下网络资源的命令“wget -P /var/ftp/tools 资源的URL”
由于centos有dvd1和dvd2两个iso镜像,使用下列命令为客户端提供一个接近完整的yum源:
mkdir /var/ftp/centos6
mount /dev/cdrom /mnt ##放入dvd-1.iso
rsync -av /mnt/ /var/ftp/centos6/
umount /mnt/
mount /dev/cdrom /mnt ##放入dvd-2.iso
rsync -av /mnt/ /var/ftp/centos6/
在真机上访问:
ftp://192.168.100.100 ##测试是否能访问如果不能访问请检查:真机虚拟vnet1网卡的IP地址是否设置,能否ping通。
5)配置dns:
[[email protected] ~]# cd /var/named/chroot/etc/
[[email protected] etc]# vim named.conf
options { directory "/var/named"; }; zone "linuxyy.cn." IN { type master; file "linuxyy.cn.zone"; }; zone "100.168.192.in-addr.arpa" IN { type master; file "192.168.100.arpa"; };
:wq
[email protected] etc]# cd ../var/named/
[[email protected] named]# pwd
/var/named/chroot/var/named
[[email protected] named]# vim linuxyy.cn.zone
$TTL 86400 @ IN SOA linuxyy.cn. root.linuxyy.cn. ( 20170630 1H 2M 3W 1D ) @ IN NS ns.linuxyy.cn. mail IN MX 10 mail.linuxyy.cn. @ IN A 192.168.100.100 mail IN A 192.168.100.100 ns IN A 192.168.100.100 ftp IN A 192.168.100.100 ntp IN CNAME ns www IN A 192.168.100.150
:wq
[[email protected] named]# vim 192.168.100.arpa
$TTL 86400 @ IN SOA linuxyy.cn. root.linuxyy.cn. ( 20170630 1H 2M 3W 1D ) @ IN NS ns.linuxyy.cn. 100 IN PTR ns.linuxyy.cn. 100 IN PTR ntp.linuxyy.cn. 100 IN PTR ftp.linuxyy.cn. 150 IN PTR www.linuxyy.cn.
:wq
[[email protected] named]# chown named:named linuxyy.cn.zone 192.168.100.arpa ../../etc/named.conf
[[email protected] named]# named-checkconf ../../etc/named.conf
[[email protected] named]# named-checkzone linuxyy.cn.zone 192.168.100.arpa
zone linuxyy.cn.zone/IN: loaded serial 20150630
OK
[[email protected] named]# /etc/init.d/named restart
[[email protected] named]# chkconfig named on
[[email protected] named]# netstat -utpln |grep 53
[[email protected] named]# nslookup ##测试dns
> server 192.168.100.100
Default server: 192.168.100.100
Address: 192.168.100.100#53
> ns.linuxyy.cn
Server: 192.168.100.100
Address: 192.168.100.100#53
Name: ns.linuxyy.cn
Address: 192.168.100.100
> www.linuxyy.cn
Server: 192.168.100.100
Address: 192.168.100.100#53
Name: www.linuxyy.cn
Address: 192.168.100.150
> ftp.ln
Server: 192.168.100.100
Address: 192.168.100.100#53
Name: ftp.linuxyy.cn
Address: 192.168.100.100
> exit
[[email protected] named]#
5)开SNAT共享上网:
[[email protected] ~]# iptables -t nat -I POSTROUTING -s 192.168.100.0/24 -o eth1 -j MASQUERADE
[[email protected] ~]# /etc/init.d/iptables save
[[email protected] ~]# sed -i ‘/ip_forward/s/0/1/g‘ /etc/sysctl.conf ##开启路由功能
[[email protected] ~]# sysctl -p
总结:
配置好dhcp为以后的实验虚拟机分配ip地址,vsftpd提供资源下载,dns提供名称解析。
一切正常后做好快照。
以后如果需要使用虚拟机,使用母盘克隆即可,克隆后将网卡改为eth0,dns设置为192.168.100.100和其他基础设置(包括/etc/sysconfig/network中的主机名,/etc/hosts等)。
克隆8个虚拟机:
ctos-1 :192.168.100.150
ctos-2 :192.168.100.151
ctos-3 :192.168.100.152
ctos-4 :192.168.100.153
ctos-5 :192.168.100.154
ctos-6 :192.168.100.155
ctos-7 :192.168.100.156
ctos-8 :192.168.100.157
设置步骤:
1.修改eth1==》eth0
2.修改yum--》
vi /etc/yum.repos.d/centos.repo
[local]
name=local
baseurl=ftp://192.168.100.100/centos6
enabled=1
gpgcheck=0
:wq
reboot
history -c
>.bash_history
3.xshell连接:终端修改字符UTF-8,外观设置16大小字体,配色方案。
poweroff
4.为ctos-1设置快照--》clear
复制虚拟机时请选择:我移动虚拟机