果粉派

如何使用 GCP(Google Cloud Platform)

2020-02-29  本文已影响0人  EchoZuo

用 Google GCP 搭建专属免费VPS

本文仅用于学习、记录、总结、分享云服务器自行搭建VPS的过程及方法。

简介

感谢谷歌提供的GCP服务(Google Cloud Platform,谷歌云平台服务),首次注册激活GCP,你会获享12个月试用期和$300 赠金,是不是免费?

请注意:教程很详细,图很多!


image.png

首先你需要准备:

开始搭建

1. 登录 Google Cloud Platform 激活账户填写相关信息

image.png

账户类型记得选个人

信用卡必须填写。填写之后点击开始免费使用。

谷歌声称“我们要求您提供信用卡信息是为了确认您不是机器人。除非您手动升级为付费帐号,否则我们不会向您收费。”具体信息可以参考:https://www.youtube.com/watch?v=kJHKsOywfxE

image.png image.png

2. 创建VM虚拟机实例

image.png image.png
- 填写 名称
- 选择 区域 及 地区(日本站点距离近,响应速度快)
- 调整一下 内核 及 内存,选择最低共享配置即可满足
- 更改 启动磁盘 为 Ubuntu 18.04 LTS
image.png
- 防火墙勾选 允许 HTTP 流量 允许 HTTPS 流量
- 点击 创建,创建完成如下图。
image.png

3. 设置防火墙规则

image.png image.png
- 名称 按规则自定义
- 目标 选择  网络中的所有实例
image.png
- 来源ip地址范围 0.0.0.0/0
- 协议和端口 勾选 UDP 填写 500,4500,勾选 其他协议 填写 esp
- 点击 创建,创建成功,如下图
image.png

4. 配置VPC网络

image.png
- 左侧菜单栏 ---> 网络 ---> VPC网络 ---> default
image.png
- 点击修改
image.png
- 子网创建模式 选择 自动
- 动态路由模式 选择 全局
- 点击保存即可

5. 设置 负载平衡

image.png image.png
- 名称 按规则自定义填写
- 选择 区域
- 选择第一步所创建的VM实例
- 点击前端配置
image.png
- 名称 按规则自定义填写
- 端口 填写500-4500
- 点击 完成 
- 点击 创建,创建完成如下
image.png

6. 登录服务器

image.png image.png

7. 开始部署服务

sudo apt-get update && apt-get dist-upgrade
控制台输出
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
zuoqianheng@instance-1:~$ sudo apt-get update && apt-get dist-upgrade
Hit:1 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]               
Get:3 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]             
Get:4 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [8570 kB]               
Get:5 http://archive.canonical.com/ubuntu bionic InRelease [10.2 kB]                                              
Get:6 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]                                       
Get:7 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic/universe Translation-en [4941 kB]
Get:8 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [151 kB]              
Get:9 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic/multiverse Translation-en [108 kB]        
Get:10 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [682 kB]           
Get:11 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-updates/main Translation-en [251 kB]      
Get:12 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [970 kB]       
Get:13 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-updates/universe Translation-en [293 kB]  
Get:14 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [6640 B]     
Get:15 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-updates/multiverse Translation-en [3556 B]
Get:16 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-backports/main amd64 Packages [2512 B]         
Get:17 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-backports/main Translation-en [1644 B]    
Get:18 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [3736 B]     
Get:19 http://asia-northeast1.gce.archive.ubuntu.com/ubuntu bionic-backports/universe Translation-en [1696 B]
Get:20 http://archive.canonical.com/ubuntu bionic/partner amd64 Packages [2320 B]                                 
Get:21 http://archive.canonical.com/ubuntu bionic/partner Translation-en [1276 B]
Get:22 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [450 kB]
Get:23 http://security.ubuntu.com/ubuntu bionic-security/main Translation-en [156 kB]
Get:24 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [570 kB]
Get:25 http://security.ubuntu.com/ubuntu bionic-security/universe Translation-en [185 kB]
Get:26 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [4008 B]
Get:27 http://security.ubuntu.com/ubuntu bionic-security/multiverse Translation-en [2060 B]
Fetched 17.6 MB in 4s (4193 kB/s)                     
Reading package lists... Done
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
zuoqianheng@instance-1:~$ 
wget https://git.io/vpnsetup -O vpnsetup.sh && sudo \
VPN_IPSEC_PSK='预分享密钥' \
VPN_USER='用户名' \
VPN_PASSWORD='密码' sh vpnsetup.sh
记得修改命令中的个人信息部分。
一个安全的 IPsec PSK 应该至少包含 20 个随机字符。
需要等待大概5-10分钟后,控制台输出
image.png

详细部署VPN服务教程可参考:IPsec VPN 服务器一键安装脚本

================================================
IPsec VPN server is now ready for use!
Connect to your new VPN with these details:
Server IP: 34.*******
IPsec PSK: ********************
Username: ******************
Password: ***************
Write these down. You'll need them to connect!
Important notes:   https://git.io/vpnnotes
Setup VPN clients: https://git.io/vpnclients
================================================
zuoqianheng@instance-1:~$ 

8. 如何连接?

Info

https://github.com/EchoZuo/Google-GCP-VPS

上一篇 下一篇

猜你喜欢

热点阅读