Huawei Cloud Yunyao Cloud Server L Instance Evaluation | Yunyao Cloud Server L Instance Deployment SpaceInvaders Classic Mini Game

I. Introduction

Yunyao Cloud Server L instance is a new generation of lightweight application cloud server, specially designed for small and medium-sized enterprises and developers, providing a convenient out-of-box experience. This product provides rich and strictly screened application images and can deploy applications with one click, greatly simplifying the process of customers building e-commerce websites, web applications, applets, learning environments, and various development and testing tasks in the cloud.

Insert image description here

2. Introduction to SpaceInvaders mini-game

2.1 Introduction to SpaceInvaders mini-game

SpaceInvaders translates as Space Invaders. This small game is also a flight shooting game. It is simple and easy to use. It is deeply loved by players and has become one of the classic games.

2.2 SpaceInvaders mini-game play

The gameplay of the game is very simple. Players control a spaceship to move continuously on the screen and try to shoot the moving alien spacecraft. The alien spaceship moves along the top of the screen and continuously fires bullets at the player. The player needs to dodge these bullets and defeat all the spaceships as much as possible. The difficulty of the game will increase over time, the speed of the ship will become faster, and more enemies will appear. At the same time, large "BOSS" enemies will appear in the game from time to time, requiring players to spend more time and energy to defeat them.

3. Introduction to this practice

3.1 Introduction to this practice

1. This practice is a personal test learning environment, aiming to quickly deploy applications. Please be cautious in the production environment;
2. This practice environment is a Yunyao Cloud Server L instance, and the application image used is Portainer 2.18.4;
3. Due to the use The application image is Portainer, and the cloud server has automatically deployed the Docker environment;
4. Deploy the SpaceInvaders classic mini game on the Huawei Cloud Yaoyun Server L instance.

3.2 This environmental plan

Server category Application image Intranet IP address Docker version Portainer version
Yunyao cloud server L instance Docker visualization Portainer 192.168.0.168 24.0.4 2.18.4

4. Purchase an L instance of Yunyao Cloud Server

4.1 Purchase Yunyao Cloud Server L instance

  • Purchase steps:

1. Official website link: https://www.huaweicloud.com/product/hecs-light.html
2. Purchase specifications:
Region: North China-Beijing IV;
Application image: Docker visualization-Portainer;
Instance specifications: 2 cores 2G/system Disk 40G/peak bandwidth 3Mbps/traffic package 400G;
instance name: Customize it, edit it here as HECS-L-Portainer;
purchase duration: 1 month.

  • Just pay after selecting the specifications.

Insert image description here

4.2 Check the status of Yunyao Cloud Server L instance

  • Check the status of the purchased Huawei Cloud Yaoyun Server L instance. It is running normally after startup.

Insert image description here

4.3 Reset server password

  • Click to remotely log in to Yunyao Cloud Server L instance

Insert image description here

  • Enter the Huawei Cloud web version Shell tool CloudShell.

Insert image description here

  • Reset password: Click the reset password option on the right. Identity verification is required. After selecting mobile phone verification, the password can be reset successfully.

Insert image description here

Insert image description here

4.4 Xshell remote connection server

  • Copy the elastic public IP address of Yunyao Cloud Server L instance and use it when connecting to the server remotely.

Insert image description here

  • In the Xshell tool, fill in the server's elastic public IP address, account and password information, and connect to the remote server via ssh.

Insert image description here

Insert image description here

  • Successfully used the Xshell tool to connect to Huawei Cloud Yaoyun Server L instance.

Insert image description here

5. Check the server environment

5.1 Check operating system version

Check the operating system version of the Huawei Cloud Yaoyun Server L instance. The current version is 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 Display basic system information

Use the neofetch command to see basic system information.

neofetch

Insert image description here

5.3 Check the current system load situation

Use the top command in the Xshell command line terminal to check the system load of the current Yunyao Cloud Server L instance.

Insert image description here

Check the current system resource status on the monitoring page of Huawei Cloud Yaoyun Server L instance.

Insert image description here

6. Configure nginx service

6.1 Check the current nginx service

When the Yunyao Cloud Server L instance uses the Portainer application image, the nginx service is installed and started by default, and the portainer 9091 service is reverse-proxyed to the local port 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 View the default nginx configuration file

View the current default nginx configuration file

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  ---------------
}

Back up configuration files to prevent loss.

cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak

Modify the default.conf configuration file,

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;
    }
}

Check whether the nginx configuration file syntax is correct.

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 Restart nginx service

Restart the nginx service and check the nginx service status.

 systemctl restart nginx

Insert image description here

7. Deploy SpaceInvaders classic mini-game

7.1 Download SpaceInvaders source code

  • Go to the website root directory
cd /usr/share/nginx/html
  • Download SpaceInvaders source code
git clone https://github.com/StrykerKKD/SpaceInvaders.git
  • Github download is too slow, you can use code cloud to download.
git clone https://gitee.com/mirrors_strykerkkd/spaceinvaders.git

7.2 View source code

View the downloaded source code directory

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 Restart nginx service

Restart nginx service

systemctl restart nginx

7.4 Release security group ports

Enter the security group management page of Huawei Cloud Yaoyun Server L instance and allow the inbound security group port 7990.

Insert image description here
Insert image description here

8. Try the classic mini-game SpaceInvaders

Open the browser and visit the address: http://Elastic public IP address:7990/spaceinvaders

Insert image description here

  • Basic operations and game rules of mini games

1. The player controls the left and right movement of his small spacecraft through the left and right arrow keys on the keyboard;
2. The alien spacecraft will continuously fire bullets to attack the small spacecraft;
3. When the small spacecraft destroys the alien spacecraft, it will score points and destroy all alien spacecrafts. Will go to the next level;
4. The player needs to avoid the bullets from the alien spacecraft. When hit, the health value will be consumed. When the health value reaches 0, the game ends.

Insert image description here

9. Use experience and summary

This practice "Huawei Cloud Cloud Server L Instance Evaluation | Cloud Server L Instance Deployment SpaceInvaders Classic Game" was successfully completed. Huawei Cloud Yaoyun Server L instance has excellent performance and high cost performance, and the overall personal experience is good. You can choose different server configuration specifications, as well as different application images and system images according to your own needs. It is very flexible and is an excellent cloud server product!

Guess you like

Origin blog.csdn.net/jks212454/article/details/133032910