@[TOC](华为云云耀云服务器L实例评测|云耀云服务器L实例部署SpaceInvaders经典小游戏
一、前言
- 官网链接:华为云云耀云服务器L实例
- 云耀云服务器L实例简介
云耀云服务器L实例是新一代的轻量应用云服务器,专为中小企业和开发者设计,提供便捷的开箱即用体验。该产品提供丰富且经过严格筛选的应用镜像,可一键部署应用,极大程度简化了客户在云端构建电商网站、Web应用、小程序、学习环境以及各类开发测试等任务的过程。
二、SpaceInvaders小游戏介绍
2.1 SpaceInvaders小游戏简介
SpaceInvaders翻译为太空入侵者,这个小游戏也是一款飞行射击类游戏,操作简单易上手,深受玩家的喜爱,成为了经典的游戏之一。
2.2 SpaceInvaders小游戏玩法
游戏的玩法非常简单,玩家操控一艘飞船在屏幕上不断移动,并尝试射击移动的外星飞船。外星飞船沿着屏幕上方移动,并不断向玩家发射子弹,玩家需要躲避这些子弹并尽可能击败所有的飞船。游戏的难度会随着时间的推移而增加,飞船的速度会变得更快,也会有更多的敌人出现。同时,游戏还会不定期地出现大型的“BOSS”型敌人,需要玩家花费更多的时间和精力去击败。
三、本次实践介绍
3.1 本次实践简介
1.本次实践为个人测试学习环境,旨在快速部署应用,生产环境请谨慎;
2.本次实践环境为云耀云服务器L实例,使用的应用镜像为Portainer 2.18.4;
3.由于使用的应用镜像为Portainer,云服务器自动已部署好Docker环境;
4.在华为云云耀云服务器L实例上部署SpaceInvaders经典小游戏。
3.2 本次环境规划
服务器类别 | 应用镜像 | 内网IP地址 | Docker版本 | Portainer版本 |
---|---|---|---|---|
云耀云服务器L实例 | Docker可视化Portainer | 192.168.0.168 | 24.0.4 | 2.18.4 |
四、购买云耀云服务器L实例
4.1 购买云耀云服务器L实例
- 购买步骤:
1.官网链接:https://www.huaweicloud.com/product/hecs-light.html
2.购买规格:
区域:华北—北京四;
应用镜像:Docker可视化-Portainer;
实例规格:2核2G/系统盘40G/峰值带宽 3Mbps/流量包400G;
实例名称:自定义即可,这里编辑为HECS-L-Portainer;
购买时长:1个月。
- 选择好规格后付款即可。
4.2 查看云耀云服务器L实例状态
- 查看购买的华为云云耀云服务器L实例状态,启动后正常运行中。
4.3 重置服务器密码
- 点击远程登录云耀云服务器L实例
- 进入到华为云网页版Shell工具CloudShell中。
- 重置密码:点击右侧的重置密码选项,需要进行身份验证,选择手机验证后,即可重置密码成功。
4.4 Xshell远程连接服务器
- 复制云耀云服务器L实例的弹性公网IP地址,在远程连接服务器时使用。
- 在Xshell工具中,填写服务器弹性公网IP地址、账号密码信息,ssh连接远程服务器。
- 成功使用Xshell工具连接到华为云云耀云服务器L实例。
五、检查服务器环境
5.1 检查操作系统版本
检查华为云云耀云服务器L实例的操作系统版本,当前版本为Ubuntu 22.04.1 LTS。
root@hcss-ecs-f91c:~# cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
5.2 显示系统基本信息
使用neofetch命令,可以看到系统基本信息。
neofetch
5.3 查看当前系统负载情况
在Xshell命令行终端使用top命令,查看当前云耀云服务器L实例的系统负载情况。
在华为云云耀云服务器L实例的监控页面,查看当前系统资源状态。
六、配置nginx服务
6.1 检查当前nginx服务
当云耀云服务器L实例使用Portainer应用镜像时,默认已经安装并启动nginx服务,并将portainer的9091服务反向代理到本地的80端口。
root@hcss-ecs-f91c:~# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2023-09-18 19:44:47 CST; 20h ago
Docs: https://nginx.org/en/docs/
Main PID: 1006 (nginx)
Tasks: 3 (limit: 2006)
Memory: 45.2M
CPU: 81ms
CGroup: /system.slice/nginx.service
├─1006 "nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf"
├─1007 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
└─1008 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
Sep 18 19:44:46 websoft9-portainer-communitylatest-0722-ubuntu22 systemd[1]: Starting nginx - high performance web server...
Sep 18 19:44:47 websoft9-portainer-communitylatest-0722-ubuntu22 systemd[1]: nginx.service: Can't open PID file /run/nginx.pid (yet?) after start: Operation not permitted
Sep 18 19:44:47 websoft9-portainer-communitylatest-0722-ubuntu22 systemd[1]: Started nginx - high performance web server.
6.2 查看默认nginx配置文件
查看当前默认nginx配置文件
root@hcss-ecs-f91c:/usr/share/nginx/html# cat /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name example.yourdomain.com;
location / {
proxy_pass http://127.0.0.1:9091;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
#规则:禁用不必要的http方法:DELETE、PUT、TRACE、OPTIONS等
limit_except GET POST HEAD{
deny all;}
}
# 规则:使用安全的TLS协议
ssl_protocols TLSv1.2;
# 规则:禁止备份、敏感文件解析
location ~* \s(\.(svn|git|sql|bak|old|tar|gz|tgz|zip|7z|rar|DS_store)$){
deny all;
}
# 规则:防护nginx文件解析漏洞(CVE-2013-4547)
location ~* /((.*)\s+\\0\.php) {
deny all;}
# 规则:使用安全的加密套件
ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES256-SHA:HIGH:!MEDIUM:!LOW:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4:@STRENGTH';
ssl_prefer_server_ciphers on;
error_log /var/log/nginx/example.yourdomain.com-error.log error;
access_log /var/log/nginx/example.yourdomain.com-access.log;
include extra/*.conf;
#------------- SSL Start --------------
#------------- SSL End ---------------
}
备份配置文件,防止丢失。
cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
修改default.conf配置文件,
server {
listen 7990;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
检测nginx配置文件语法是否正确。
root@hcss-ecs-f91c:/usr/share/nginx/html# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
6.3 重启nginx服务
重启nginx服务,并查看nginx服务状态。
systemctl restart nginx
七、部署SpaceInvaders经典小游戏
7.1 下载SpaceInvaders源码
- 进入到网站根目录
cd /usr/share/nginx/html
- 下载SpaceInvaders源码
git clone https://github.com/StrykerKKD/SpaceInvaders.git
- github下载过慢,可以使用码云下载。
git clone https://gitee.com/mirrors_strykerkkd/spaceinvaders.git
7.2 查看源码
查看下载的源码目录
root@hcss-ecs-f91c:/usr/share/nginx/html# tree -L 2 ./spaceinvaders/
./spaceinvaders/
├── assets
│ ├── css
│ ├── img
│ └── javascript
├── index.html
├── indexOpt.html
├── LICENSE
└── README.md
4 directories, 4 files
7.3 重启nginx服务
重启nginx服务
systemctl restart nginx
7.4 放行安全组端口
进入华为云云耀云服务器L实例的安全组管理页面,放行入方向安全组端口7990。
八、试玩SpaceInvaders经典小游戏
打开浏览器,访问地址:http://弹性公网IP地址:7990/spaceinvaders
- 小游戏基本操作与游戏规则
1.玩家通过键盘左右方向键控制自己小飞船的左右移动;
2.外星飞船会不断的发射子弹攻击小飞船;
3.当小飞船摧毁外星飞船时,就会得分,消灭所有外星飞船将会到下一关;
4.玩家需要躲避外星飞船的子弹,当被击中时会消耗生命值,当生命值为0,游戏结束。
九、使用体验与总结
本次实践《华为云云耀云服务器L实例评测|云耀云服务器L实例部署SpaceInvaders经典小游戏》成功完成。华为云云耀云服务器L实例的性能表现优秀,性价比高,个人整体使用下来体验良好。可根据自身需要选择不同的服务器配置规格,以及不同的应用镜像和系统镜像,非常灵活,是一款出色的云服务器产品!