GitGitlab及Git菜鸟成神之路Git使用

自建Git服务器之Gogs

2019-05-02  本文已影响2人  ImClive

一、什么是Gogs

Gogs 是一款极易搭建的自助 Git 服务,个人感觉比Gitlab要轻量级,搭建起来更方便。

二、下载及使用链接

三、环境搭建过程

1、环境要求(参考官方说明)

2、开始搭建

2.1、新建一个git用户

Gogs 默认以 git 用户运行,新建一个git用户。

sudo adduser git

以 git 用户登录,到 git 用户的主目录中新建好 .ssh 文件夹。

su git
cd /home/git
mkdir .ssh
//注意由于原始git服务也是用的git用户,ssh服务可能会被gogs改写后占用,如下面的authorized_keys文件内容
command="/home/git/gogs/gogs serv key-2 --config='/home/git/gogs/custom/conf/app.ini'",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXX@qq.com
//导致用ssh登陆时会有如下面输出
ssh git@YourHost
PTY allocation request failed on channel 0
Hi there, You've successfully authenticated, but Gogs does not provide shell access.
If this is unexpected, please log in with password and setup Gogs under another user.
Connection to YourHost closed.

解决方法:

2.2、找到想要的Gogs版本进行下载

cd /home/git
wget https://dl.gogs.io/0.11.34/linux_amd64.tar.gz
tar -zxvf linux_amd64.tar.gz

2.3、启动Gogs服务

cd gogs
./gogs web

//命令行输出
sh-4.1$ ./gogs web
2019/05/02 11:57:17 [TRACE] Custom path: /home/git/gogs/custom
2019/05/02 11:57:17 [TRACE] Log path: /home/git/gogs/log
2019/05/02 11:57:17 [TRACE] Log Mode: File (Trace)
2019/05/02 11:57:17 [ INFO] Wooduan 0.11.34.1122

//也可以以守护进程启动
nohup ./gogs web &

2.4、相关配置

SET GLOBAL innodb_file_per_table = ON,                                                          
           innodb_file_format = Barracuda,                                                      
           innodb_large_prefix = ON;                                                            
DROP DATABASE IF EXISTS gogs;                                                                   
CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
ALTER TABLE `access` ROW_FORMAT=DYNAMIC;
ALTER TABLE `access_token` ROW_FORMAT=DYNAMIC;
ALTER TABLE `action` ROW_FORMAT=DYNAMIC;
ALTER TABLE `attachment` ROW_FORMAT=DYNAMIC;
ALTER TABLE `collaboration` ROW_FORMAT=DYNAMIC;
ALTER TABLE `comment` ROW_FORMAT=DYNAMIC;
ALTER TABLE `deploy_key` ROW_FORMAT=DYNAMIC;
ALTER TABLE `email_address` ROW_FORMAT=DYNAMIC;
ALTER TABLE `follow` ROW_FORMAT=DYNAMIC;
ALTER TABLE `hook_task` ROW_FORMAT=DYNAMIC;
ALTER TABLE `issue` ROW_FORMAT=DYNAMIC;
ALTER TABLE `issue_label` ROW_FORMAT=DYNAMIC;
ALTER TABLE `issue_user` ROW_FORMAT=DYNAMIC;
ALTER TABLE `label` ROW_FORMAT=DYNAMIC;
ALTER TABLE `login_source` ROW_FORMAT=DYNAMIC;
ALTER TABLE `milestone` ROW_FORMAT=DYNAMIC;
ALTER TABLE `mirror` ROW_FORMAT=DYNAMIC;
ALTER TABLE `notice` ROW_FORMAT=DYNAMIC;
ALTER TABLE `org_user` ROW_FORMAT=DYNAMIC;
ALTER TABLE `protect_branch` ROW_FORMAT=DYNAMIC;
ALTER TABLE `protect_branch_whitelist` ROW_FORMAT=DYNAMIC;
ALTER TABLE `public_key` ROW_FORMAT=DYNAMIC;
ALTER TABLE `pull_request` ROW_FORMAT=DYNAMIC;
ALTER TABLE `release` ROW_FORMAT=DYNAMIC;
ALTER TABLE `repository` ROW_FORMAT=DYNAMIC;
ALTER TABLE `star` ROW_FORMAT=DYNAMIC;
ALTER TABLE `team` ROW_FORMAT=DYNAMIC;
ALTER TABLE `team_repo` ROW_FORMAT=DYNAMIC;
ALTER TABLE `team_user` ROW_FORMAT=DYNAMIC;
ALTER TABLE `two_factor` ROW_FORMAT=DYNAMIC;
ALTER TABLE `two_factor_recovery_code` ROW_FORMAT=DYNAMIC;
ALTER TABLE `upload` ROW_FORMAT=DYNAMIC;
ALTER TABLE `user` ROW_FORMAT=DYNAMIC;
ALTER TABLE `watch` ROW_FORMAT=DYNAMIC;
ALTER TABLE `webhook` ROW_FORMAT=DYNAMIC;
ln -s /usr/local/git-2.12.2/bin/git-upload-pack /bin/git-upload-pack
ln -s /usr/local/git-2.12.2/bin/git-cvsserver /bin/git-cvsserver
ln -s /usr/local/git-2.12.2/bin/gitk /bin/gitk
ln -s /usr/local/git-2.12.2/bin/git-receive-pack /bin/git-receive-pack
ln -s /usr/local/git-2.12.2/bin/git-shell /bin/git-shell
ln -s /usr/local/git-2.12.2/bin/git-upload-archive /bin/git-upload-archive

[root@10-23-67-69 conf]# ll /bin/git*
lrwxrwxrwx 1 root root 29 May  2 01:24 /bin/git -> /usr/local/git-2.12.2/bin/git
lrwxrwxrwx 1 root root 39 May  2 01:25 /bin/git-cvsserver -> /usr/local/git-2.12.2/bin/git-cvsserver
lrwxrwxrwx 1 root root 42 May  2 01:25 /bin/git-receive-pack -> /usr/local/git-2.12.2/bin/git-receive-pack
lrwxrwxrwx 1 root root 35 May  2 01:25 /bin/git-shell -> /usr/local/git-2.12.2/bin/git-shell
lrwxrwxrwx 1 root root 44 May  2 01:25 /bin/git-upload-archive -> /usr/local/git-2.12.2/bin/git-upload-archive
lrwxrwxrwx 1 root root 41 May  2 01:20 /bin/git-upload-pack -> /usr/local/git-2.12.2/bin/git-upload-pack
lrwxrwxrwx 1 root root 30 May  2 01:26 /bin/gitk -> /usr/local/git-2.12.2/bin/gitk

暂时想到的就这么多,安装或者使用上面有问题的话,请留言给我,我会及时回复的。

上一篇下一篇

猜你喜欢

热点阅读