Day01-公有云使用指南-ori
公有云目标
- 熟练说出或识别出公有云服务名字
- 熟练说出和画出公有云网站架构
- 熟练使用公有云的产品比如:ecs,slb,rds,oss…
- 服务购买,续费操作
1. 回顾及课程内容
专业词汇 | |
---|---|
ecs | 云服务器 |
vpc | 虚拟专用网络 局域网 |
安全组 | 防火墙,白名单 |
实例 | 阿里云中任何一个产品或一个功能, 每个实例一般有一个独一无二的id |
1c1g 2c4g | 云服务器的配置 |
快照 | 类似于虚拟机的快照, 快照默认按量收费 (购买存储包 包年包月) |
镜像 | 创建镜像,需要创建快照---->镜像 , 镜像可以用来实现克隆的功能. 网站迁移功能 |
云盘 | 云服务器的磁盘 系统盘 数据盘 |
eip | 弹性公网ip, 主要可以给slb,ecs… |
按量负载(后付费) | |
包年包月(预付费) |
2. 案例01:创建ecs
名词 | |
---|---|
ecs | 云服务器 |
实例 | 一台设备/一个功能 |
释放 | 删除 |
2.1 付费模式
付费类型 | 说明 | 建议 |
---|---|---|
包年包月 | 工作必备 | |
按量付费 | 按小时计算 | 可以临时测试使用 |
抢占式 | 按小时计算 | 价格更加便宜,如果某个地区的云服务器数量不足,可能会被释放 0.1元/小时 价格随着需求变化 |
2.2 地域可用区
-
地域 region 不同的地区 北京 杭州
-
可用区:zone 可用区是同一个地域中的不同机房
地域 | ||
---|---|---|
地域 region | 不同的地区 北京(华北2) 杭州(华东1) | 不同地域,内网不通 |
可用区 zone | 可用区是同一个地域中的不同机房 | 同一个地域中的,不同可用区内网互通. |
2.3 实例规格和镜像
- 镜像
镜像 | |
---|---|
公共镜像 | 阿里云官方镜像(修改改) |
自定义镜像 | 用于克隆 |
共享镜像 | 自己创建的自定义镜像,可以共享给别人使用 |
2.4 存储
- 系统盘
- 数据盘
- 快照
2.5 vpc与安全组
-
vpc 虚拟局域网
-
虚拟交换机
2.5.1 vpc
-
VPC
-
交换机
- 整体网络架构
- 创建专有网络
- 专有网络创建成功
公网流量费用按实际使用流量收费,每小时扣费。仅单向收取 流出 流量费用,流入流量免费。例如您在 1 小时内公网流出流量为
6.51GB,收取费用为 6.51GB * 0.8 元 / GB = 5.20 元(注:不同地域“公网流量费用”的单价略有不同,实际价格请参照“当前配置”的
报价)
2.5.2 安全组
- 使用默认的,后期修改
2.6 完成创建
2.7 案例02:重置root密码
- 找到实例旁边的…
- 在线重置密码
- 离线重置密码
- 方法02:通过web页面vnc连接,重启linux,进入救援模式,进行操作…
案例03:更改实例的vpc配置
案例04:磁盘空间扩容与增加硬盘
- 磁盘不足,不能删除数据
- 扩容磁盘空间或增加硬盘
- 如果是数据盘可以选择扩容
- 如果是系统判断,增加硬盘挂载
- 下面是/data/分区导致空间不足,把/data/分区迁移到新硬盘的流程
#!/bin/bash
set -eu
# 1. 安装growpart工具
type growpart || yum install -y cloud-utils-growpart
#
# 2. 扩容分区:运行命令 growpart /dev/vda 1
LC_ALL=en_US.UTF-8 growpart /dev/vda 1
# 扩容文件系统:您当前的文件系统为ext4,因此运行resize2fs命令
resize2fs /dev/vda1
- 挂载硬盘
[root@iZbp1g4vdpcsajzxgdnr4dZ ~]# mkfs.ext4 /dev/vdb
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2621440 inodes, 10485760 blocks
524288 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2157969408
320 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@iZbp1g4vdpcsajzxgdnr4dZ ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs 1.8G 432K 1.8G 1% /run
tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
/dev/vda1 45G 2.3G 40G 6% /
tmpfs 365M 0 365M 0% /run/user/0
[root@iZbp1g4vdpcsajzxgdnr4dZ ~]# mkdir -p /data
[root@iZbp1g4vdpcsajzxgdnr4dZ ~]# mount /dev/vdb /data/
[root@iZbp1g4vdpcsajzxgdnr4dZ ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs 1.8G 432K 1.8G 1% /run
tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
/dev/vda1 45G 2.3G 40G 6% /
tmpfs 365M 0 365M 0% /run/user/0
/dev/vdb 40G 49M 38G 1% /data
案例05:创建快照与镜像
3. 阿里云-数据库-rds
- 创建rds
- 添加用户(数据库管理员用户)
- 添加数据库
- 添加数据使用的普通用户
- 申请rds,内网地址,设置白名单
- linux命令行或代码访问rds
案例06:部署kodbox项目
yum install -y nginx
yum install -y epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache php72w-pecl-memcached php72w-pecl-redis php72w-pecl-mongodb
sed -i 's#apache#nginx#g' /etc/php-fpm.d/www.conf
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location ~* \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
[root@iZbp1g4vdpcsajzxgdnr4dZ ~]# systemctl enable nginx.service php-fpm.service
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[root@iZbp1g4vdpcsajzxgdnr4dZ ~]# systemctl start nginx.service php-fpm.service
[root@iZbp1g4vdpcsajzxgdnr4dZ ~]# curl ifconfig.io
116.62.20.244
wget https://static.kodcloud.com/update/download/kodbox.1.37.zip
[root@iZbp1g4vdpcsajzxgdnr4dZ ~]# cat /etc/nginx/nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
index index.php;
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location ~* \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2;
# listen [::]:443 ssl http2;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
[root@iZbp1g4vdpcsajzxgdnr4dZ ~]# chown -R nginx.nginx /usr/share/nginx/html/
[root@iZbp1g4vdpcsajzxgdnr4dZ ~]#
4. 阿里云-nas/oss
4.0 概述
-
块存储:磁盘,云盘
-
文件存储:nfs存储,samba存储,nas存储
-
对象存储:自带数据高可用.ceph(开源软件),阿里云oss
4.1 nas文件存储
- 创建
- 挂载nfs
[root@iZbp1g4vdpcsajzxgdnr4dZ ~]# mount -t nfs 0ec4e490b1-mav53.cn-hangzhou.nas.aliyuncs.com:/ /mnt/
[root@iZbp1g4vdpcsajzxgdnr4dZ ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs 1.8G 444K 1.8G 1% /run
tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
/dev/vda1 45G 2.8G 40G 7% /
tmpfs 365M 0 365M 0% /run/user/0
0ec4e490b1-mav53.cn-hangzhou.nas.aliyuncs.com:/ 10P 0 10P 0% /mnt
[root@iZbp1g4vdpcsajzxgdnr4dZ ~]# rpm -qa|grep nfs
libnfsidmap-0.25-19.el7.x86_64
nfs-utils-1.3.0-0.68.el7.2.x86_64
- 移除挂载点
4.3 OSS
-
对象存储 程序代码掉用oss,读写,存储桶.
-
网盘操作(web页面操作)
-
oss术语
-
bucket oss存储空间,可以创建多个 每个bucket有自己的名字
-
bucket oss名称独一无二
-
Endpoint 访问地址
-
存储类型 标准/低频/归档
-
读写权限 私有(通过配置access id 和key)
5. RAM访问控制
5.1 概述
-
子账号
-
运维(web页面)/开发使用 (accesskey id 和 accesskey secret)
5.2 授权
ram用户访问方式 | |
---|---|
控制台访问 | web页面(运维使用) |
编程访问 | 程序代码中,使用某个功能(开发的代码调用) |
5.3 小结
- 访问控制
- 运维/运营- ram账号 子账号
- 开发:程序代码中使用 accesskey id 和secret
案例07:kodbox-连接oss存储
-
需要准备的内容:
- 创建oss对象存储 bucket存储桶. 存储桶的名字
- 存储桶的域名和endpoint.
- ram ak id和ak secret
- ram用户授权管理oss存储.
-
kodbox后台管理配置kodbox连接oss存储.
-
创建oss对象存储 bucket存储桶. 存储桶的名字
- 存储桶的域名和endpoint.
- kodbox上传文件测试
- oss中检查
今日总结
-
ecs使用,连接,重置密码,更改vpc,续费,快照,镜像.
-
rds会创建即可,添加用户,创建库.
-
nas了解即可,类似于nfs.
-
oss创建bucket,创建ram用户. ak
-
完成ecs+rds+oss kodbox
-
用公有云部署bbs-go代码,连接rds数据库.存储略