自己搭建git server,从网上搜索似乎非常简单, 只需要简单的几步就能完成. 但这样的git server 只有最基本的功能, 没有PR, 没有Wiki, 没有web端, 不适合工程用.
经过一番搜索, 找到了gitea这个神器
Ubuntu安装 gitea
很简单,
- 首先确保安装了数据库, 我选择了mysql:
#更新源
sudo apt-get update
#安装, 安装过程中会询问root用户名和密码,自己设置即可
sudo apt-get install mysql-server
#启动
systemctl start mysql
#随系统启动
systemctl enable mysql
# 登陆mysql shell
/usr/bin/mysql -u root -p
# 建立gitea数据库, 注意, gitea数据库的charset必须是`utf8-geleral-ci`
CREATE DATABASE IF NOT EXISTS gitea DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
至此数据库安装完成
- 测试安装gitea, 先体验一下:
找到一个合适的位置,运行:
# 这是目前linux最新版本(1.6)的二进制文件
sudo wget -O gitea https://dl.gitea.io/gitea/1.6/gitea-1.6-linux-amd64
# 赋予权限
sudo chmod +x gitea
# 运行以下命令就可以开始测试了, 建议在一个测试文件夹中完成这个工作,因为我们毕竟是要注册成服务的
./gitea web
这时,打开http://localhost:3000
将会看到gitea的初始页面:
# 更新源
sudo apt-get update
# 安装git
sudo apt install git
# 添加git用户用来运行gitea
sudo adduser --system --shell /bin/bash --gecos 'Gitea user' --group --disabled-password --home /home/git git
# 建立所需的文件夹结构并赋予权限
sudo mkdir -p /home/git/gitea/{custom,data,indexers,public,log}
sudo chown git:git /home/git/gitea/{custom,data,indexers,public,log}
sudo chmod 750 /home/git/gitea/{custom,data,indexers,public,log}
sudo chown git:git /home/git/gitea
# 可以把测试时的安装包copy进来或者重新下载
cd /home/git/gitea
sudo wget -O gitea https://dl.gitea.io/gitea/1.6/gitea-1.6-linux-amd64
sudo chmod +x gitea
# 安装服务, github上又一个示范配置文件,我们先下载下来
cd /home/git/gitea
sudo wget https://raw.githubusercontent.com/go-gitea/gitea/master/contrib/systemd/gitea.service
sudo nano gitea.service
可看到以下内容:
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
#After=mysqld.service
#After=postgresql.service
#After=memcached.service
#After=redis.service
[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
# If you want to bind Gitea to a port below 1024 uncomment
# the two values below
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
对其中的重要内容进行修改:
Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
# 使用mysql
After=mysqld.service
#After=postgresql.service
#After=memcached.service
#After=redis.service
[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
# 取消大文件限制
LimitMEMLOCK=infinity
LimitNOFILE=65535
RestartSec=2s
Type=simple
User=git
Group=git
# 此处要改
WorkingDirectory=/home/git/gitea/
# 此处要改
ExecStart=/home/git/gitea/gitea web -c /home/git/gitea/custom/conf/app.ini
Restart=always
# 此处要改
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/home/git/gitea
# If you want to bind Gitea to a port below 1024 uncomment
# the two values below
###
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
Save (ctrl+o) and close (ctrl+x) the editor.
# 添加服务软连接
sudo ln -s /home/git/gitea/gitea.service /lib/systemd/system/gitea.service
sudo systemctl daemon-reload
# 启动并检查服务状态
sudo systemctl start gitea
sudo systemctl status gitea
# 如果服务没有启动, 查看日志文件
sudo journalctl -u gitea
# 添加开机启动
sudo systemctl enable gitea
sudo systemctl is-enabled gitea
这样就安装好了gitea
image.png- 一键安装(没试过,建议不要用)
https://git.coolaj86.com/coolaj86/gitea-installer.sh
网友评论