谷歌云再搞一年免费试用的活动,有兴趣的朋友可以网上查询一下申请教程。这里仅对谷歌云使用中的常见问题做一个总结。

创建谷歌云 CE 实例

从以下功能位置进入谷歌云 CE 实例管理页面,按页面提示创建即可。

Google Cloud Platform > Compute Engine > VM 实例

设置静态 IP 和防火墙

设置静态 IP 地址

谷歌云 CE(Compute Engine) 实例默认外部 IP 地址是临时分配地址,需要设置为静态地址

设置方法很简单,在以下功能位置按提示设置即可。

Google Cloud Platform > VPC 网络 > 外部 IP 地址

设置防火墙规则

防火墙规则设置也在 VPC 网络 设置菜单下面,默认开启了常用规则。

Google Cloud Platform > VPC 网络 > 防火墙规则

设置 SSH 登录方式为密码登录

谷歌云 CE 默认不提供密码登录方式,为了使用方便需要更改为密码登录方式。

登录谷歌云 CE 实例

从以下功能位置进入谷歌云 CE 实例

Google Cloud Platform > Compute Engine > VM 实例

点击相应 CE 实例后面的SSH下拉选项,选择在浏览器窗口中打开

浏览器开新窗口自动完成 VM 实例登录。

修改 SSH 配置文件

1
2
3
4
5
# 切换到 root 用户
sudo -i

# 修改 ssh 配置文件
vim /etc/ssh/sshd_config

按以下说明修改代码:

1
2
3
4
5
# 允许 Root 用户远程登录
PermitRootLogin = yes

# 允许密码授权
PasswordAuthentication = yes

给 root 用户设置密码

1
passwd root

重启 SSH 服务使修改生效

1
2
# 以 CentOS 7 为例
systemctl restart sshd

现在可以再 xshell 中,直接使用 root 账号和密码登录。

配置 CentOS 7 第三方源

谷歌云默认 VM 实例安装的 CentOS 和阿里云、腾讯云不同,自带源缺少一些常用软件。因此需要配置第三方源。

下载第三方源

点击 这里 进入第三方源网站,选择下载适合自己的源。

我下载的是:EL 7: x86_64

安装第三方源

谷歌云默认实例没有 wget,因此需要将该文件上传到服务器手动安装。

使用 WinSCP 上传下载文件。

1
2
3
4
5
6
7
8
# 安装 rpm 包
rpm -ivh 包名

# 确认是否添加成功。该目录下是否新增了rpmforge.repo文件,如果有说明添加成功。
ls /etc/yum.repos.d/
CentOS-Base.bak.repo CentOS-Debuginfo.repo CentOS-Sources.repo epel-testing.repo mirrors-rpmforge-extras
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo google-cloud.repo mirrors-rpmforge-testing
CentOS-CR.repo CentOS-Media.repo epel.repo mirrors-rpmforge rpmforge.repo

安装 wget 测试源

现在可以安装 wget 了。

1
yum -y install wget

禁止 root 用户远程登录和修改 ssh 端口

为了系统安全,建议禁止 root 用户远程登录。

创建用户和密码

1
2
3
4
5
# 创建新用户
useradd aikiki

# 修改新用户密码
passwd aikiki

新用户创建成功后,建议注销系统后重新用新用户登录。以便测试新用户创建的正确性。

修改 sshd 配置文件

1
2
3
4
5
# 切换到 root 用户
su -

# 编辑 sshd 配置文件
vim /etc/ssh/sshd_config

修改以下配置:

1
2
3
4
5
# 关闭 Root 用户远程登录
PermitRootLogin false

# 将默认端口修改为任意端口(可以设置数字建议1000-60000,尽量的不要与其他项目冲突。)。
Port 22

建议不要修改 22 端口,而是使用防火墙限制 22 端口的可访问 IP 地址。如果是 CentOS 7 系统修改了 SSH 端口,还需要配置 SELinux 打开修改后的端口或是关闭 SELinux。

重启 sshd 服务

1
systemctl restart sshd

搭建服务器

一键搭建脚本:

1
wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/ssr.sh && chmod +x ssr.sh && bash ssr.sh

该安装脚本为中文提示信息,这里就不多做说明,只说明几个关键点:

  • 加密方式选择:10 aes-256-cfb
  • 协议插件选择:2 auth_shal-v4
  • 协议插件兼容原版选择:y
  • 混淆插件选择:1 plain

安装完成后会出现安装信息提示,需要设置到客户端。

附客户端一键安装:

1
2
3
4
5
6
7
8
9
10
11
12
13
# 该脚本会运行 git 命令,所以需提先安装 git。
sudo apt-get install git

# 下载和安装脚本
wget http://www.djangoz.com/ssr
sudo mv ssr /usr/local/bin
sudo chmod 766 /usr/local/bin/ssr

# 安装
ssr install

# 配置
ssr config

一键安装脚本 git 地址

编辑 rc.local 文件增加自启动命令:

1
sudo vim /etc/rc.local

在配置文件末尾增加启动命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
sudo ssr start
exit 0