Centos7+CloudStack+KVM基础搭建文档

南风 2018年03月18日 45次浏览

关闭selinux

sed -i s#'SELINUX=enforcing'#'SELINUX=disabled'#g /etc/selinux/config

setenforce 0

关闭防火墙

systemctl stop firewalld

systemctl disable firewalld

安装NTP(时间同步)

yum -y install ntp

systemctl enable ntpd

安装ManagementServer(管理端的源)

vi /etc/yum.repos.d/cloudstack.repo

[cloudstack]
name=cloudstack
baseurl=http://cloudstack.apt-get.eu/centos/7/4.8/
enabled=1
gpgcheck=0

安装Cloudstack管理server

yum -y install cloudstack-management 

安装数据库(mysql和mariadb都可以)

yum install mariadb mariadb-server 

vi /etc/my.cnf 

[mysqld]
innodb_rollback_on_timeout=1
innodb_lock_wait_timeout=600
max_connections=350
log-bin=mysql-bin
binlog-format = 'ROW'

启动数据库并设置为开机启动

systemctl start mariadb      ###启动数据库
systemctl enable mariadb     ###开机自启动

初始化数据库

mysql_secure_installation              
###设置密码然后一路yyyy (yes)

使用cloudstack-setup-databases初始化ClouStack数据库:

cloudstack-setup-databases cloud:cloud@localhost --deploy-as=root:123456 -i 192.168.100.4 
 
### 192.168.100.4是当前系统的本地ip
### 重置数据库123456数据库密码

cloudstack安装tomcat服务器

cloudstack-setup-management --tomcat7

启动cloudstack

systemctl start cloudstack-management

配置NFS存储

yum -y install nfs-utils rpcbind

配置域名(随意配置)

vi /etc/idmapd.conf
Domain = xxx

准备NFS目录

mkdir -p /data/cloudstack/{primary,secondary}

修改nfs服务参数

vim /etc/sysconfig/nfs (直接加载结尾也可以)
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
RQUOTAD_PORT=875
MOUNTD_PORT=892
STATD_PORT=662
STATD_OUTGOING_PORT=2020
RPCNFSDARGS="-N 4"

配置文件

vim /etc/exports
/data/cloudstack/primary *(rw,async,no_root_squash,no_subtree_check)
/data/cloudstack/secondary *(rw,async,no_root_squash,no_subtree_check)

设置nfs挂载配置文件

vim /etc/nfsmount.conf
Nfsvers=3

启动nfs和rpcbind

systemctl enable rpcbind
systemctl enable nfs-server
systemctl start rpcbind
systemctl start nfs-server

测试挂载

mount -t nfs 192.168.100.4:/data/cloudstack/primary /mnt
df -h         ###查看有了代表成功
umount /mnt

下载系统VM模板

/usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt -m /data/cloudstack/secondary -u http://cloudstack.apt-get.eu/systemvm/4.6/systemvm64template-4.6.0-kvm.qcow2.bz2 -h kvm -F 

安装agent(cloudstack主机,如果部署集群,备机只需要直接部署agent)

yum -y install cloudstack-agent

配置文件修改

vi /etc/libvirt/qemu.conf    并取消如下行的注释

vnc_listen=0.0.0.0

配置KVM

vi /etc/libvirt/libvirtd.conf
listen_tls = 0
listen_tcp = 1
tcp_port = "16059"
auth_tcp = "none"
mdns_adv = 0

vi /etc/sysconfig/libvirtd
LIBVIRTD_ARGS="--listen"

systemctl restart libvirtd
systemctl enable libvirtd

配置agent

vi /etc/cloudstack/agent/agent.properties
host=192.168.100.4

配置网卡(做桥接)

网卡1
vi /etc/sysconfig/network-scripts/ifcfg-em1 

###编辑第一块网卡 是什么就编辑什么 我这叫em1

TYPE=Ethernet
IPV6INIT=no   
DEVICE=em1
ONBOOT=yes
BRIDGE=cloudbr0
网卡桥接
vi /etc/sysconfig/network-scripts/ifcfg-cloudbr0

####名字也可以自定义,要和里边配置对应上
TYPE=Bridge
BOOTPROTO=static
DEVICE=cloudbr0
IPV6INIT=no
ONBOOT=yes
IPADDR=192.168.100.4
NETMASK=255.255.255.0
GATEWAY=192.168.110.1
DNS1=202.106.0.20###我写了个公网的

初始化cloudstack-agent

cloudstack-setup-agent    ##一路回车

systemctl restart cloudstack-agent
systemctl restart libvirtd

查看8080端口是否启动

netstat -tunlp|grep 8080

打开浏览器,我们进行下一步配置

http://192.168.100.4:8080/client/   账号admin 密码password

参考文献:
http://www.cnblogs.com/wsy1030/p/8430351.html