centos6.5 安裝Gogs

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

安裝Gogs之前先安裝好mysql,nginx

建立git使用者

gogs預設以git使用者運行

  1. 建立git使用者
    adduser git

  2. 以git使用者登入
    su git

  3. cd 到git使用者主目錄 /home/git 建立.ssh檔案夾 使用權限設定為0755

安裝Go語言運行環境

Gogs由Go語言編寫,運行時需要安裝Golang運行環境
如果系統中其他程式並不需要運行Go語言程式,可以只為上文建立的git使用者配置運行環境,也可以選擇配置全系統所有使用者的Go語言運行環境

  1. 配置環境變數,切換到使用者git,並只為該使用者配置Go運行環境

    su gitcd ~
  2. 寫入環境變數

    export GOROOT=$HOME/goexport GOARCH=386   #系統位元,386表示32位系統,amd64表示64位系統。export GOOS=linux   #系統類別型export PATH=$PATH:$GOROOT/bin
  3. 使環境變數生效
    source ~/.bashrc

安裝Go

  1. Go語言官網 可以擷取最新的二進位安裝包

    wget https://storage.googleapis.com/golang/go1.5.2.linux-386.tar.gztar xzvf go1.5.2.linux-386.tar.gzmv go $GOROOT

    Go語言運行環境就安裝完成了

  2. 測試Golang是否安裝成功
    go env

安裝 Gogs

  1. 下載先行編譯的二進位安裝包
    安裝包各版本地址:https://gogs.io/docs/installation/install_from_binary
    su gitcd ~wget -c http://7d9nal.com2.z0.glb.qiniucdn.com/gogs_v0.8.10_linux_386.tar.gztar zxf gogs_v0.8.10_linux_386.tar.gz
  2. 建立資料庫
    /home/git/gogs/scripts/mysql.sql是資料庫初始設定檔案
    提示:資料庫必須支援InnoDB引擎
    cd gogsmysql -u root -p < scripts/mysql.sql #(需輸入密碼)即可初始化好資料庫
  3. 登入 MySQL 建立一個新使用者 gogs,並將資料庫 gogs 的所有許可權都賦予該使用者
    mysql -u root -pcreate user 'gogs'@'localhost' identified by '密碼';grant all privileges on gogs.* to 'gogs'@'localhost';flush privileges;exit;
  4. 編輯 gogs/scripts/supervisor/gogs 修改如下
    directory=/home/git/gogs/command=/home/git/gogs/gogs web
    大家修改時根據實際路徑

nginx 反向 Proxy

  1. http
    server { server_name 網域名稱或IP; listen 80; location / { # 如果你希望通過子路徑訪問,此處修改為子路徑,注意以 / 開頭並以 / 結束     proxy_pass http://127.0.0.1:3000/; }}
  2. https
    server { listen 443 ssl; server_name 網域名稱或IP; ssl_certificate /path/to/gogs.io.unified.crt; ssl_certificate_key /path/to/gogs.io-decrypted.key; location / {     proxy_set_header X-Real-IP $remote_addr;     proxy_pass http://localhost:3000 $request_uri; }}

運行gogs

  1. 手動開啟gogs

    su gitcd ~/gogs./gogs web
  2. 守護進程開啟
    nohup ./gogs web &

  3. 加入服務運行
    將 /home/git/gogs/scripts/init/centos/gogs複製到/etc/init.d中
    root使用者下 service gogs stop|start|restart|reload|status

Gogs開啟後就可以使用 http://ip:3000 訪問 或者使用上面nginx配置的ip或網域名稱訪問
如需要通過3000連接埠訪問請注意在防火牆中開啟連接埠

配置說明

設定檔位於 Gogs 目錄的 custom/conf/app.ini,是 INI 格式的文字檔。
詳細的配置解釋和預設值請參考官方文檔,其中關鍵的配置大概是下面這些。
RUN_USER 預設是 git,指定 Gogs 以哪個使用者運行
ROOT 所有倉庫的儲存根路徑
PROTOCOL 如果你使用 nginx 反代的話請使用 http,如果直接裸跑對外服務的話隨意
DOMAIN 網域名稱。會影響 SSH clone 地址
ROOT_URL 完整的根路徑,會影響訪問時頁面上連結的指向,以及 HTTP clone 的地址
HTTP_ADDR 監聽地址,使用 nginx 的話建議 127.0.0.1,否則 0.0.0.0 也可以
HTTP_PORT 監聽連接埠,預設 3000
INSTALL_LOCK 鎖定安裝頁面
Mailer 相關的選項

設定倉庫和網站目錄同步

  1. 切換到git使用者
    su gitcd /wwwmkdir git-repocd git-repogit clone /home/git/gogs-repositories/user/demo.git
  2. 編輯 /home/git/gogs-repositories/user/demo.git/hooks/post-receive
    !/bin/sh  export LANG=zh_CN.UTF-8  cd /www/git-repo/demounset GIT_DIR //重要是這裡..  git pull origin masterchmod +x post-receive

其他

  1. 為git使用者佈建密碼
    passwd git

  2. 產生SSH密鑰
    設定全域的name和email

    git config --global user.name "xxx"git config --global user.email "xxx"

    或在倉庫目錄下設定該倉庫的name和email

    git config user.name x1git config user.email x1@xx.com

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

注意

  • 如果本地 push到遠程時提示沒有許可權
  • 可能是 gogs/data 和 gogs/data/sessions 目錄為root許可權 導致使用者建立的倉庫的許可權也為root

參考文章
https://mynook.info/blog/post/host-your-own-git-server-using-gogs
http://www.tuicool.com/articles/bYBnu2V https://gogs.io/docs/installation/install_from_binary

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.