CloudStack 雲計算平臺框架

前言

CloudStack 和OpenStack 同樣都是IaaS層 開源框架,能夠管理XenServer、ESXI、KVM、OVM等主流虛擬機,相對OpenStack比較簡單、穩定;html

 

 

2、Cloud Stack架構

Zone:至關於現實中的1個數據中心,它是CloudStack中最大的一個單元java

Pod(機櫃):1個Zone包含N個Pod node

Pod(集羣):1個Pod包含N個Clusterpython

Host(主機):1個Cluster包含N個Hostmysql

 

 

3、基於centos7安裝Cloud Stack4.8.0 

1.下載cloudstack4.8.0linux

Managementnginx

Commonweb

Agentsql

 

2.修改hostname 和 hosts文件數據庫

agent1
vim /etc/hostname
192.168.226.159 master1
vim /etc/hosts

檢查主機名是否修改爲功?

[root@master1 zhanggen]# hostname --fqdn
master1
hostname --fqdn

 

3.關閉Selinux和Firewalld

setenforce 0
systemctl stop firewalld.service
setenforce 0 && systemctl stop firewalld.service

 

4.安裝epel yum源

yum -y install epel*
yum -y install epel*

 

5.安裝 ntp服務 保證主從間時間同步 

 yum -y install ntp
yum -y install ntp

啓動ntpd服務

[root@master1 zhanggen]# chkconfig ntpd on
注意:正在將請求轉發到「systemctl enable ntpd.service」。
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@master1 zhanggen]# systemctl enable ntpd.service
[root@master1 zhanggen]# 
systemctl enable ntpd.service

 

6.安裝nfs服務

yum -y install nfs-utils
yum -y install nfs-utils

配置

/export/secondary *(rw,async,no_root_squash,no_subtree_check)
vim /etc/exports
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892
STATD_PORT=662
RQUOTAD_PORT=875
STATD_OUTGOING_PORT=2020
vim /etc/sysconfig/nfs

 

啓動nfs、rpcbind 服務

systemctl start nfs
systemctl start nfs
[root@master1 /]# systemctl start rpcbind
systemctl start rpcbind

 

7.master1主節點和 agent從節點掛載NFS

master1主節點

[root@master1 /]# echo "/dev/sdb /export/secondary ext4 defaults 0 0 " >> /etc/fstab 
[root@master1 /]# 
echo "/dev/sdb /export/secondary ext4 defaults 0 0 " >> /etc/fstab

 agent1從節點

[root@agent1 export]#  echo "/dev/sdb /export/primary ext4 defaults 0 0 " >> /etc/fstab 
[root@agent1 export]#  mount -a
[root@agent1 export]# df
文件系統          1K-塊    已用     可用 已用% 掛載點
/dev/sda3      18555904 5128464 13427440   28% /
devtmpfs        1435012       0  1435012    0% /dev
tmpfs           1449728     156  1449572    1% /dev/shm
tmpfs           1449728    9156  1440572    1% /run
tmpfs           1449728       0  1449728    0% /sys/fs/cgroup
/dev/sda1        303780  154916   148864   51% /boot
tmpfs            289948       8   289940    1% /run/user/1000
/dev/sdb       51474912   53272 48783816    1% /export/primary
[root@agent1 export]# 
echo "/dev/sdb /export/primary ext4 defaults 0 0 " >> /etc/fstab

檢查NFS是否掛載成功

[root@agent1 export]# showmount -e master1
Export list for master1:
/export/secondary *
[root@agent1 export]# 
showmount -e master1

 

8.master節點

CloudStack管理端安裝

 cloudstack-management-4.8.0-1.el7.centos.x86_64.rpm 和 cloudstack-common-4.8.0-1.el7.centos.x86_64.rpm

