公有云 — 華為云
云平臺部署管理架構圖
公有云配置
區域: 同一個區域中的云主機是可以互相連通的,不通區域云主機是不能使用內部網路互相通信的
選擇離自己比較近的區域,可以減少網路延時卡頓
華為云yum源配置 https://support.huaweicloud.com/ecs_faq/ecs_faq_1003.html
跳板機配置
配置yum源,安裝軟體包
[root@ecs-proxy ~]# rm -rf /etc/yum.repos.d/*.repo
[root@ecs-proxy ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.myhuaweicloud.com/repo/CentOS-Base-7.repo
[root@ecs-proxy ~]# yum clean all
[root@ecs-proxy ~]# yum makecache
[root@ecs-proxy ~]# yum install -y net-tools lftp rsync psmisc vim-enhanced tree vsftpd bash-completion createrepo lrzsz iproute
[root@ecs-proxy ~]# mkdir /var/ftp/localrepo
[root@ecs-proxy ~]# cd /var/ftp/localrepo
[root@ecs-proxy ~]# createrepo .
[root@ecs-proxy ~]# createrepo --update . # 更新
[root@ecs-proxy ~]# systemctl enable --now vsftpd
優化系統服務
[root@ecs-proxy ~]# systemctl stop postfix
[root@ecs-proxy ~]# yum remove -y postfix firewalld-*
[root@ecs-proxy ~]# yum install chrony
[root@ecs-proxy ~]# vim /etc/chrony.conf
# 注釋掉 server 開頭行,添加下面的配置
server ntp.myhuaweicloud.com minpoll 4 maxpoll 10 iburst
[root@ecs-proxy ~]# systemctl enable --now chronyd
[root@ecs-proxy ~]# chronyc sources -v
# 驗證配置結果 ^* 代表成功
[root@ecs-proxy ~]# vim /etc/cloud/cloud.cfg
# manage_etc_hosts: localhost 注釋掉這一行
[root@ecs-proxy ~]# reboot
安裝配置ansible管理主機
[root@ecs-proxy ~]# cp -a ansible_centos7 /var/ftp/localrepo/ansible
[root@ecs-proxy ~]# cd /var/ftp/localrepo
[root@ecs-proxy ~]# createrepo --update .
[root@ecs-proxy ~]# vim /etc/yum.repos.d/local.repo
[local_repo]
name=CentOS-$releasever – Localrepo
baseurl=ftp://192.168.1.252/localrepo
enabled=1
gpgcheck=0
[root@ecs-proxy ~]# yum makecache
[root@ecs-proxy ~]# yum install -y ansible
# 去華為云網頁下載秘鑰,并上傳秘鑰到跳板機
[root@ecs-proxy ~]# mv luck.pem /root/.ssh/id_rsa
[root@ecs-proxy ~]# chmod 0400 /root/.ssh/id_rsa
模板鏡像配置
購買云主機使用秘鑰認證
配置yum源,安裝軟體包
[root@ecs-host ~]# passwd root
[root@ecs-host ~]# rm -rf /etc/yum.repos.d/*.repo
[root@ecs-host ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.myhuaweicloud.com/repo/CentOS-Base-7.repo
[root@ecs-host ~]# vim /etc/yum.repos.d/local.repo
[local_repo]
name=CentOS-$releasever – Localrepo
baseurl=ftp://192.168.1.252/localrepo
enabled=1
gpgcheck=0
[root@ecs-host ~]# yum clean all
[root@ecs-host ~]# yum makecache
[root@ecs-host ~]# yum repolist
[root@ecs-host ~]# yum install -y net-tools lftp rsync psmisc vim-enhanced tree lrzsz bash-completion lrzsz iproute
優化系統服務
[root@ecs-host ~]# systemctl stop postfix atd tuned
[root@ecs-host ~]# yum remove -y postfix at audit tuned kexec-tools firewalld-*
[root@ecs-host ~]# yum install chrony
[root@ecs-host ~]# vim /etc/chrony.conf
# 注釋掉 server 開頭行,添加下面的配置
server ntp.myhuaweicloud.com minpoll 4 maxpoll 10 iburst
[root@ecs-host ~]# systemctl enable --now chronyd
[root@ecs-host ~]# chronyc sources -v
# 驗證配置結果 ^* 代表成功
[root@ecs-host ~]# vim /etc/cloud/cloud.cfg
# manage_etc_hosts: localhost 注釋掉這一行
[root@ecs-host ~]# yum clean all
[root@ecs-host ~]# poweroff
關機以后把主機系統盤制作為模板
網站云平臺部署實戰
網站架構圖
實驗要求:購買3臺 1CPU, 1G記憶體的云主機,部署 apache + php 的網站
? 192.168.1.11 web-0001
? 192.168.1.12 web-0002
? 192.168.1.13 web-0003
? 軟體素材在云盤的 public/web_install 目錄下
[root@ecs-proxy ~]# vim /etc/ansible/ansible.cfg
[defaults]
inventory = /etc/ansible/hosts
host_key_checking = False
[root@ecs-proxy ~]# vim /etc/ansible/hosts
[web]
192.168.1.[11:13]
[root@ecs-proxy ~]# vim web_install.yaml
---
- name: web 集群安裝
hosts: web
tasks:
- name: 安裝 apache 服務
yum:
name: httpd,php
state: latest
update_cache: yes
- name: 配置 httpd 服務
service:
name: httpd
state: started
enabled: yes
- name: 部署網站網頁
unarchive:
src: files/webhome.tar.gz
dest: /var/www/html/
copy: yes
owner: apache
group: apache
[root@ecs-proxy ~]# mkdir files
# 上傳 webhome.tar.gz 到 files 目錄下
[root@ecs-proxy ~]# ansible-playbook web_install.yaml
通過華為云負載均衡部署訪問,通過瀏覽器查看結果