CentOS7和OpenStack的筆記(一)
最近搞CentOS7系統和OpenStack框架,整了近一個星期,系統裝了好幾次,框架搭了又從搭。雖然最后的實例沒能啟動成功,但是在這專研的一個星期里,也算是有了很多的心得體會,在此記下,方便以后查看。
一、CentOS7
1、主機名修改
hostnamectl set-hostname MyHostname
2、修改網卡名
在順利的條件下改網卡名很簡單:
在/etc/sysconfig/network-scripts/目錄下,查看是否有網卡接口文件,名字一般為ifcfg-eno16777736類似的文件。
編輯文件 vi ifcfg-eno16777736
將里面的DEVICE=eno16777736和NAME=eno16777736修改成
DEVICE=eth0
NAME=eth0
重啟即可改網卡名。如果不成功,網上很多教程。
3、防火牆和SELinux
關閉防火牆firewalld,CentOS7應該是不再使用iptables了,關閉firewall即可關閉防火牆
systemctl stop firewalld.service
systemctl disable firewalld.service
關閉SELinux
vim /etc/selinux/config 修改 SELINUX=disable 退出后使用命令即時生效 setenforce 0
4、系統鏡像DVD鏡像文件里有很多軟件,可以設置成yum源,即做成本地yum倉庫
vi /etc/yum.repos.d/local.repo [centos] name=centos baseurl=file:///opt/centos/ gpgcheck=0 enabled=1
5、安裝vsftp共享本地yum源
yum install vsftpd -y
vi /etc/vsftpd/vsftpd.service 在最后新增一行 anon_root=/opt 啟動vsftp並開機自啟 systemctl start vsftpd.service systemctl enable vsftpd.service
另一台機器使用ftp源
vi /etc/yum.repos.d/local.repo [centos] name=centos baseurl=ftp://192.168.100.10/centos/ gpgcheck=0 enabled=1
測試yum源
yum list
如果計算節點yum list出錯,檢查一下雙方節點是否能ping通,檢查防火牆和selinux是否關閉。
6、修改yum源為清華源,安裝EPEL 倉庫
使用清華源比較穩定,阿里源不是很好用,有些鏡像點不能訪問到,或者速度很慢。
網站: https://mirrors.tuna.tsinghua.edu.cn/help/centos/

刪除開始所有的yum源 rm -f /etc/yum.repos.d/* vim /etc/yum.repos.d/CentOS-Base.repo 將以下內容寫入 # CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-$releasever - Base baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus gpgcheck=1 enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
EPEL(Extra Packages for Enterprise Linux)是由Fedora Special Interest Group維護的Enterprise Linux(RHEL、CentOS)中經常用到的包。
這個倉庫的包非常多,是很棒的倉庫,原來在清華鏡像站上有國內源。
網站:https://mirrors.tuna.tsinghua.edu.cn/help/epel/

yum install epel-release -y vim /etc/yum.repos.d/epel.repo [epel] name=Extra Packages for Enterprise Linux 7 - $basearch baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch failovermethod=priority enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 [epel-debuginfo] name=Extra Packages for Enterprise Linux 7 - $basearch - Debug baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch failovermethod=priority enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 gpgcheck=1 [epel-source] name=Extra Packages for Enterprise Linux 7 - $basearch - Source baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch failovermethod=priority enabled=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 gpgcheck=1 yum makecache yum update
7、安裝常用軟件和工具
yum install -y net-tools vim lrzsz tree screen lsof tcpdump
8、更新系統並重啟
yum update -y && reboot
給虛擬機做快照
9、踢掉用戶
使用w命令可以看到在線的用戶
踢掉pts/1用戶
pkill -kill -t pts/1
10、ssh登錄很久都上不去
使用root權限修改ssh的配置文件 vim /etc/ssh/sshd_config 最后增加一行記錄: UseDNS no
二、OpenStack
1、虛擬機要記得開啟CPU虛擬化
2、可以設置兩塊網卡,也可以設置一塊網卡來啟動實例
兩塊網卡:一塊是連接公網使用,一塊是內部網絡使用
一塊網卡:一塊網卡,即是內部管理網絡,也是連接公網的網絡。
虛擬機網絡設置,如果是自己設置的IP地址,發現是上不了網。不清楚有什么辦法解決。如果是DHCP獲取的地址就可以正常上網。
3、內存大小設置
我這里是雙節點設置,即,controller節點和compute節點
controller節點比較重要,設置內存4G;建議內存不要太小,不然很吃力。
compute節點,設置內存2G;
4、時間同步
yum install ntpdate -yntpdate ntp.tuna.tsinghua.edu.cn
如果運行 ntpd 服務,一般來說 ntpd 會逐漸調整時鍾,避免時間跳變。
在 /etc/ntp.conf
中添加一行 server ntp.tuna.tsinghua.edu.cn
即可。
使用 ntpdate ntp.tuna.tsinghua.edu.cn
進行一次性的同步
5、數據庫MariaDB
yum install -y mariadb mariadb-server python2-PyMySQL cd /etc/my.cnf.d/ vim openstack.cnf [mysqld] bind-address = 192.168.137.11 # 監聽的IP地址(也可以寫0.0.0.0) default-storage-engine = innodb # 默認存儲引擎[innodb] innodb_file_per_table # 使用獨享表空間 max_connections = 4096 # 最大連接數是4096 (默認是1024) collation-server = utf8_general_ci # 數據庫默認校對規則 character-set-server = utf8 # 默認字符集 或者 vim /etc/my.cnf [mysqld] bind-address = 192.168.100.10 default-storage-engine = innodb innodb_file_per_table max_connections = 4096 collation-server = utf8_general_ci character-set-server = utf8
7、查看日志排錯
目錄:/var/log/nova/、/var/log/neutron/、/var/log/glance/、/var/log/keystone/
使用tail -20 /var/log/nova/nova-server.log可以看到ERROR字樣的就是錯誤信息。
8、PlacementNotConfigured: This compute is not configured to talk to the placement service的解決辦法

PlacementNotConfigured: This compute is not configured to talk to the placement service 原因:官方文檔中遺漏了-nova-placement-api的安裝 安裝步驟 1、先安裝openstack octca版本的yum源 yum install https://rdoproject.org/repos/rdo-release.rpm 2、控制節點 yum install openstack-nova-placement-api firewall-cmd --zone=public --add-port=8778/tcp --permanent firewall-cmd --reload systemctl restart httpd 3、計算節點 編輯 /etc/nova/nova.conf 增加 [placement] auth_uri = http://controller:5000 auth_url = http://controller:35357 memcached_servers = controller:11211 auth_type = password project_domain_name = default user_domain_name = default project_name = service username = nova password = ****** os_region_name = RegionOne 重啟 systemctl restart openstack-nova-compute.service
未完待續。。。
參考網址:
1、controllerha的博客 https://blog.csdn.net/controllerha/article/list/5
2、shhnwangjian https://www.cnblogs.com/shhnwangjian/category/942049.html