[root@master1 Desktop]# ls
cloudstack-common-4.8.0-1.el7.centos.x86_64.rpm
cloudstack-management-4.8.0-1.el7.centos.x86_64.rpm
[root@master1 Desktop]# yum install cloudstack-management-4.8.0-1.el7.centos.x86_64.rpm cloudstack-common-4.8.0-1.el7.centos.x86_64.rpm
yum install cloudstack-management-4.8.0-1.el7.centos.x86_64.rpm cloudstack-common-4.8.0-1.el7.centos.x86_64.rpm
yum install mariadb-server mariadb
 systemctl enable mariadb
mariadb 安裝
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
vim /etc/my.cnf
[root@master1 /]# mysqladmin -uroot password 123.com
[root@master1 /]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> delete from mysql.user where user='';
Query OK, 2 rows affected (0.00 sec)

MariaDB [(none)]> 
設置mysql密碼刪除空用戶
[root@master1 /]# mysql -uroot -p123.com -e "GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY '123.com'";
[root@master1 /]#
給root用戶受權

 

9.Agent 節點 安裝KVM代理

[root@agent1 Desktop]# yum -y install cloudstack-agent-4.8.0-1.el7.centos.x86_64.rpm cloudstack-common-4.8.0-1.el7.centos.x86_64.rpm
yum -y install cloudstack-agent-4.8.0-1.el7.centos.x86_64.rpm cloudstack-common-4.8.0-1.el7.centos.x86_64.rpm

 

10.Master節點初始化數據庫

[root@master1 Desktop]# rpm -qa | grep cloud
cloudstack-management-4.8.0-1.el7.centos.x86_64
cloudstack-common-4.8.0-1.el7.centos.x86_64
[root@master1 Desktop]# cloudstack-setup-databases cloud:123.com@localhost --deploy-as=root:123.com
Mysql user name:cloud                                                           [ OK ]
Mysql user password:******                                                      [ OK ]
Mysql server ip:localhost                                                       [ OK ]
Mysql server port:3306                                                          [ OK ]
Mysql root user name:root                                                       [ OK ]
Mysql root user password:******                                                 [ OK ]
Checking Cloud database files ...                                               [ OK ]
Checking local machine hostname ...                                             [ OK ]
Checking SELinux setup ...                                                      [ OK ]
Detected local IP address as 192.168.226.159, will use as cluster management server node IP[ OK ]
Preparing /etc/cloudstack/management/db.properties                              [ OK ]
Applying /usr/share/cloudstack-management/setup/create-database.sql             [ OK ]
Applying /usr/share/cloudstack-management/setup/create-schema.sql               [ OK ]
Applying /usr/share/cloudstack-management/setup/create-database-premium.sql     [ OK ]
Applying /usr/share/cloudstack-management/setup/create-schema-premium.sql       [ OK ]
Applying /usr/share/cloudstack-management/setup/server-setup.sql                [ OK ]
Applying /usr/share/cloudstack-management/setup/templates.sql                   [ OK ]
Processing encryption ...                                                       [ OK ]
Finalizing setup ...                                                            [ OK ]

CloudStack has successfully initialized database, you can check your database configuration in /etc/cloudstack/management/db.properties

[root@master1 Desktop]# mysql -uroot -p123.com
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cloud              |
| cloud_usage        |
| mysql              |
| performance_schema |
| test               |
+--------------------+
6 rows in set (0.04 sec)

MariaDB [(none)]> 
cloudstack-setup-databases cloud:123.com@localhost --deploy-as=root:123.com Mysql user name:cloud

 

11.啓動Master

[root@master1 management]# cloudstack-setup-management --tomcat7
Starting to configure CloudStack Management Server:
Configure Firewall ...        [OK]
Configure CloudStack Management Server ...[OK]
CloudStack Management Server setup is Done!
[root@master1 management]# systemctl status cloudstack-management.service
● cloudstack-management.service - CloudStack Management Server
   Loaded: loaded (/usr/lib/systemd/system/cloudstack-management.service; enabled; vendor preset: disabled)
   Active: active (running) since 三 2019-04-03 16:16:38 CST; 5s ago
 Main PID: 18268 (java)
   CGroup: /system.slice/cloudstack-management.service
           └─18268 /usr/lib/jvm/jre/bin/java -Djava.awt.headless=true -Dcom.sun.management.jmxremote=false -Xmx2g -XX:+HeapDumpOnOutOfMem...

