公有云平台管理
云平台部署管理架构图
通过跳板机管理云APP服务器
前置准备
- 购买云主机(华为云)
主机名 | 内网IP | 作用 |
---|---|---|
proxy | 192.168.1.252 | 跳板机 |
host | 192.168.1.251 | 模板机 |
web-0001 | 192.168.1.11 | web集群 |
web-0002 | 192.168.1.12 | web集群 |
web-0003 | 192.168.1.13 | web集群 |
elb-my | 192.168.1.250 | ELB 负载均衡 |
跳板机配置
#proxy
rm -rf /etc/yum.repos.d/*.repo #测试先不需要网络yum源 可以mv备份
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.myhuaweicloud.com/repo/CentOS-Base-7.repo #下载华为云内网yum源 华为云官网直接搜yum源配置教程即可
yum clean all
yum makecache #缓存网络yum源 方便快速查找
yum install -y net-tools lftp rsync psmisc vim-enhanced tree vsftpd bash-completion createrepo lrzsz iproute #安装常用工具
#配置ftp服务
mkdir /var/ftp/localrepo
cd /var/ftp/localrepo
createrepo . #配置自定义yum源
createrepo --update . # 更新
systemctl enable --now vsftpd #开机自启ftp服务
#优化系统服务
systemctl stop postfix atd tuned #关闭邮箱等不需要的功能
ss -tlun #查看启动的服务
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 *:68 *:* #DHCP服务
udp UNCONN 0 0 127.0.0.1:323 *:* #NTP服务
udp UNCONN 0 0 [::1]:323 [::]:* #NTP服务 同步时间
tcp LISTEN 0 128 *:22 *:* #ssh服务
tcp LISTEN 0 32 [::]:21 [::]:* #ftp服务
tcp LISTEN 0 128 [::]:22 [::]:* #ssh服务
yum remove -y postfix at audit tuned kexec-tools firewalld-* #删除不需要的工具
vim /etc/cloud/cloud.cfg #修改云服务器配置文件
# manage_etc_hosts: localhost 注释掉这一行
reboot #重启云服务器
#proxy安装ansible
tar -zxf ansible_centos7.tar.gz
yum install -y ansible_centos7/*.rpm #看找的资源
ssh-keygen -t rsa -b 2048 -N '' -f /root/.ssh/id_rsa #生成公私钥
chmod 0400 /root/.ssh/id_rsa #修改成所有者可读
ssh-copy-id -i /root/.ssh/id_rsa 192.168.1.251 #发送给模板机
# ansible是通过ssh来完成自动作业的 所以需要配置ssh密钥
模板镜像配置
rm -rf /etc/yum.repos.d/*.repo #同跳板机处理 私网yum源和系统优化
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.myhuaweicloud.com/repo/CentOS-Base-7.repo #下载华为云内网yum源 华为云官网直接搜yum源配置教程即可
yum clean all
yum makecache #缓存网络yum源 方便快速查找
yum install -y net-tools lftp rsync psmisc vim-enhanced tree vsftpd bash-completion createrepo lrzsz iproute #安装常用工具
#优化系统服务
systemctl stop postfix atd tuned #关闭邮箱等不需要的功能
yum remove -y postfix at audit tuned kexec-tools firewalld-* #删除不需要的工具
vim /etc/cloud/cloud.cfg #修改云服务器配置文件
# manage_etc_hosts: localhost 注释掉这一行
yum clean all
poweroff #关闭模板云服务器
华为云网页将host云主机做成镜像 生成镜像后可以删除了
购买三台云主机 使用上面模板机生成的镜像 使用镜像密码
配置web集群
#开始配置云主机服务
#proxy主机 ansible控制
mkdir -p web-site #创建工作目录
cd web-site
cp /etc/ansible/ansible.cfg .
vim ansible.cfg #修改配置文件
==========================================
inventory = hostlist #指定主机清单文件
host_key_checking = False #不检测ssh密钥
================================================
vim hostlist #配置主机清单文件
====================
[web]
192.168.1.[11:13] #web组有1.11~13三台云主机
===================================================
vim web_install.yml #写剧本完成配置
=======================
---
- 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
===============================
mkdir files #创建网站文件所需目录
#拷贝webhome.tar.gz到files目录下 可以自己写个网页
ansible-playbook web_install.yml #执行剧本
配置ELB(弹性负载均衡)
华为云购买ELB服务器 192.168.1.250 配置监听器 负载均衡算法 后台服务器组创建(将之前的1.11~13加入)
添加之后会异常 一分钟后刷新即可正常
访问web集群
#proxy
curl 192.168.1.250 #内网访问 因为没配置公网IP只能内网测试访问了~
#也可以买个公网IP绑定ELB 访问即可