openstack-Ubuntu-18.04映象製作
阿新 • • 發佈:2020-07-14
映象製作
https://docs.openstack.org/image-guide/ubuntu-image.html #製作ubuntu映象參考
https://docs.openstack.org/image-guide/obtain-images.html #官方提供的映象(已安裝完作業系統及環境)
KVM伺服器所需操作
1、cd /usr/local/src #上傳ubuntu-18.04映象 2、qemu-img create -f qcow2 /var/lib/libvirt/images/ubuntu-1804.qcow2 10G #建立磁碟檔案 3、virt-install --virt-type kvm --name ubuntu-18.04 --ram 1024 --cdrom=/usr/local/src/ubuntu-18.04.3-server-amd64.iso --disk path=/var/lib/libvirt/images/ubuntu-1804.qcow2 --network bridge=br0 --graphics vnc,listen=0.0.0.0 --noautoconsole #建立虛擬機器 4、virt-manager #xshell開啟xll轉發後,可以檢視到虛擬機器 5、先按F6,再按ESC,輸入修改網絡卡名稱的核心引數,然後回車
6、不需要通過代理
7、不進行自動更新
8、安裝openssh服務,不安裝openssh則無法通過ssh協議連線虛擬機器
進入KVM建立的ubuntu的虛擬機器,進行相關初始化配置
1、sudo su - root 2、vim /etc/ssh/sshd_config PasswordAuthentication yes #開啟密碼認證 UseDNS no #禁止反向解析 PermitRootLogin yes #允許root遠端登入 3、systemctl restart sshd 4、將映象源換成阿里雲 5、apt update 6、apt install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev gcc iotop unzip zip -y #安裝基礎命令 7、apt install cloud-init -y #centos還需要再安裝一個包,ubuntu只安裝這一個包即可 #cloud init服務是安裝在虛擬機器中的,此服務會訪問openstack API,通過API從而拿到公鑰、例項型別、例項的元資料、當前虛擬機器的磁碟空間等,然後對虛擬機器進行相應調整,主要是對磁碟自動拉伸(只能增大,不會減小);不安裝此服務的話,openstack建立完的虛擬機器磁碟大小是固定的,即KVM建立虛擬機器時磁碟是多大,openstack建立後就是多大,不會增大磁碟空間,所以需要安裝此服務 8、vim /etc/cloud/cloud.cfg users: - root #使用root賬號對磁碟進行拉伸 disable_root: false #允許使用root cloud_init_modules: # - migrator # - seed_random # - bootcmd # - write-files - growpart #開啟磁碟空間拉伸,拉伸後需要進行磁碟空間重置 - resizefs #開啟磁碟空間重置 # - disk_setup #其餘模組都關閉;如果模組都開,會影響虛擬機器開機速度,開機時會載入很多模組 # - mounts # - set_hostname #此模組會把通過API獲取到的例項名稱設定為當前虛擬機器的主機名 # - update_hostname # - update_etc_hosts # - ca-certs # - rsyslog # - users-groups # - ssh #關閉ssh模組,否則cloud-init會為了安全考慮,修改sshd的配置檔案,禁止root使用者遠端ssh連線 cloud_config_modules: # - emit_upstart # - snap # - ssh-import-id # - locale # - set-passwords # - grub-dpkg # - apt-pipelining # - apt-configure # - ubuntu-advantage # - ntp # - timezone # - disable-ec2-metadata # - runcmd # - byobu cloud_final_modules: # - package-update-upgrade-install # - fan # - landscape # - lxd # - ubuntu-drivers # - puppet # - chef # - mcollective # - salt-minion # - rightscale_userdata # - scripts-vendor # - scripts-per-once # - scripts-per-boot # - scripts-per-instance # - scripts-user # - ssh-authkey-fingerprints # - keys-to-console # - phone-home # - final-message # - power-state-change 9、dpkg-reconfigure cloud-init #配置cloud init使用EC2 API作為資料來源讀取元資料,其餘的資料來源都關閉 10、把ansible的公鑰拷貝到虛擬機器中(映象) 11、systemctl disable cloud-init #開機不啟動cloud-init,否則openstack建立的虛擬機器在開機時會向openstack API獲取當前虛擬機器的元資料,進行磁碟拉伸,這樣會大大的影響虛擬機器的開機速度 12、poweroff #關閉虛擬機器
KVM伺服器把虛擬機器磁碟檔案拷貝到controller
1、cd /var/lib/libvirt/images/
2、scp ubuntu-1804.qcow2 172.31.7.102:/usr/local/src/
#將虛擬機器的磁碟檔案拷貝到controller節點上
controller及compute節點需要做的配置
1、vim /etc/neutron/plugins/ml2/linuxbridge_agent.ini [securitygroup] enable_security_group = flase #controller及node節點都需要關閉安全組,否則會影響cloud-init訪問openstack API 2、重啟neutron服務 3、檢視neutron日誌是否有報錯
controller節點建立映象
1、cd /usr/local/src
2、openstack image create "Ubuntu-18.04-template" --file ./ubuntu-1804.qcow2 --disk-format qcow2 --container-format bare --public
#指定建立的映象名稱及磁碟檔案路徑,映象可見性為公有
dashboard建立虛擬機器
1、dashboard基於上傳的ubuntu映象建立虛擬機器
2、通過ansible等批量部署工具連線到建立的虛擬機器
3、systemctl start cloud-init
#通過ansible連線到虛擬機器批量開啟cloud-init服務,進行磁碟拉伸(CPU、記憶體會自動拉伸,是不需要cloud-init服務的),cloud-init會把磁碟拉伸到建立虛擬機器時,指定的例項型別所設定的磁碟大小
4、df -TH #檢視磁碟是否拉伸
5、systemctl stop cloud-init #磁碟拉伸後關閉cloud-init服務