被 OpenStack 的環境部署困擾很久之後,終於在 VirtualBox 的 CentOS 7 裡用 DevStack 裝好了 Mitaka 版本。踩到的坑大多集中在兩處:網絡問題(源在國外,下載超時)與軟件版本問題(軟件間相互依賴,某個 Python module 在 import 時報錯,因為新版本不再沿用舊的命名方式)。
網上教程多基於 Ubuntu 與 OpenStack L 版,個人更偏愛 CentOS,加上 M 版已經出來一段時間,於是動手試了一次,把流程記錄下來,希望它是可重複的。
用 VirtualBox 裝一台 CentOS 7 VM,內存 2GB,硬盤 100GB,鏡像為 CentOS-7-x86_64-Minimal-1511.iso。
為 VM 設置一張 NAT 網卡以便訪問公網;同時為了在 Windows 上用 Xshell 遠程連接,為這張網卡配置端口轉發:
[root@localhost ~]# vi /etc/selinux/config # SELINUX=enforcing SELINUX=disabled
[root@localhost ~]# yum -y install iptables-services [root@localhost ~]# systemctl disable iptables [root@localhost ~]# reboot
[root@localhost ~]# yum -y install epel-release git [root@localhost ~]# yum -y install net-tools
[root@localhost ~]# cd /home [root@localhost ~]# git clone https://git.trystack.cn/openstack-dev/devstack.git -b stable/mitaka
[root@localhost ~]# cd /home/devstack/tools/ [root@localhost ~]# bash ./create-stack-user.sh
[root@localhost ~]# chown -R stack:stack /home/devstack [root@localhost ~]# chmod 777 /opt/stack -R
[root@localhost ~]# su stack
[stack@localhost devstack]$ cd /home/devstack [stack@localhost devstack]$ vi local.conf
這裡採用最小化配置,並使用九州雲的 devstack 源加速下載,比國外源快了不止一星半點:
[[local|localrc]] # use TryStack git mirror GIT_BASE=https://git.trystack.cn NOVNC_REPO=https://git.trystack.cn/kanaka/noVNC.git SPICE_REPO=https://git.trystack.cn/git/spice/spice-html5.git # Define images to be automatically downloaded during the DevStack built process. DOWNLOAD_DEFAULT_IMAGES=False IMAGE_URLS="https://images.trystack.cn/cirros/cirros-0.3.4-x86_64-disk.img" # Credentials ADMIN_PASSWORD=admin DATABASE_PASSWORD=$ADMIN_PASSWORD RABBIT_PASSWORD=$ADMIN_PASSWORD SERVICE_PASSWORD=$ADMIN_PASSWORD
[stack@localhost devstack]$ git config --global url."https://".insteadOf git://
[stack@localhost devstack]$ ./stack.sh
注意必須用 stack 用戶運行。安裝成功後會看到類似輸出:
======================== DevStack Components Timed ======================== run_process - 87 secs pip_install - 1174 secs restart_apache_server - 14 secs wait_for_service - 48 secs yum_install - 757 secs git_timed - 947 secs This is your host IP address: 10.0.2.15 This is your host IPv6 address: ::1 Horizon is now available at https://10.0.2.15/dashboard Keystone is serving at https://10.0.2.15:5000/ The default users are: admin and demo The password: admin stack.sh completed in 4318 seconds.
某些網絡環境禁用 git 協議,會報 fatal: unable to connect to git.openstack.org。兩種解法:一是執行 git config --global url."https://".insteadOf git://;二是改配置文件,把 GIT_BASE=${GIT_BASE:-git://git.openstack.org} 改為 GIT_BASE=${GIT_BASE:-https://git.openstack.org}。
有教程說換 163 源更快,做法是先備份 /etc/yum.repos.d/CentOS-Base.repo,再下載 CentOS7-Base-163.repo,然後 yum clean all 與 yum makecache。但實踐中有一次安裝失敗就是因為換了 163 源,提示安裝包 broken,改回官方源後通過。遇到相同現象的朋友歡迎反饋具體錯誤。
反覆重裝多次、換了多套 local.conf 方案後,最後一次出現 mariadb root 密碼錯誤,大面積重裝前不妨先想想是不是密碼配置不一致。修改數據庫 root 密碼的方法網上很多,可再行嘗試。
Trystack 国内 OpenStack 源;English0523《再玩 DevStack(Mitaka 版)》;Yikun《搭建 OpenStack 開發環境》;陳沙克日志《OpenStack 項目系列介紹(3)Devstack》。