how to install git server on ubuntu

本文详细介绍了如何在Ubuntu系统上安装配置Git服务器,包括安装Git、创建Git用户、安装PostgreSQL数据库及配置Gogs服务等步骤,并提供了数据库配置示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


# How to install git server on ubuntu

## install git

  sudo apt-get install git

## add git user 

  sudo useradd git 
  
  sudo passwd git
  
## install postgres

  sudo apt-get install postgresql
  
  sudo apt-get install pgadmin3
  
  pgadmin3 is optional, its a gui administration tool for PostgreSQL
       

### create database  
~$ sudo -i -u postgres
  
~$ psql

## if there have a error
## psql could not connect to server : No sunch file or directory
## please retart service postgresql
## Command : sudo /etc/init,d/postgresql restart
  
postgres=# CREATE USER git WITH PASSWORD 'myPassword';

Add a database called gogs

postgres=# CREATE DATABASE gogs;

Now grant all privileges on database

postgres=# GRANT ALL PRIVILEGES ON DATABASE gogs to git;

Type \q to quit:

postgres=# \q

try to connect new database with git user

~$psql -U git gogs 

##if get error 
##"psql: FATAL:  Peer authentication failed for user "git""
## sudo vi /etc/postgresql/9.5/main/pg_hba.conf
## change
## local   all             all                                     peer
## to
## local   all             all                                     md5
##
## sudo service postgreql restart

## install gogs server

    sudo -i -u git
    
    download gogs package from https://dl.gogs.io
        
    extract downloaded package 
    
    cd gogs
    
    sudo chown -R git:git /home/git/gogs
    
    config custom/conf/app.ini follow this link https://gogs.io/docs/advanced/configuration_cheat_sheet
    
*         database config
*         repository path
*         server config
*         mailer config
        
###  config example
        
        
```   
         [database]
         DB_TYPE  = postgres
         HOST     = 127.0.0.1:5432
         NAME     = gogs
         USER     = git
         PASSWD   = myPassword
         SSL_MODE = require
         PATH     = data/gogs.db
         
         [repository]
         ROOT = /home/git/gogs-repositories
         
         [server]
         DOMAIN       = 192.168.1.100
         HTTP_PORT    = 3000
         ROOT_URL     = http://192.168.1.100:3000/
         DISABLE_SSH  = false
         SSH_PORT     = 22
         OFFLINE_MODE = false
         
         [mailer]
         ENABLED = True
         DISABLE_HELO = true
         HELO_HOSTNAME = hello
         HOST = smtp.exmail.qq.com:25
         FROM = user@email.com
         USER = user@email.com
         PASSWD = passwd
         SKIP_VERIFY = true
         
         [service]
         REGISTER_EMAIL_CONFIRM = false
         ENABLE_NOTIFY_MAIL     = true
         DISABLE_REGISTRATION   = false
         ENABLE_CAPTCHA         = true
         REQUIRE_SIGNIN_VIEW    = false

```

### start run gogs

    ./gogs web
    
## supervisor 
   
   supervisor used to auto restart gogs server when fail

    sudo apt-get install supervisor
    
    add config file:   vim /etc/supervisor/conf.d/gogs.conf

```
        [program:gogs]
        directory=/home/git/gogs/
        command=/home/git/gogs/gogs web
        autostart=true
        autorestart=true
        startsecs=10
        stdout_logfile=/var/log/gogs/stdout.log
        stdout_logfile_maxbytes=1MB
        stdout_logfile_backups=10
        stdout_capture_maxbytes=1MB
        stderr_logfile=/var/log/gogs/stderr.log
        stderr_logfile_maxbytes=1MB
        stderr_logfile_backups=10
        stderr_capture_maxbytes=1MB
        user = git
        environment = HOME="/home/git", USER="git"
```

    sudo touch /var/run/supervisor.sock
    sudo chmod 777 /var/run/supervisor.sock
    sudo mkdir /var/log/gogs
    sudo touch /var/log/gogs/stdout.log /var/log/gogs/stderr.log
    sudo chmod 777 /var/log/gogs/*

    sudo supervisorctl restart

    sudo reboot
    
    run supervisorctl to check if gogs is running 
    

## log 

    check the log file  if gogs server fail, the log in:
    
    /home/git/gogs/log/gogs.log
    
    /var/log/gogs/stderr.log
    
    /var/log/gogs/stdout.log
    
# BACKUP

##  TODO repo backup

##  TODO database backup   
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值