Linux 轻量级Git服务Gogs 发表于 2022-01-11 浏览量 541 没有评论 # 简介 Gogs 是一款极易搭建的自助 Git 服务。 [官网地址](https://dl.gogs.io/) # 安装 ``` #gogs需要用到数据库,这里先安装数据库 yum install mariadb mariadb-server -y systemctl enable mariadb systemctl restart mariadb mysql_secure_installation //初始化数据库 #登录到数据库 mysql -p123.com -a create database gogs character set utf8 collate utf8_bin; //创建数据库 grant all privileges on gogs.* to 'gogs'@'127.0.0.1' identified by '123.com'; //创建用户并授权 flush privileges; //刷新权限 [root@test3 data]# mysql -ugogs -p123.com -h127.0.0.1 -A //测试登录 # 安装git,并创建用户 yum install git -y; useradd git -s /sbin/nologin # 解压gogs安装包 tar xzvf gogs_0.11.86_linux_amd64.tar.gz -C /usr/local/ #启动(默认前台启动)监听3000端口。 /usr/local/gogs/gogs web 2021/06/04 02:31:36 [ INFO] Cache Service Enabled 2021/06/04 02:31:36 [ INFO] Session Service Enabled 2021/06/04 02:31:36 [ INFO] SQLite3 Supported 2021/06/04 02:31:36 [ INFO] Run Mode: Development 2021/06/04 02:31:36 [ INFO] Listen: http://0.0.0.0:3000 # 登录网页根据提示填写具体信息 ``` # 关闭注册 ``` vim /usr/local/gogs/custom/conf/app.ini [service] DISABLE_REGISTRATION = true //修改此处 ``` # systemctl管理gogs ``` vim /usr/local/gogs/start.sh #!/bin/sh /usr/local/gogs/gogs web >/tmp/gogs.log 2>&1 # 添加权限 chmod +x /usr/local/gogs/start.sh # 添加systemctl文件 vim /usr/lib/systemd/system/gogs.service [Unit] Description=gogs After=network.target [Service] Type=simple ExecStart=/usr/local/gogs/start.sh User=root [Install] WantedBy=multi-user.target # 启动并验证 systemctl start gogs netstat -ntpl | grep 3000 tcp6 0 0 :::3000 :::* LISTEN 18018/gogs ``` # 简单使用 ``` [root@test3 shell]# vim ouge.sh echo "ouge666" [root@test3 shell]# git add * //添加到本地 [root@test3 shell]# git commit -m "1" //提交 [master(根提交) 7b4d49f] 1 1 file changed, 1 insertion(+) create mode 100644 ouge.sh [root@test3 shell]# git remote add origin http://172.16.7.203:3000/ouge/devops.git [root@test3 shell]# git push -u origin master //推送至Git仓库 Username for 'http://172.16.7.203:3000': ouge Password for 'http://ouge@172.16.7.203:3000': Counting objects: 3, done. Writing objects: 100% (3/3), 213 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To http://172.16.7.203:3000/ouge/devops.git * [new branch] master -> master 分支 master 设置为跟踪来自 origin 的远程分支 master。 ``` # 保存用户密码 ``` vim .git/config [remote "origin"] url = http://ouge:123.com@172.16.7.203:3000/ouge/devops.git //此处加入你的用户名跟密码 ```