沃梦达 / IT编程 / 服务器 / 正文

kvm,nginx,apache nginx (一)

今天心血来潮做一个简单的架构玩玩,架构介绍:一台服务器,安装kvm工具,虚拟2台服务器搭建lamp和lnmp,然后再主服务器上做个nginx负载均衡。1 .准备工作:做一个虚拟机centos6.7-64位,配置如下,怎么做的就不介绍了...

今天心血来潮做一个简单的架构玩玩,架构介绍:

一台服务器,安装kvm工具,虚拟2台服务器搭建lamp和lnmp,然后再主服务器上做个nginx负载均衡。


1 .准备工作:


做一个虚拟机centos6.7-64位,配置如下,怎么做的就不介绍了,不是小白的话应该都知道。

这个可以根据自己的电脑配置而定,内存可以在高点,因为是实验我就给2个G,废话不说,开机。


配置IP地址:(作用是方便远程管理)


# dhclient


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDgzNzgzNC5qcGc=" title="Ny5wbmc=" />


# ifconfig


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDgzODgwOC5qcGc=" title="My5wbmc=" />


#cd /etc/sysconfig/network-scripts/

#ls

#mv ifcfg-eth0 ifcfg-eth1


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDgzOTEyNy5qcGc=" title="NC5wbmc=" />


#vim ifcfg-eth1


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDgzOTMzNC5qcGc=" title="NS5wbmc=" />


因为我的是克隆的虚拟机,所以要把mac和uuid注释掉,如果是自己新搭建的系统就不需要,接下来重启一下网卡。


# /etc/init.d/network restart


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDgzOTUxOC5qcGc=" title="Ni5wbmc=" />


为了不影响实验效果我们把selinx和iptables关闭


# sed -i "s/LINUX=.*/LINUX=disabled/g" /etc/selinux/config

# grep -i --color  linux  /etc/selinux/config


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDgzOTc4Ny5qcGc=" title="OC5wbmc=" />


# chkconfig --list


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0MDA0My5qcGc=" title="OS5wbmc=" />

大家注意啊,iptables关闭了,但是还有一个ip6tables呢?


#chkconfig ip6tables off

# /etc/init.d/ip6tables stop


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0MDQyMS5qcGc=" title="OS5wbmc=" />


ok 我们重启服务器,到这里我们的准备工作就做完了。


2 . kvm工具的使用


首先第一步 检查 cpu 是否支持虚拟化


# egrep ‘(vmx|svm)‘ --color=always /proc/cpuinfo


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0MDc3MC5qcGc=" title="MTEucG5n" />


接下来安装kvm以及依赖包

# yum install -y kvm virt-* libvirt bridge-utils qemu-img


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0MTA1NS5qcGc=" title="MS5wbmc=" />

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0MTQ1OC5qcGc=" title="Mi5wbmc=" />


验证 kvm 模块已经加载

# lsmod |grep --color kvm


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0MTY5My5qcGc=" title="My5wbmc=" />


配置 KVM 虚拟机运行的网络环境


# cd /etc/sysconfig/network-scripts/

# cp ifcfg-eth1 ifcfg-br0

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0MTkwNS5qcGc=" title="NC5wbmc=" />

# vim ifcfg-eth1

# vim ifcfg-br0

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0MjE5Mi5qcGc=" title="NS5wbmc=" />

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0MjQ4MS5qcGc=" title="Ni5wbmc=" />


# /etc/init.d/network restart


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0Mjc2MS5qcGc=" title="Ny5wbmc=" />


3  添加一块硬盘


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0MzEyNy5qcGc=" title="OC5wbmc=" />


# fdisk -l

接下来也没有什么好说的,看图吧


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0MzMyOS5qcGc=" title="MS5wbmc=" />


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0MzgyMC5qcGc=" title="Mi5wbmc=" />

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0NDEwNS5qcGc=" title="My5wbmc=" />


分完区再来查看一下


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0NDQ0MS5qcGc=" title="NC5wbmc=" />


ok  接下来就是格式化,和挂载文件系统了


# mkfs.ext4 /dev/sdb1

# mkdir /data/

