虚拟私有云
虚拟私有云是化为的网络配置入口
在配置其他服务之前,必须先配定义网络
创建虚拟私有云
区域:按照地理位置划分
同一区域内的主机可以互通,不可跨区域(北京区域和北京区域的可以通)
选择离自己比较近的区域,可以减少网络延时卡顿
创建安全组,相当于防火墙 在内网使用
购买云主机
使用自己创建的安全组 手动分配ip (暂不购买公网ip)
登录云主机 进行管理
购买弹性公网ip
绑定:
绑定弹性ip后,会发现有俩个ip,其中一个是弹性ip
用终端连接 ssh弹性ip
查看自己的公网弹性ip 直接ifconfig看的是私网ip
云主机架构
架构说明:
管理员远程跳板机,跳板机又是一个自定义的yum仓库,同时具有公网和私网ip,私网ip管理内网云主机服务器,弹性公网ip给管理员用来管理,可以连接外网,是一个控制主机。因为内网服务器不能上网,所以通过跳板机编写ansible剧本,对内网服务器集体操作。(华为云提供的官方yum有不足,所以跳板机需要自定义一个yum)
华为云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
# lftp ftp的客户端服务
# rsync 远程 命令
# psmisc 查看系统进程
优化系统服务
[root@ecs-proxy ~]# systemctl stop postfix atd tuned
[root@ecs-proxy ~]# yum remove -y postfix at audit tuned kexec-tools firewalld-*
[root@ecs-proxy ~]# vim /etc/cloud/cloud.cfg
# manage_etc_hosts: localhost 注释掉这一行
[root@ecs-proxy ~]# reboot
安装配置ansible管理主机
[root@ecs-proxy ~]# systemctl stop postfix atd tuned
[root@ecs-proxy ~]# yum remove -y postfix at audit tuned kexec-tools firewalld-*
[root@ecs-proxy ~]# vim /etc/cloud/cloud.cfg
# manage_etc_hosts: localhost 注释掉这一行
[root@ecs-proxy ~]# reboot
# postfix
# atd
# tuned
安装配置ansible管理主机
[root@ecs-proxy ~]# tar zxf ansible_centos7.tar.gz
[root@ecs-proxy ~]# yum install -y ansible_centos7/*.rpm
[root@ecs-proxy ~]# ssh-keygen -t rsa -b 2048 -N '' -f /root/.ssh/id_rsa
[root@ecs-proxy ~]# chmod 0400 /root/.ssh/id_rsa
[root@ecs-proxy ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub 模板主机IP
模板镜像配置
配置yum源,安装软件包
[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 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 ~]# vim /etc/cloud/cloud.cfg
# manage_etc_hosts: localhost 注释掉这一行
[root@ecs-host ~]# yum clean all
[root@ecs-host ~]# poweroff
关机以后把主机系统盘制作为模板
创建私有镜像
项目实战:
实验要求:购买3台云主机,部署 apache + php 的网站
云主机名称 | 云主机IP地址 | 云主机配置 |
---|---|---|
web-0001 | 192.168.1.11 | 1CPU,1G内存 |
web-0002 | 192.168.1.12 | 1CPU,1G内存 |
web-0003 | 192.168.1.13 | 1CPU,1G内存 |
ELB负载均衡
工作原理图
编写剧本自动部署
[root@ecs-proxy ~]# mkdir -p web-site
[root@ecs-proxy ~]# cd web-site
[root@ecs-proxy ~]# vim ansible.cfg
[defaults]
inventory = hostlist
host_key_checking = False
[root@ecs-proxy ~]# vim hostlist
[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
购买ELB 弹性负载均衡 (服务)
配置负载均衡
默认状态为异常,完成健康检查后变为正常。
测试: