OpenCloudOS 8.8(云服务)搭建Git服务器Gitea

在这里插入图片描述

之前使用WindowsServerR12搭建的Gogs服务感觉用的有点卡,故打算换成Linux(OpenCloudOS 8.8)的Gitea,希望能够好用。

参考官方文档:https://docs.gitea.cn/installation/database-prep

1. 重装云服务

首先是使用腾讯云的控制台重装系统,选择推荐的OpenCloudOS,划到最下面点击确定,一分钟就能重装完成。重装完成后,可以通过终端工具MobaXterm登录。

MobaXterm下载:https://mobaxterm.mobatek.net/download-home-edition.html

在这里插入图片描述

2. 检查系统状态

然后是 检查下操作系统版本和发行版信息

[root@VM-16-11-opencloudos ~]# cat /etc/os-release
NAME="OpenCloudOS"
VERSION="8.8"

检查系统的内存使用情况

[lighthouse@VM-16-11-opencloudos ~]$ free -h
        total       used        free      shared     buff/cache   available
Mem:    1.7Gi       201Mi       818Mi     11Mi       701Mi        1.3Gi
Swap:   0B          0B          0B

检查磁盘空间的使用情况

[lighthouse@VM-16-11-opencloudos ~]$ df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        843M     0  843M   0% /dev
tmpfs           861M   24K  861M   1% /dev/shm
tmpfs           861M  9.5M  852M   2% /run
tmpfs           861M     0  861M   0% /sys/fs/cgroup
/dev/vda1        40G  3.6G   35G  10% /

检查没啥大问题后,开始准备数据库。

3. 安装数据库

由于机器配置较差(2核2G+存储40G),故还是采用小占用的SQLite。因为大多数Linux发行版都预装了SQLite,所以可以通过在终端命令sqlite3 -version来检查SQLite是否已安装以及安装的版本,若已安装则继续下一步,否则需百度安装下。

[lighthouse@VM-16-11-opencloudos ~]$ sqlite3 -version
3.26.0 2018-12-01 12:34:55 

4. 安装Git

同样是检查下是否已安装 Git(要求 Git 版本 >= 2.0),若未安装则使用sudo yum install git安装下。

[lighthouse@VM-16-11-opencloudos ~]$ git --version
git version 2.43.0

5. 安装Gitea

5.1 下载二进制文件

浏览器打开 https://dl.gitea.com/gitea/1.22.1/下载适用于 64-bit Linux 平台的二进制文件gitea-1.21.1-linux-amd64,然后上传到云机器,并使用chmod +x 命令增加执行权限。

[gitea@VM-16-11-opencloudos ~]$ ll
total 139484
-rwxr-x--x 1 gitea git 142829320 Jul  8 14:13 gitea-1.22.1-linux-amd64
[gitea@VM-16-11-opencloudos ~]$

5.2. 安装Gitea

(1)新建用户组git

[root@VM-16-11-opencloudos ~]# groupadd --system git

(2)新建用户git、gitea,并修改密码

[root@VM-16-11-opencloudos ~]# adduser \
>    --system \
>    --shell /bin/bash \
>    --comment 'Git Version Control' \
>    --gid git \
>    --home-dir /home/git \
>    --create-home \
>    git
...
[root@VM-16-11-opencloudos ~]# adduser \
>    --system \
>    --shell /bin/bash \
>    --gid git \
>    --home-dir /home/gitea \
>    --create-home \
>    gitea
...
[root@VM-16-11-opencloudos ~]# passwd git
...
[root@VM-16-11-opencloudos ~]# passwd gitea
...

(3)创建工作路径

[root@VM-16-11-opencloudos ~]# mkdir -p /var/lib/gitea/{custom,data,log}
[root@VM-16-11-opencloudos ~]# chown -R git:git /var/lib/gitea/
[root@VM-16-11-opencloudos ~]# chmod -R 750 /var/lib/gitea/
[root@VM-16-11-opencloudos ~]# mkdir /etc/gitea
[root@VM-16-11-opencloudos ~]# chown root:git /etc/gitea
[root@VM-16-11-opencloudos ~]# chmod 770 /etc/gitea

(4)配置 Gitea 工作路径

[root@VM-16-11-opencloudos ~]# export GITEA_WORK_DIR=/var/lib/gitea/
[root@VM-16-11-opencloudos ~]# env | grep git
GITEA_WORK_DIR=/var/lib/gitea/
[root@VM-16-11-opencloudos ~]#

(5)复制二进制文件到全局位置

[root@VM-16-11-opencloudos home]# cp gitea/gitea-1.22.1-linux-amd64 /usr/local/bin/gitea

6.运行Gitea

以 service 方式运行Gitea有两种方案,一种是systemd 方式,另一种是supervisor方式。

6.1 systemd 方式

(1)新建文件 gitea.service,写入后面的指定内容。

sudo vim /etc/systemd/system/gitea.service
[Unit]
Description=Gitea (Git with a cup of tea)
After=network.target
###
# Don't forget to add the database service dependencies
###
#
#Wants=mysql.service
#After=mysql.service
#
#Wants=mariadb.service
#After=mariadb.service
#
#Wants=postgresql.service
#After=postgresql.service
#
#Wants=memcached.service
#After=memcached.service
#
#Wants=redis.service
#After=redis.service
#
###
# If using socket activation for main http/s
###
#
#After=gitea.main.socket
#Requires=gitea.main.socket
#
###
# (You can also provide gitea an http fallback and/or ssh socket too)
#
# An example of /etc/systemd/system/gitea.main.socket
###
##
## [Unit]
## Description=Gitea Web Socket
## PartOf=gitea.service
##
## [Socket]
## Service=gitea.service
## ListenStream=<some_port>
## NoDelay=true
##
## [Install]
## WantedBy=sockets.target
##
###

[Service]
# Uncomment the next line if you have repos with lots of files and get a HTTP 500 error because of that
# LimitNOFILE=524288:524288
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
# If using Unix socket: tells systemd to create the /run/gitea folder, which will contain the gitea.sock file
# (manually creating /run/gitea doesn't work, because it would not persist across reboots)
#RuntimeDirectory=gitea
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
# If you install Git to directory prefix other than default PATH (which happens
# for example if you install other versions of Git side-to-side with
# distribution version), uncomment below line and add that prefix to PATH
# Don't forget to place git-lfs binary on the PATH below if you want to enable
# Git LFS support
#Environment=PATH=/path/to/git/bin:/bin:/sbin:/usr/bin:/usr/sbin
# If you want to bind Gitea to a port below 1024, uncomment
# the two values below, or use socket activation to pass Gitea its ports as above
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
###
# In some cases, when using CapabilityBoundingSet and AmbientCapabilities option, you may want to
# set the following value to false to allow capabilities to be applied on gitea process. The following
# value if set to true sandboxes gitea service and prevent any processes from running with privileges
# in the host user namespace.
###
#PrivateUsers=false
###

[Install]
WantedBy=multi-user.target

(2)激活 gitea 并启动服务

[root@VM-16-11-opencloudos system]# sudo systemctl enable gitea
[root@VM-16-11-opencloudos system]# sudo systemctl start gitea

(3)检查服务状态

[root@VM-16-11-opencloudos system]# sudo systemctl status gitea

6.2 supervisor方式

Supervisor是一个用Python语言编写的进程管理工具,它在Linux/Unix系统下运行,提供了进程监控、自动重启、日志管理等功能。
(1)安装

[root@VM-16-11-opencloudos system]# sudo yum install supervisor

(2)为 supervisor 配置日志路径

[git@VM-16-11-opencloudos ~]$ mkdir -p /home/git/gitea/log/supervisor

(3)编辑配置文件supervisord.conf,在末尾添加[program:gitea]的内容。

[root@VM-16-11-opencloudos system]# sudo vim /etc/supervisord.conf
[program:gitea]
directory=/home/git/gitea/
command=/home/git/gitea/gitea web
autostart=true
autorestart=true
startsecs=10
stdout_logfile=/var/log/gitea/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/var/log/gitea/stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
user = git
environment = HOME="/home/git", USER="git"

(4)新建文件supervisor.service,写入[Unit] [Service] [Install]的内容。

[root@VM-16-11-opencloudos system]# sudo nano /etc/systemd/system/supervisor.service
[Unit]  
Description=Supervisor process control system for UNIX  
After=network.target  
  
[Service]  
Type=forking  
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf  
ExecStop=/usr/bin/supervisorctl shutdown  
ExecReload=/usr/bin/supervisorctl shutdown && /usr/bin/supervisord -c /etc/supervisor/supervisord.conf  
KillMode=process  
Restart=on-failure  
RestartSec=5  
  
[Install]  
WantedBy=multi-user.target

(5)新建/var/log/gitea/stdout.log

mkdir -p /var/log/gitea
sudo vim stdout.log

(6)激活 supervisor 并启动服务

sudo systemctl enable supervisor
sudo systemctl start supervisor

(7)检查服务状态

[root@VM-16-11-opencloudos gitea]# sudo systemctl status supervisor

7.Gitea初始配置

gitea服务启动成功后,浏览器打开http://云机器公网IP:3000/既可进入Gitea初始配置页面。除了数据库类型选择SQLite3外,其余选项保持默认即可,然后点击立即安装。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
安装完成后,自动进入登录页面,第一个注册的用户即为管理员账号。
在这里插入图片描述
登录之后,就可以开始使用了。

在这里插入图片描述

8. pull/push测试

(1)使用管理员账户新建一个HelloWorld仓库
(2)修改本地global .gitconfig配置

[user]
	name = 刚刚注册的管理员名称
	email = 刚刚注册的管理员邮箱

(3)随便找个位置,pull下代码。
在这里插入图片描述
(4)pull成功后,放入一些新文件,Add后commit&push下,此时应该会自动弹出授权界面,点击“应用授权”。
在这里插入图片描述
(5)提交成功界面
在这里插入图片描述

  • 13
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

馍拉克斯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值