4月 03 16:16:40 master1 server[18268]: Apr 03, 2019 4:16:40 PM org.apache.catalina.core.StandardEngine startInternal
4月 03 16:16:40 master1 server[18268]: INFO: Starting Servlet Engine: Apache Tomcat/7.0.76
4月 03 16:16:40 master1 server[18268]: Apr 03, 2019 4:16:40 PM org.apache.catalina.startup.HostConfig deployDirectory
4月 03 16:16:40 master1 server[18268]: INFO: Deploying web application directory /usr/share/cloudstack-management/webapps/client
4月 03 16:16:41 master1 server[18268]: Apr 03, 2019 4:16:41 PM org.apache.catalina.loader.WebappClassLoaderBase validateJarFile
4月 03 16:16:41 master1 server[18268]: INFO: validateJarFile(/usr/share/cloudstack-management/webapps/client/WEB-INF/lib/servlet-...t.class
4月 03 16:16:41 master1 server[18268]: Apr 03, 2019 4:16:41 PM org.apache.catalina.loader.WebappClassLoaderBase validateJarFile
4月 03 16:16:41 master1 server[18268]: INFO: validateJarFile(/usr/share/cloudstack-management/webapps/client/WEB-INF/lib/servlet-...t.class
4月 03 16:16:41 master1 server[18268]: Apr 03, 2019 4:16:41 PM org.apache.catalina.loader.WebappClassLoaderBase validateJarFile
4月 03 16:16:41 master1 server[18268]: INFO: validateJarFile(/usr/share/cloudstack-management/webapps/client/WEB-INF/lib/tomcat-e...t.class
Hint: Some lines were ellipsized, use -l to show in full.
[root@master1 management]# ss -tnl
State      Recv-Q Send-Q                         Local Address:Port                                        Peer Address:Port              
LISTEN     0      50                                         *:3306                                                   *:*                  
LISTEN     0      128                                        *:111                                                    *:*                  
LISTEN     0      5                              192.168.122.1:53                                                     *:*                  
LISTEN     0      128                                        *:662                                                    *:*                  
LISTEN     0      128                                        *:22                                                     *:*                  
LISTEN     0      128                                127.0.0.1:631                                                    *:*                  
LISTEN     0      100                                127.0.0.1:25                                                     *:*                  
LISTEN     0      128                                        *:892                                                    *:*                  
LISTEN     0      64                                         *:2049                                                   *:*                  
LISTEN     0      64                                         *:32803                                                  *:*                  
LISTEN     0      128                                       :::111                                                   :::*                  
LISTEN     0      100                                       :::20400                                                 :::*                  
LISTEN     0      128                                       :::8080                                                  :::*                  
LISTEN     0      128                                       :::662                                                   :::*                  
LISTEN     0      128                                       :::22                                                    :::*                  
LISTEN     0      50                                        :::42743                                                 :::*                  
LISTEN     0      128                                      ::1:631                                                   :::*                  
LISTEN     0      128                                       :::892                                                   :::*                  
LISTEN     0      64                                        :::2049                                                  :::*                  
LISTEN     0      64                                        :::32803    
cloudstack-setup-management --tomcat7

 

12.訪問

http://192.168.226.159:8080/client/

 默認user :admin 默認密碼:password

 

13.下載KVM模板

[root@master1 Desktop]# /usr/share/cloudstack-common/scripts/storage/secondary/cloud-install-sys-tmplt -m /export/secondary/ -f /home/zhanggen/Desktop/systemvm64template-4.6.0-ovm.raw.bz2 -h kvm -F
Uncompressing to /usr/share/cloudstack-common/scripts/storage/secondary/3a2c5a43-2dd0-4130-b225-535221756540.qcow2.tmp (type bz2)...could take a long time
Moving to /export/secondary/template/tmpl/1/3///3a2c5a43-2dd0-4130-b225-535221756540.qcow2...could take a while
Successfully installed system VM template /home/zhanggen/Desktop/systemvm64template-4.6.0-ovm.raw.bz2 to /export/secondary/template/tmpl/1/3/
[root@master1 Desktop]# cd /export/secondary/
lost+found/ template/   
[root@master1 Desktop]# cd /export/secondary/template/tmpl/1/3/
[root@master1 3]# ls
3a2c5a43-2dd0-4130-b225-535221756540.qcow2  template.properties
[root@master1 3]# 
加載kvm模板

 

14.Agent libvert配置文件

CloudStack也是經過libverd來管理kvm的全部要修改 agent節點配置文件

vnc_listen = "0.0.0.0"
vim /etc/libvirt/qemu.conf
listen_tls = 0
listen_tcp = 1
tcp_port = "16509"
auth_tcp = "none"
mdns_adv =0
vim /etc/libvirt/libvirtd.conf

 

4、配置CloudStack

查看管理節點日誌

tail -f /var/log/cloudstack/management/management-server.log

 查看Agent節點日誌

tail -f /var/log/cloudstack/agent/agent.log 

 

1.添加資源

 

 

 2.基本資源

 

3.設置DNS

 

 

 4.設置網卡名稱

 

4.設置網絡

注意網段不要包含master 和agent的IP,避免形成IP衝突

 

 

5.設置管理網絡 

就是管理虛擬機用得網絡,注意不要和上面的IP衝突

 

 6.設置集羣名稱

 

7.添加agent節點

設置agent節點

 

 

8.  設置主存儲

主存儲 就是Agent上的存儲路徑,經過網絡掛載到 Master 節點的NFS路徑

 

 

9.設置二級存儲

二級存儲就是 Master節點中 NFS路徑

 

 

10.添加資源成功

 

 

5、搭建網絡鏡像倉庫

搭建http服務器,用於管理ISO鏡像和虛擬機模板,經過url下載鏡像、模板

1.安裝Nginx

yum -y install nginx
systemctl start nginx
安裝Nginx

2.修改Nginx配置文件成爲文件目錄服務器

    access_log  /var/log/nginx/access.log  main;
    autoindex on;
    autoindex_exact_size on;
    autoindex_localtime on;
    sendfile            on;
/etc/nginx/nginx.conf

 

 3.開放secstrage.allow權限

 

4.重啓cloudstack-management.service

[root@master1 html]# systemctl restart cloudstack-management.service
[root@master1 html]# 

 

6、註冊ISO鏡像

1.組冊ISO

 

 

 

 

7、添加實例

 資源和鏡像全有了,也該添加虛擬機實例了

1.添加實例

 

 2.選擇經過ISO鏡像的方式建立虛擬機

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

8、python3調用CloudStack的API

import requests
import urllib,hmac,base64,hashlib

api_url='http://192.168.226.159:8080/client/api'
api_key='Y3-zVsLYyBjf1sJr73Eb_17BitmsErXrvc6oIJBQBVjaIn2SbOvapI7gTs5Lycw8DqbzWu3NyVu8urR6ldcMyQ'
security_key='JqNOR8WtSvSS7wdDRhmwQn1VU8HBc5LbgWIImdzpRsvojYLvS1ClIGgBe_t40j7BaOtSHU7cMEe803QvN6FcdQ'


def get_url(cmd): #獲取加密後的簽名+拼接URL
    arges={
    "apikey":api_key.lower(),
    "command":cmd.lower(),
    "response":"json"
    }
    sig_url=urllib.parse.urlencode(arges)
    hmac_byte=hmac.new(bytes(security_key,'utf-8'),bytes(sig_url,'utf-8'),hashlib.sha1 ).digest()
    base64_str=base64.b64encode(hmac_byte).strip()
    sig = urllib.parse.quote_plus(base64_str)

    full_url = api_url + '?' + 'command=' + cmd + '&apikey=' + api_key + '&response=json' + '&signature=' + sig
    return full_url

urI=get_url(cmd='listHosts')

print(requests.get(url=urI).json())
獲取主機

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

參考

相關文章
相關標籤/搜索