Ubuntu16.04 Gogs

Gogs 是一款极易搭建的自助 Git 服务。

Gogs

Init The required Env

sudo apt-get update
sudo apt-get install git nginx wget
sudo adduser git
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| /etc/passwd                              |
|                                          |
| git:x:1000:1000::/home/git:/bin/bash     |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cd /home && chown -R git.git git
chmod 700 git

sudo apt-get install mysql-server (安装过程中会让设置密码)

su - git
wget https://dl.gogs.io/0.11.53/gogs_0.11.53_linux_amd64.tar.gz

Install Gogs

cd /home/git
tar xf gogs_0.11.53_linux_amd64.tar.gz
cd /home/git/gogs/scripts
mysql -p < mysql.sql
cp systemd/gogs.service /etc/systemd/system/

systemctl start gogs.service
systemctl status gogs.service
lsof -i:3000

访问 http://x.x.x.x:3000/install 来完成首次运行的配置工作
页面上都有详细注释,这里不做详解

Settings Nginx

/etc/nginx/nginx.conf

http {
    **********************
    |~~~~~~~~~~~~~~~~~~~~|
    **********************
    
    server {
        listen       80;
        server_name  gogs.itchao.win;
        
        location / {
             proxy_pass http://127.0.0.1:3000/;
             proxy_redirect default;
        }
    }

    include    conf.d/www.conf;
}
Gogs展示

Extend Hexo Blog

  • hexo 推送到Gogs仓库
deploy:
  type: git
  repo: 
      gogs: [email protected]:Evan/hexo.git
  • Git自动部署钩子
gogs-repositories/evan/hexo.git/hooks/post-receive
git --work-tree=/var/www/html checkout -f
  • Nginx 解析
www.conf

server {
        listen       80;
        server_name  www.itchao.win;

    root         /var/www/html;

    location / {
            index  index.html;
            try_files $uri $uri/ /index.html;
        }
}
cd /var/www && chown -R git. html 
nginx -t
systemctl reload nginx.service 
首页

Migration & Upgrade

本迁移或升级教程基于二进制安装

#迁移
mysqldump -ugogs -p  -B gogs > gogs.sql           #回车输入密码备份gogs库数据
tar zcf gogs.migra.gz gogs-repositories gogs.sql  #打包仓库及数据
scp gogs.migra.gz NewServerIP:/home/git/      #把压缩包传到新服务器的Git家目录

#新服务器上获取相应的二进制版本并解压
wget https://dl.gogs.io/0.11.53/gogs_0.11.53_linux_amd64.tar.gz
tar xf gogs_0.11.53_linux_amd64.tar.gz
tar xf gogs.migra.gz
$ ls
gogs gogs.migra.gz gogs.sql gogs-repositories gogs_0.11.53_linux_amd64.tar.gz 

mysql -p < gogs.sql
\cp /home/git/gogs/scripts/systemd/gogs.service /etc/systemd/system/
systemctl enable gogs.service
systemctl start gogs.service

#升级参考迁移步骤,变动之处就是下载新的二进制安装包并解压
wget https://dl.gogs.io/$VERSION/gogs_$VERSION_$OS_$ARCH.tar.gz   (gogs_0.11.86_linux_amd64.tar.gz)
tar xf gogs_$VERSION_$OS_$ARCH.tar.gz

个人账户安全设置

用户设置 ---> 账户安全 ---> 两步验证
用Google Authenticator 扫描 开启两步验证

原文链接

你可能感兴趣的:(Ubuntu16.04 Gogs)