重磅圖文詳解:OpenNebula安裝和節(jié)點(diǎn)配置實(shí)戰(zhàn)
OpenNebula 4.10入門之安裝和節(jié)點(diǎn)配置
環(huán)境說明:
所有系統(tǒng)環(huán)境管理端和節(jié)點(diǎn)宿主機(jī)都采用CentOS 6.6 x86_64
服務(wù)器使用情況:
1. 控制節(jié)點(diǎn)和存儲節(jié)點(diǎn)使用同一臺服務(wù)器.
2. 計(jì)算節(jié)點(diǎn)分別使用兩臺服務(wù)器
系統(tǒng)約定:
cloud.webxury.com 192.168.15.100 (計(jì)算節(jié)點(diǎn))
cloud1.webxury.com 192.168.15.101 (計(jì)算節(jié)點(diǎn))
storage.webxury.com 192.168.15.200 (存儲和控制)
系統(tǒng)最小化安裝(略過),并且根據(jù)約定配置好IP地址,修改好計(jì)算機(jī)名,檢查系統(tǒng)時(shí)間是否正確,確保機(jī)器能和外界通信,并且將以上內(nèi)容添加到本地/etc/hosts文件內(nèi),確保域名解析正常,并且永久關(guān)閉SELINUX以及IPTABLES,并且重啟,方可進(jìn)行安裝部署.因?yàn)槭菧y試,所以暫時(shí)關(guān)閉,正式上線,需要添加需要權(quán)限以及防火墻的端口設(shè)定.
控制臺安裝篇
1. 為系統(tǒng)添加EPEL源,添加EPEL源的原因是因?yàn)橐鉀Q一些在安裝上的依賴
yum –y install epel-release
2. 為系統(tǒng)添加Opennebula官方源
- # vi /etc/yum.repos.d/opennebula.repo
- [opennebula]
- name=opennebula
- baseurl=http://downloads.opennebula.org/repo/4.10/CentOS/6/x86_64/
- enabled=1
- gpgcheck=0
3. 生成源緩存(個(gè)人習(xí)慣)
yum makecache
4. 安裝Opennebula控制臺.
1.)# yum –y install opennebula-server opennebula-sunstone
安裝完成之后創(chuàng)建如下用戶以及目錄文件:
- # grep oneadmin /etc/passwd
- oneadmin:x:9869:9869::/var/lib/one:/bin/bash
- # ls -ld /etc/one/ //OpenNebula相關(guān)配置文件所在目錄
- drwxr-x---. 11 root oneadmin 4096 Feb 2 11:35 /etc/one/
- #ls/etc/init.d/opennebula*
- /etc/init.d/opennebula
- /etc/init.d/opennebula-occi
- /etc/init.d/opennebula-sunstone
- # ls -ld /var/log/one/
- drwxr-x---. 2 oneadmin oneadmin 4096 Feb 2 01:13 /var/log/one/
2).安裝組件
- # /usr/share/one/install_gems
- lsb_release command not found. If you are using a RedHat based distribution install redhat-lsb Select your distribution or press enter to continue without installing dependencies.
- 0. CentOS/RedHat
- 1. Ubuntu/Debian
選擇相對應(yīng)的操作系統(tǒng),我們選擇0
5. 默認(rèn)OpenNebula數(shù)據(jù)存儲使用sqlite,如果需要使用MySQL,則需要做如下操作
1).安裝mysql數(shù)據(jù)庫
- yum –y install mysql mysql-server
- #service mysqld start
- #chkconfig mysqld on
并且設(shè)置MYSQL密碼(忽略)
2).創(chuàng)建數(shù)據(jù)庫
- $ mysql -u root -p
- Enter password:
- Welcome to the MySQL monitor. [...]
- mysql> GRANT ALL PRIVILEGES ON opennebula.* TO '用戶名' IDENTIFIED BY '密碼'; Query OK, 0 rows affected (0.00 sec)
3).設(shè)置隔離級別
mysql> SET GLOBAL TRANSACTION ISOLATION LEVEL READ COMMITTED;
6. 修改配置文件如下 [用戶、端口、密碼、庫名和實(shí)際情況對應(yīng)修改:
- # vi /etc/one/oned.conf
- … …
- #DB = [ backend = "sqlite" ] (記得把這行注銷)
- # Sample configuration for
- DB = [ backend = "mysql",
- server = "localhost",
- port = 0, (這里0的意思代表使用MYSQL默認(rèn)3306端口,所以不需要修改)
- user = "剛才設(shè)置的用戶名",
- passwd = "剛才設(shè)置的密碼",
- db_name = "opennebula" ]
- … …
7. 修改sunstone默認(rèn)監(jiān)聽IP:
vi /etc/one/sunstone-server.conf
找到 :host: 127.0.0.1
修改成 :host: 0.0.0.0
8.啟動(dòng)相關(guān)服務(wù)
- # service opennebula start
- # service opennebula-sunstone start
- #chkconfig opennebula on
- #chkconfig opennebula-sunstone on
8.添加NFS共享存儲目錄
- vi /etc/exports
- /var/lib/one/ *(rw,sync,no_subtree_check,root_squash)
啟動(dòng)服務(wù)
- # service rpcbind restart
- # service nfs restart
- # chkconfig nfs on
- # chkconfig rpcbind on
9.添加SSH公共KEY
- # su - oneadmin
- $ vi ~/.ssh/config
添加以下內(nèi)容
- Host *
- StrictHostKeyChecking no
- UserKnownHostsFile /dev/null
修改文件權(quán)限
- $ chmod 600 ~/.ssh/config
10.修改oneadmin密碼
- #su oneadmin
- $passwd oneadmin
注:測試過程中因?yàn)闇y試環(huán)境服務(wù)端時(shí)間不對,導(dǎo)致cookie被忽略,OpenNebula Sunstone選擇Keep me logged in一直登陸不上或者直接登陸很快退出,尋找原因花了很長時(shí)間,最后調(diào)整到正確時(shí)間,登陸顯示ok。
P.S: 時(shí)間是一個(gè)非常容易被我們忽略的問題,切記切記!
完成以上步驟之后,瀏覽器登陸 http://ip:9869 即可
#p#
節(jié)點(diǎn)安裝篇
系統(tǒng)約定:
cloud.webxury.com 192.168.15.100 (計(jì)算節(jié)點(diǎn))
cloud1.webxury.com 192.168.15.101 (計(jì)算節(jié)點(diǎn))
storage.webxury.com 192.168.15.200 (存儲和控制)
系統(tǒng)最小化安裝(略過),并且根據(jù)約定配置好IP地址,修改好計(jì)算機(jī)名,檢查系統(tǒng)時(shí)間是否正確,確保機(jī)器能和外界通信,并且將以上內(nèi)容添加到本地/etc/hosts文件內(nèi),確保域名解析正常,并且永久關(guān)閉SELINUX以及IPTABLES,并且重啟,方可進(jìn)行安裝部署.因?yàn)槭菧y試,所以暫時(shí)關(guān)閉,正式上線,需要添加需要權(quán)限以及防火墻的端口設(shè)定.
安裝篇
1.為系統(tǒng)添加EPEL源,添加EPEL源的原因是因?yàn)橐鉀Q一些在安裝上的依賴
yum –y install epel-release
2.為系統(tǒng)添加Opennebula官方源
- # vi /etc/yum.repos.d/opennebula.repo
- [opennebula]
- name=opennebula
- baseurl=http://downloads.opennebula.org/repo/4.10/CentOS/6/x86_64/
- enabled=1
- gpgcheck=0
3.生成源緩存(個(gè)人習(xí)慣)
yum makecache
4.安裝節(jié)點(diǎn)組件
yum –y install opennebula-node-kvm
啟動(dòng)相關(guān)服務(wù)
- # service messagebus start
- # service libvirtd start
- # chkconfig messagebus on
- # chkconfig libvirtd on
5.給系統(tǒng)網(wǎng)卡做橋接
首先先復(fù)制一份ifcfg-eth0的文件,重命名為ifcfg-br0
網(wǎng)卡路徑: /etc/sysconfig/network-scripts/ifcfg-eth0
拷貝一份eth0,并且重命名為br0
cd /etc/sysconfig/network-scripts/
cp ifcfg-eth0 ifcfg-br0
修改網(wǎng)卡文件eth0
- DEVICE=eth0
- BOOTPROTO=none
- NM_CONTROLLED=no
- ONBOOT=yes
- TYPE=Ethernet
- BRIDGE=br0
修改剛才拷貝的ifcfg-br0文件
- DEVICE=br0(記得修改網(wǎng)卡名稱,因?yàn)槭菑?fù)制過來的)
- TYPE=Bridge
- IPADDR=192.168.15.100
- NETMASK=255.255.255.0
- GATEWAY=192.168.15.1
- DNS1=8.8.8.8
- DNS2=8.8.4.4
- ONBOOT=yes
- BOOTPROTO=static
- NM_CONTROLLED=no
重啟網(wǎng)卡
- # service network restart
6. 掛載存儲的NFS共享目錄
編輯: /etc/fstab
添加以下內(nèi)容
192.168.15.200:/var/lib/one /var/lib/one/ nfs soft,intr,rsize=8192,wsize=8192,noauto
7. 修改oneadmin密碼
#passwd oneadmin
回到控制節(jié)點(diǎn)服務(wù)器,讓SSH無密碼登陸節(jié)點(diǎn)服務(wù)器,否則控制節(jié)點(diǎn)添加計(jì)算節(jié)點(diǎn)將會(huì)失敗
- [oneadmin@storage ~]# su oneadmin
- [oneadmin@storage ~]$ ssh-keygen
- Generating public/private rsa key pair.
- Enter file in which to save the key (/var/lib/one/.ssh/id_rsa):
- Enter passphrase (empty for no passphrase):
- Enter same passphrase again:
- Your identification has been saved in /var/lib/one/.ssh/id_rsa.
- Your public key has been saved in /var/lib/one/.ssh/id_rsa.pub.
- 一路回車直到結(jié)束
- [oneadmin@storage~]$ssh-copy-id -i /var/lib/one/.ssh/id_rsa.pub oneadmin@cloud.webxury.com
- oneadmin@cloud.webxury.com 's password:
- .ssh/authorized_keys
根據(jù)提示輸入密碼后,已經(jīng)成功登陸節(jié)點(diǎn)服務(wù)器,然后退出,嘗試再次從控制節(jié)點(diǎn)服務(wù)器,ssh進(jìn)入節(jié)點(diǎn)服務(wù)器,已經(jīng)是不需要密碼了,說明設(shè)置成功,然后退出,并且重啟服務(wù)器,服務(wù)器啟動(dòng)后,請檢查是否掛載成功.
注:掛載的時(shí)候我遇到一個(gè)問題,我把storage掛載到每一個(gè)節(jié)點(diǎn)下的/var/lib/one/目錄下,發(fā)現(xiàn)權(quán)限已經(jīng)改變,默認(rèn)權(quán)限所屬用戶組和用戶名都是oneadmin,但是掛在后發(fā)現(xiàn)用戶名密碼都是nobody,所以我們要修改/etc/idmapd.conf這個(gè)文件,把Nobody-User=XXX修改成oneadmin,Nobody-Group=XXX也同樣修改成oneadmin,并且重啟服務(wù),service rpcidmapd restart.
安裝教程基本完成,可以簡單做測試,現(xiàn)在我們打開UI界面.
#p#
現(xiàn)在我們開始創(chuàng)建集群.
現(xiàn)在我們開始添加節(jié)點(diǎn)服務(wù)器,記得將節(jié)點(diǎn)添加到集群選項(xiàng)里面,看操作.
節(jié)點(diǎn)添加完成,我們現(xiàn)在開始添加網(wǎng)絡(luò).請看操作.
網(wǎng)絡(luò)添加完成了,請記得把網(wǎng)絡(luò)添加到集群里面,否則會(huì)出現(xiàn)錯(cuò)誤.
#p#
最后,我們檢查集群,將存儲添加進(jìn)去,然后檢查一遍,是否全部正確.
現(xiàn)在看到集群里面,有2個(gè)計(jì)算節(jié)點(diǎn),一個(gè)虛擬網(wǎng)絡(luò),3個(gè)存儲.這個(gè)是正確的.
現(xiàn)在我們導(dǎo)入官方的一個(gè)模板和鏡像文件做測試.
經(jīng)過幾分鐘,已經(jīng)成功導(dǎo)入,導(dǎo)入的時(shí)間,是根據(jù)網(wǎng)絡(luò)而定,因?yàn)橐螺d回來,所以是需要時(shí)間的.
#p#
導(dǎo)入鏡像的時(shí)候,它配有一個(gè)模板文件,我們稍微拿來改動(dòng)一下就可以使用,下面看我操作.
接下來我們可以創(chuàng)建虛擬機(jī)來測試一下.
現(xiàn)在看見虛擬機(jī)可以運(yùn)行了.但是有一個(gè)地方需要注意和修改,不然虛擬機(jī)一直會(huì)停留在等待,而不會(huì)運(yùn)行.
用SSH 進(jìn)入控制臺的主機(jī),找到/etc/sched.conf這個(gè)文件,找到調(diào)度配置文件,以下請根據(jù)自己需求去修改.
- DEFAULT_SCHED: Definition of the default scheduling algorithm
- # - policy:
- # 0 = Packing. Heuristic that minimizes the number of hosts in use by
- # packing the VMs in the hosts to reduce VM fragmentation
- # 1 = Striping. Heuristic that tries to maximize resources available for
- # the VMs by spreading the VMs in the hosts
- # 2 = Load-aware. Heuristic that tries to maximize resources available for
- # the VMs by using those nodes with less load
- # 3 = Custom.
- # - rank: Custom arithmetic exprission to rank suitable hosts based in their
- # attributes
- # 4 = Fixed. Hosts will be ranked according to the PRIORITY attribute found
- # in the Host or Cluster template.
- #
- # DEFAULT_DS_SCHED: Definition of the default storage scheduling algorithm
- # - policy:
- # 0 = Packing. Tries to optimize storage usage by selecting the DS with
- # less free space
- # 1 = Striping. Tries to optimize I/O by distributing the VMs across
- # datastores.
- # 2 = Custom.
- # - rank: Custom arithmetic exprission to rank suitable datastores based on
- # their attributes
- # 3 = Fixed. Datastores will be ranked according to the PRIORITY attribute
- # found in the Datastore template.
- 這個(gè)是調(diào)度的說明,我用的是2和3的調(diào)度機(jī)制
- DEFAULT_SCHED = [
- policy = 2
- ]
- DEFAULT_DS_SCHED = [
- policy = 3
- ]
請根據(jù)自己需求去修改.
下面是修改高可用配置.實(shí)現(xiàn)其中一臺計(jì)算節(jié)點(diǎn)服務(wù)器宕機(jī)后,另外一個(gè)計(jì)算節(jié)點(diǎn)自動(dòng)接管
編輯/etc/one/oned.conf文件,找到
- HOST_HOOK = [
- name = "error",
- on = "ERROR",
- command = "ft/host_error.rb",
- arguments = "$ID -m -p 1",(原來這里的1是5,我改成了1,是因?yàn)闄z測時(shí)間為5分鐘,我改成了1分鐘,1分鐘后計(jì)算節(jié)點(diǎn)還在宕機(jī),另外一臺則自動(dòng)接管)
- remote = "no" ]
- VM_HOOK = [
- name = "advanced_hook",
- on = "CUSTOM",
- state = "ACTIVE",
- lcm_state = "BOOT_UNKNOWN",
- command = "log.rb",
- arguments = "$ID $PREV_STATE $PREV_LCM_STATE" ]
#p#
#號去掉,然后重啟服務(wù).
1分鐘后,另外一臺主機(jī)自動(dòng)接管了,虛擬機(jī)恢復(fù)正常,可以根據(jù)自己的需求來修改鉤子觸發(fā)的配置文件,來達(dá)到高可用目的.
本文轉(zhuǎn)自KVM虛擬化實(shí)踐微信公眾號,特此感謝。 |