序 - 想在GCP免费额度下搭建Git服务器
你好,我是无能。
不知为何,我好久没登录GCP本身了?
看来我最后创建的项目是在2016年...

看来访问后会更新,所以My First Project感觉更早...
话说,现在是2024年,那就是8年前...我才15岁啊!!!!。
时光流逝真是残酷。
感觉有所成长,但也有退化的地方...不,退化也包含进化的意义。让我们积极一点吧。
题外话,周五吃了美味的饭菜后,就想懒洋洋地放松一下。



前言
我也有OCI账户,但最初注册时选错了区域,放置了半年多?偶尔去看,免费额度的资源总是用完了。
话说,不知为何周围只有我用不了...我大概是想着小众区域资源会多吧!结果注册后就顺利地'爆死'了。
工作上也会用到Google生态系统,所以借此机会我想在GCE上搭建一个Git服务器。
另外还有一个原因,我只是觉得把Git服务器放在家以外的地方,数据备份会更容易。关于网络,如果只是我自己用的话,应该不会收费,我之前没用GCP就是因为这个↓
Google Cloud Platform (GCP) 的免费额度包含1GB的出站网络流量。
这相当麻烦。或者说非常麻烦。但是,如果只是作为个人使用的Git服务器,似乎也没那么需要担心,所以我只是在脑子里模糊地想着,打算有空的时候再做。
想完全免费使用
这类收费服务每年都变得越来越难懂,所以应该随时关注那些更新完全免费知识的人。他们详细的解释真的很有帮助。
话说回来,感觉UI方面和以前也没太大变化,但更有可能只是我的记忆模糊了。
在GCP免费额度下创建VM实例
利用Google Cloud Platform(GCP)免费额度搭建服务器
快速创建用户
毕竟使用Google账户默认的用户名感觉不太舒服,所以我会切换到root用户,创建新用户并配置SSH访问。
root@git-srv1:~# adduser haturatu
Adding user `haturatu' ...
Adding new group `haturatu' (1002) ...
Adding new user `haturatu' (1002) with group `haturatu (1002)' ...
Creating home directory `/home/haturatu' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for haturatu
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]
Adding new user `haturatu' to supplemental / extra groups `users' ...
Adding user `haturatu' to group `users' ...
root@git-srv1:~# usermod -aG sudo haturatu
root@git-srv1:~# su - haturatu
haturatu@git-srv1:~$
SSH设置
haturatu@git-srv1:~$ vim .ssh/authorized_keys
haturatu@git-srv1:~$ chmod 600 .s
.ssh/ .sudo_as_admin_successful
haturatu@git-srv1:~$ chmod 600 .ssh/authorized_keys
haturatu@git-srv1:~$ chmod 700 .ssh
haturatu@git-srv1:~$
haturatu@git-srv1:~$ sudo service sshd restart
防火墙设置
haturatu@git-srv1:~$ sudo apt install ufw
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
ufw
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 168 kB of archives.
After this operation, 878 kB of additional disk space will be used.
Get:1 file:/etc/apt/mirrors/debian.list Mirrorlist [30 B]
Get:2 https://deb.debian.org/debian bookworm/main amd64 ufw all 0.36.2-1 [168 kB]
Fetched 168 kB in 0s (1133 kB/s)
Preconfiguring packages ...
Selecting previously unselected package ufw.
(Reading database ... 68496 files and directories currently installed.)
Preparing to unpack .../archives/ufw_0.36.2-1_all.deb ...
Unpacking ufw (0.36.2-1) ...
Setting up ufw (0.36.2-1) ...
Creating config file /etc/ufw/before.rules with new version
Creating config file /etc/ufw/before6.rules with new version
Creating config file /etc/ufw/after.rules with new version
Creating config file /etc/ufw/after6.rules with new version
Created symlink /etc/systemd/system/multi-user.target.wants/ufw.service → /lib/systemd/system/ufw.service.
Processing triggers for rsyslog (8.2302.0-1) ...
Processing triggers for man-db (2.11.2-2) ...
haturatu@git-srv1:~$ sudo ufw allow 22/tcp
Rules updated
Rules updated (v6)
haturatu@git-srv1:~$ sudo ufw reload
Firewall not enabled (skipping reload)
haturatu@git-srv1:~$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup
haturatu@git-srv1:~$ sudo ufw reload
Firewall reloaded
准备SSH
我已经通过vim .ssh/authorized_keys放入了密钥,接下来只需在客户端PC(我正在操作的笔记本电脑)上进行SSH连接即可。
alleycat:[haturatu]:~$ ssh -l haturatu gce-global-ip
The authenticity of host 'nyao-n' can't be established.
ED25519 key fingerprint is SHA256:nyannyan
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'nyannyan' (ED25519) to the list of known hosts.
Linux git-srv1 6.1.0-27-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.115-1 (2024-11-01) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
haturatu@git-srv1:~$ uname -a
Linux git-srv1 6.1.0-27-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.115-1 (2024-11-01) x86_64 GNU/Linux
很快就完成了!
嗯,贴着贴着就变长了,下篇继续。