自动化kolla-ansible部署centos7.9+openstack-train-超融合高可用架构
欢迎加QQ群:1026880196 进行交流学习
环境说明:
1. 满足一台电脑一个网卡的环境进行模拟测试,由于配置较低,这里只涉及常规测试,不做更深入开展。
2.如果你是物理机,可以准备2个物理网卡,一个作为管理网接口,一个作为浮动网接口(实例上外网的需要,这里需要交换机支持dhcp功能,可以自动获取ip地址)。
3.根据环境需要注意一下参数修改:
nova_compute_virt_type: "kvm"
vim /etc/kolla/config/nova/nova-compute.conf
[libvirt]
inject_password=true
cpu_mode=host-passthrough
virt_type =
kvm
1. PC台式电脑硬件配置
2. 虚拟软件配置
#虚拟机下载 VMware-workstation-full-16.1.0-17198959.exe 百度网盘: 链接:https://pan.baidu.com/s/1RlgNja260HZtRffN_vc9EA 提取码:2021
3. 节点信息 # 三台融合控制/计算/存储
node1 CPU:4核 内存:8GB 系统盘SSD 200GB*1 数据盘SSD 300GB*1 管理网:ens33 192.168.1.20/24 浮动网:ens34 dhcp ( BOOTPROTO=dhcp )
node2 CPU:4核 内存:8GB 系统盘SSD 200GB*1 数据盘SSD 300GB*1 管理网:ens33 192.168.1.21/24 浮动网:ens34 dhcp ( BOOTPROTO=dhcp )
node3 CPU:4核 内存:8GB 系统盘SSD 200GB*1 数据盘SSD 300GB*1 管理网:ens33 192.168.1.22/24 浮动网:ens34 dhcp ( BOOTPROTO=dhcp )
4. 系统安装配置 #镜像下载 https://mirrors.ustc.edu.cn/centos/7.9.2009/isos/x86_64/CentOS-7-x86_64-Minimal-2009.iso
1. 系统版本
CentOS-7-x86_64-Minimal-2009.iso(CentOS 7.9 64位)
2. 语言
英文=标准安装
3. 分区
/boot 1000M /swap 4096M 其余/
5. 网卡信息
6. 系统基本环境 #注意每个节点都要执行
1. 安装常用软件包
yum install gcc vim wget net-tools ntpdate git -y
2. 关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
firewall-cmd --state
3. 关闭selinux
sed -i '/^SELINUX=.*/c SELINUX=disabled' /etc/selinux/config
sed -i 's/^SELINUXTYPE=.*/SELINUXTYPE=disabled/g' /etc/selinux/config
grep --color=auto '^SELINUX' /etc/selinux/config
setenforce 0
4. 主机名:
echo "
192.168.1.20 node1
192.168.1.21 node2
192.168.1.22 node3
">>/etc/hosts
5. ssh免密验证 #只在node1下操作,其它节点不执行
ssh-keygen
ssh-copy-id root@node1
ssh-copy-id root@node2
ssh-copy-id root@node3
6. 修改ssh
sed -i 's/#ClientAliveInterval 0/ClientAliveInterval 60/g' /etc/ssh/sshd_config
sed -i 's/#ClientAliveCountMax 3/ClientAliveCountMax 60/g' /etc/ssh/sshd_config
systemctl daemon-reload && systemctl restart sshd && systemctl status sshd
7. 使用中国科技大学源
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.ustc.edu.cn/centos|g' \
-i.bak \
/etc/yum.repos.d/CentOS-Base.repo
8. 配置docker源
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo
9. 安装epel源
yum makecache
yum install -y epel-release
10. 使用清华pypi源
mkdir ~/.pip
cat > ~/.pip/pip.conf << EOF
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
EOF
11. 安装安装python-pip
yum install python-pip -y
pip install --upgrade "pip < 21.0"
pip install pbr
12. 重启系统
reboot
#注意每个节点都要执行
1. 安装chrony服务
yum -y install chrony
2. 配置chrony文件
cp /etc/chrony.conf{,.bak}
echo "
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server ntp6.aliyun.com iburst
stratumweight 0
driftfile /var/lib/chrony/drift
rtcsync
makestep 10 3
bindcmdaddress 127.0.0.1
bindcmdaddress ::1
keyfile /etc/chrony.keys
commandkey 1
generatecommandkey
noclientlog
logchange 0.5
logdir /var/log/chrony
">/etc/chrony.conf
3. 启动服务
systemctl enable chronyd && systemctl restart chronyd && systemctl status chronyd
4. chrony同步源
chronyc sources -v
ntpdate ntp1.aliyun.com
hwclock -w
5. 配置定时任务
crontab -e
0 */1 * * * ntpdate ntp1.aliyun.com > /dev/null 2>&1; /sbin/hwclock -w
0 */1 * * * ntpdate ntp2.aliyun.com > /dev/null 2>&1; /sbin/hwclock -w
8. 安装配置
# node1下操作
1. 安装依赖软件包
yum install python2-devel libffi-devel openssl-devel libselinux-python -y
yum remove docker docker-common docker-selinux docker-engine -y
yum install yum-utils device-mapper-persistent-data lvm2 -y
2. 安装ansible
yum install -y "ansible < 2.9.19"
3. 配置ansible.cfg文件
sed -i 's/#host_key_checking = False/host_key_checking = True/g' /etc/ansible/ansible.cfg
sed -i 's/#pipelining = False/pipelining = True/g' /etc/ansible/ansible.cfg
sed -i 's/#forks = 5/forks = 100/g' /etc/ansible/ansible.cfg
4. 安装 kolla-ansible
pip install kolla-ansible==9.3.1 --ignore-installed PyYAML
#报错解决
pip install --upgrade setuptools
如果还出错,就安装以下软件
pip install --upgrade pip
pip install
pbr==5.6.0
5. 安装docker-ce
yum install docker-ce-20.10.5 -y
6. kolla-ansible配置文件到当前环境
mkdir -p /etc/kolla
chown $USER:$USER /etc/kolla
cp -r /usr/share/kolla-ansible/etc_examples/kolla/* /etc/kolla
cp /usr/share/kolla-ansible/ansible/inventory/* .
7. 修改docker配置文件配置国内阿里云地址,docker推送地址
mkdir /etc/docker/
cat >> /etc/docker/daemon.json << EOF
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
]
}
EOF
8. 开启 Docker 的共享挂载功能
mkdir -p /etc/systemd/system/docker.service.d
cat >> /etc/systemd/system/docker.service.d/kolla.conf << EOF
[Service]
MountFlags=shared
EOF
9. 设置docker服务启动
systemctl daemon-reload && systemctl enable docker && systemctl restart docker&& systemctl status docker
9. 文件配置
#node1节点下操作
1. 配置清单
vim /root/multinode
修改如下:
[control]
node1
node2
node3
[network]
node1
node2
node3
[compute]
node1
node2
node3
[storage]
node1
node2
node3
[monitoring]
node1
node2
node3
[deployment]
node1
node2
node3
2. 配置globals.yml文件,开启需要的文件
vim /etc/kolla/globals.yml
修改如下:
kolla_base_distro: "centos"
kolla_install_type: "source"
openstack_release: "train"
node_custom_config: "/etc/kolla/config"
kolla_internal_vip_address: "192.168.1.19"
#docker_registry: "xxx123.zixuanyun.com:4000"
docker_namespace: "kolla"
network_interface: "ens33"
neutron_external_interface: "ens34"
neutron_plugin_agent: "openvswitch"
neutron_tenant_network_types: "vxlan,vlan,flat"
keepalived_virtual_router_id: "56"
openstack_logging_debug: "True"
enable_ceph: "yes"
enable_ceph_dashboard: "{{ enable_ceph | bool }}"
enable_chrony: "yes"
enable_cinder: "yes"
enable_cinder_backup: "yes"
enable_ceph_dashboard: "{{ enable_ceph | bool }}"
enable_heat: "no"
enable_neutron_dvr: "yes"
enable_neutron_agent_ha: "yes"
enable_neutron_provider_networks: "yes"
enable_nova_ssh: "yes"
glance_backend_ceph: "yes"
cinder_backend_ceph: "{{ enable_ceph }}"
cinder_backup_driver: "ceph"
nova_backend_ceph: "{{ enable_ceph }}"
nova_compute_virt_type: "qemu"
nova_console: "novnc"
3. 生成随机密码
kolla-genpwd
4. 修改界面登陆密码为123456
sed -i 's/^keystone_admin_password.*/keystone_admin_password: 123456/' /etc/kolla/passwords.yml
5. 准备后端存储# node1-3都需要执行
#格式化
mkfs.ext4 /dev/sdb
数据盘准备ceph的标签
parted /dev/sdb -s -- mklabel gpt mkpart KOLLA_CEPH_OSD_BOOTSTRAP_BS_FOO1 1 -1
6. 设置nova配置文件
mkdir /etc/kolla/config
mkdir /etc/kolla/config/nova
cat >> /etc/kolla/config/nova/nova-compute.conf << EOF
[libvirt]
virt_type = qemu
cpu_mode = none
EOF
7. 创建虚拟机界面禁止默认创建新卷.
mkdir /etc/kolla/config/horizon/
cat >> /etc/kolla/config/horizon/custom_local_settings << EOF
LAUNCH_INSTANCE_DEFAULTS = {'create_volume': False,}
EOF
8. 创建ceph.conf
cat >> /etc/kolla/config/ceph.conf << EOF
[global]
osd pool default size = 3
osd pool default min size = 2
mon_clock_drift_allowed = 2
osd_pool_default_pg_num = 8
osd_pool_default_pgp_num = 8
mon clock drift warn backoff = 30
EOF
10. 开始安装
#node1 上执行
1. 引导各节点依赖
kolla-ansible -i ./multinode bootstrap-servers
2. 检查
ansible -i multinode all -m ping
kolla-ansible -i ./multinode prechecks
3. 部署
kolla-ansible -i ./multinode deploy
4. 部署完成后生成rc文件
kolla-ansible -i ./multinode post-deploy
5. 拷贝admin-openrc.sh文件
cp /etc/kolla/admin-openrc.sh ./
chmod +x admin-openrc.sh
source admin-openrc.sh
6. 安装openstack 包
cd /etc/yum.repos.d/
yum install centos-release-openstack-train -y
yum makecache fast
yum install python-openstackclient -y
cd
7. 编辑初始化脚本
vim /usr/share/kolla-ansible/init-runonce
EXT_NET_CIDR=${EXT_NET_CIDR:-'192.168.1.0/24'}
EXT_NET_RANGE=${EXT_NET_RANGE:-'start=192.168.1.200,end=192.168.1.254'}
EXT_NET_GATEWAY=${EXT_NET_GATEWAY:-'192.168.1.1'}
8. 执行#这里需要执行pip install kolla-ansible==9.3.1 --ignore-installed PyYAML 不然报错依赖
pip install kolla-ansible==9.3.1 --ignore-installed PyYAML
sh /usr/share/kolla-ansible/init-runonce
10. 打开浏览器访问openstack-dashboard控制台
http://192.168.1.19/ admin 123456
11. 镜像上传
#node1上执行
1. 镜像下载
mkdir /root/qcow2
cd /root/qcow2
#百度云盘
链接:https://pan.baidu.com/s/1WK_VbWb-f9boOL2-QahIng
提取码:2021
#linux 默认22端口 root cloud5566@MM123
#windows 默认56221端口 administrator cloud5566@MM123
#其它镜像 需要开通会员才能上传大于4G的文件...........
2. 格式转换
yum -y install qemu-img
qemu-img convert CentOS7.8_x86_64bit.qcow2 CentOS7.8_x86_64bit.raw
3. 镜像上传
source /root/admin-openrc.sh
openstack image create "CentOS 7.8 64位" --file CentOS7.8_x86_64bit.raw --disk-format raw --container-format bare --property hw_qemu_guest_agent=yes --property os_type=linux --public
4. 查看镜像是否成功
openstack image list
12. 准备工作
1. 安全组全部放行
13. 创建实例测试
13. 后端ceph存储状态查看
docker exec -it ceph_mon ceph --version
docker exec -it ceph_mon ceph -s
docker exec -it ceph_mon ceph -w
docker exec -it ceph_mon ceph df
docker exec -it ceph_mon ceph osd tree
docker exec -it ceph_mon ceph osd perf
14. 卸载openstack集群环境
1.卸载openstack
kolla-ansible destroy -i /root/multinode --include-images --yes-i-really-really-mean-it
2.所有节点重启系统
reboot
3.所有节点硬盘格式化
dmsetup remove_all
mkfs.ext4 /dev/sdb
4.所有节点重新打ceph标签
parted /dev/sdb -s -- mklabel gpt mkpart KOLLA_CEPH_OSD_BOOTSTRAP_BS_FOO1 1 -1
15. 如果集群设备意外关机,导致数据库集群挂掉。
5. mariadb服务异常
### 解决办法
########## 停止所有mariadb容器 ##########
docker stop mariadb
########## 找到最后关闭的mariadb主机,如果不记得就随机选取一台或者根据/var/lib/docker/volumes/mariadb/_data/grastate.dat的seqno进行选取(越大优先级越高),然后修改其grastate.dat文件的safe_to_bootstrap参数 ##########
vim /var/lib/docker/volumes/mariadb/_data/grastate.dat
safe_to_bootstrap: 1
########## 修改mariadb容器启动命令后启动容器,查询日志保证mariadb服务正常启动 ##########
vim /etc/kolla/mariadb/config.json
"command": "/usr/bin/mysqld_safe --wsrep-new-cluster",
docker start mariadb
tail -200f /var/lib/docker/volumes/kolla_logs/_data/mariadb/mariadb.log
########## 启动其他节点的mariadb容器 ##########
docker start mariadb
tail -200f /var/lib/docker/volumes/kolla_logs/_data/mariadb/mariadb.log
########## 确保集群运行正常后,恢复最初修改的config.json(这样就保证集群中所有的mariadb容器都是平等的)##########
vim /etc/kolla/mariadb/config.json
"command": "/usr/bin/mysqld_safer",
tail -200f /var/lib/docker/volumes/kolla_logs/_data/mariadb/mariadb.log
如果一切正常 不需要关闭mariadb
docker stop mariadb
docker start mariadb
tail -200f /var/lib/docker/volumes/kolla_logs/_data/mariadb/mariadb.log
如果报错
每个节点都要删除以下2个文件
rm -rf /var/lib/docker/volumes/mariadb/_data/galera.cache
rm -rf /var/lib/docker/volumes/mariadb/_data/grastate.dat