# mount /dev/sdb1 /data/

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0NDY4OS5qcGc=" title="Ni5wbmc=" />

挂载完成后我们要设置一下开机挂载,有二种方式:

一种:

# echo "mount /dev/sdb1 /data/" >> /etc/rc.local

二种:

# blkid /dev/sdb1

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0NTAwNS5qcGc=" title="Mi5wbmc=" />

echo "UUID=24e4b20a-9165-4768-b5d9-ea9af5ca255a   /data/  ext4 defaults 0 0 >>  /etc/fstab


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0NTMxOS5qcGc=" title="MS5wbmc=" />

大家可以重启一下服务器实验一下,看看是否开机挂载了。


到这里我们的硬盘也结束了 


4  开始安装虚拟机系统

我们首先来搭建一个简单的NFS文件共享服务器,一会要用到。


# yum install -y nfs-utils rpcbind

# /etc/init.d/rpcbind start

# /etc/init.d/nfs start

# vim /etc/exports

/mnt    192.168.244.0/24

# showmount -e 192.168.244.150

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0NTYxNy5qcGc=" title="NC5wbmc=" />


下面我们开始安装系统

# mount /dev/sr0 /mnt/  

首先把光盘挂载 

# virt-install --name=lamp --ram=512 --disk path=/data/kvm/lamp.img,size=10 --vcpus=1 --os-type=linux --os-variant=rhel6 --network bridge=br0  --graphics=none --console pty,target_type=serial --location=/mnt/ --extra-args=‘console=ttyS0,115200n8 serial‘



会出现下面的结果,不做解释,ok

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0NTk2Ni5qcGc=" title="NS5wbmc=" />

选择NFS ok

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0NjIyMS5qcGc=" title="Ni5wbmc=" />

这个是ip的配置,我自己选择的是手动配置ip地址,ipv6关闭了,ok

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0NjQ4Ni5qcGc=" title="Ny5wbmc=" />

手动输入ip地址,自定义,ok

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0NjczNC5qcGc=" title="OC5wbmc=" />

这个就是我们刚刚建设的NFS了,看下一个图。

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0NzAxNy5qcGc=" title="OS5wbmc=" />

这是我的设置,根据自己的设置输入,注意第二项,/mnt是你挂载光驱的目录,ok 

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0NzI3NS5qcGc=" title="MS5wbmc=" />

看到这个说明你的NFS配置正确并且找到了系统,ok

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0NzQ2OC5qcGc=" title="Mi5wbmc=" />

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0NzY4OS5qcGc=" title="My5wbmc=" />

这个不做解释,ok

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0Nzk1Mi5qcGc=" title="NC5wbmc=" />

这个也不需要解释,设置自己的root密码,自定义 ok

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0ODE2NS5qcGc=" title="NS5wbmc=" />

看图:

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0ODQ0OS5qcGc=" title="Ni5wbmc=" />


看图

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0ODcwMC5qcGc=" title="Ny5wbmc=" />

还是看图

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0ODk1NC5qcGc=" title="OC5wbmc=" />

ok  到这里说明系统安装结束了。

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0OTIxOS5qcGc=" title="MS5wbmc=" />

重启就可以了 

5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0OTQ5NS5qcGc=" title="My5wbmc=" />

到这里就系统就安装完成了,直接输入用户名和密码就可以了。


第二个系统可按照上面的方法在来一遍 顺便回顾一下刚才学习的过程。

也可以克隆一台虚拟机出来,要注意的是,服务器必须在关闭的情况下才能被克隆。

过程这里就不写出来了。


查看一下:


5oqA5pyv5YiG5Lqr650) this.width=650;" src="https://oss.womengda.netL3VwbG9hZC9nZXRmaWxlcy9kZWZhdWx0LzIwMjIvMTEvOS8yMDIyMTEwOTA2NDg0OTczOC5qcGc=" title="NC5wbmc=" />


ok 2个系统安装完毕了。


安装系统到这里结束,我们下一张在来安装服务。…………………………未完

原文:http://dongxin.blog.51cto.com/3486403/1774624

本文标题为:kvm,nginx,apache nginx (一)