Gogs is a self-service Git service that is extremely easy to build.
The Gogs project aims to create a simple, stable and scalable self-service Git service in the easiest way. The use of Go language development enables Gogs to be distributed through an independent binary and supports all platforms supported by the Go language, including Linux, macOS, Windows and ARM platforms.
1. Environment construction
Install git and database
1. Install git
Yum can be installed, use the following command
yum install -y git
2. Install the database
I use the mariadb 10.0.33
installation method:
CentOS7 offline install mariadb
Two, install gogs
1. Download the gogs installation package
wget https://dl.gogs.io/0.11.86/gogs_0.11.86_linux_amd64.tar.gz
If you are prompted that the wget command is not found, you can use yum to install
yum install -y wget
2. Unzip
tar –xzvf gogs_0.11.86_linux_amd64.tar.gz
3. Create a git user
useradd git
4. Change the owner of the gogs installation package to git
chown -R git:git /home/gogs
Three, create gogs user on the database and grant permissions
1. Log in to mariadb as root
mysql -uroot -p123456
2. Create gogs database
create database gogs default charset utf8 collate utf8_general_ci;
3. Create a gogs user and grant the user all permissions to the gogs database
GRANT ALL PRIVILEGES ON gogs.* TO 'gogs'@'%' IDENTIFIED BY '123456';
4. Refresh permissions
flush privileges;
Fourth, run gos and set to start automatically
1. Enter the gogs installation path
cd /home/gogs
2. Run gogs
#默认端口启动
su git
./gogs web
#指定端口启动
su git
./gogs web –port 3001
Using this method belongs to the startup the day before yesterday and will always run in the foreground. If you close the terminal, it will automatically exit, so use the background startup method.
3. Set to start automatically
- Copy the gogs startup script to the /etc/init.d/ path:
#gogs自己提供了默认的启动脚本,在gogs安装包的scripts/init/路径下,可以根据自己的操作系统选择不同的脚本
cp /home/gogs/scripts/init/centos/gogs /etc/rc.d/init.d/
- Edit startup script
vim /etc/init.d/gogs
Modify the GOGS_HOME and GOGS_USER of the startup script, which are the installation path of gogs and the startup user of gogs respectively. For example, I changed GOGS_HOME to /home/gogs and GOGS_USER to git
- Enter the /etc/init.d path
cd /etc/init.d
- Give executable permissions to the startup script
chmod +x gogs
- Test startup script
#启动gogs
service gogs start
#关闭gogs
service gogs stop
#重启gogs
service gogs restart
- Set gogs to start at boot
chkconfig gogs on
- Check if joining is successful
chkconfig --list gogs
See the following content to explain that it takes effect
Five, install gogs on the front end
If the default port 3000 is already occupied by other ports, the background startup method cannot start normally, because the background startup cannot specify the port without the front-end installation. The corresponding port can only be generated after the front-end installation of gogs Configuration file. Therefore, before setting the port to start the background, you need to start in the foreground and install the program on the front page.
1. Enter IP+specified port in the browser. For
example: http://192.168.134.159:3001, it
will automatically enter the following installation interface:
2. Fill in the relevant information according to the requirements. If you need to change the port, fill in the actual IP and port in the application url and
click OK after completing the filling. The following interface indicates that the installation is successful
Six, configuration file
After successfully installing gogs on the front-end page, the configuration file app.ini will be generated under the installation package. The path of app.ini is gogs/custom/conf/app.ini
. The content of the configuration file is as follows:
After editing the configuration file and saving it, you need to restart gogs to take effect
service gogs restart
Interpretation of each parameter of the configuration file
1 Overview:
- APP_NAME: App name, you can change the organization or company name
- RUN_USER: The name of the user who runs the application. If this value is not set correctly, it may cause the application to crash.
- RUN_MODE: The default value is prod. In view of performance and other considerations, it is recommended not to modify it to other values.
2. Server
- PROTOCOL: protocol, select http or https
- DOMAIN: server domain name
- ROOT_URL: public full URL path
- HTTP_ADDR: Application HTTP listening address
- HTTP_PORT: Application HTTP listening port number
- LOCAL_ROOT_URL: The local (DMZ) URL used for the Gogs worker process (such as SSH) to return to the application. Generally, keep the default value, unless the SSH server node and HTTP are not the same node entry
- DISABLE_SSH: It can be disabled when the SSH function is not available
- START_SSH_SERVER: Enable this option to start the built-in SSH server
- SSH_DOMAIN: The domain name that allows public networks to access SSH
- SSH_PORT: SSH port number, the default is 22, if the SSH port number is not 22, change it to the actual port number
- SSH_LISTEN_HOST: The address monitored by the built-in SSH server
- SSH_LISTEN_PORT: The port monitored by the built-in SSH server
- SSH_ROOT_PATH: SSH root directory, generally ~/.ssh, but must be filled in as /home/git/.ssh
- SSH_KEY_TEST_PATH: Temporary directory for testing SSH public keys
- SSH_KEYGEN_PATH: The path of the ssh-keygen program, the default is ssh-keygen, which means searching through the system path
- MINIMUM_KEY_SIZE_CHECK: Specify the minimum key size of different types of public keys
- DISABLE_ROUTER_LOG: Activate this option to disable routing log printing
- CERT_FILE: HTTPS authorization file path
- KEY_FILE: HTTPS key file path
- STATIC_ROOT_PATH: The parent directory of template files and static files, the default is the location of the application binary
- APP_DATA_PATH: The storage directory of application internal data
- LANDING_PAGE: Set the default homepage for users who are not logged in, which can be home or explore (discovery page)
3. Warehouse (repository)
- ROOT: The root directory of user warehouse storage, must be an absolute path, the default is ~//gogs-repositories
- SCRIPT_TYPE: system script type, generally bash
- ANSI_CHARSET: The default character set used when encountering an unrecognized character set
- FORCE_PRIVATE: It is mandatory that all newly created warehouses are private
- MAX_CREATION_LIMIT: The global default limit for each user to create a warehouse, -1 means unlimited
- PREFERRED_LICENSES: Recommend the user's preferred authorization type
- DISABLE_HTTP_GIT: Activate this option to prohibit users from interacting with the Git repository via HTTP, that is, users can only operate via SSH
- ENABLE_LOCAL_PATH_MIGRATION: Activate this option to enable the local path migration warehouse function. After startup, only the administrator can use it by default, and ordinary users must be authorized by the administrator
4. Database
- DB_TYPE: database type, it can be mysql, postgres, mssql or sqlite3
- HOST: database host address and port
- NAME: database name
- USER: database user name
- PASSWD: database user password
5. Security
- INSTALL_LOCK: Used to indicate whether to allow access to the installation page (this page can set the administrator account, so this option is very important)
- SECRET_KEY: The global encryption key. Be sure to modify this value to ensure the security of your server (a random string will be automatically generated during each installation)
- LOGIN_REMEMBER_DAYS: Record the number of days logged in
- COOKIE_USERNAME: The name of the cookie that records the username
- COOKIE_REMEMBER_NAM: The name of the cookie that records the user's automatic login information
6. Service
- ACTIVE_CODE_LIVE_MINUTES: The validity period of the activation code, in minutes
- RESET_PASSWD_CODE_LIVE_MINUTES: the validity period of the reset password, in minutes
- REGISTER_EMAIL_CONFIRM: Activate this option to require registered users to verify their mailbox and require Mailer to be enabled
- DISABLE_REGISTRATION: Activate this option to prohibit the user registration function, only the administrator can create an account
- SHOW_REGISTRATION_BUTTON: Used to indicate whether to display the registration button
- REQUIRE_SIGNIN_VIEW: Activate this option to require users to log in to view any page
- ENABLE_CACHE_AVATAR: Activate this option to cache Gravatar’s avatar
- ENABLE_NOTIFY_MAIL: Activate this option to send notification emails to followers, for example, when creating an issue, the Mailer must be enabled
- ENABLE_REVERSE_PROXY_AUTHENTICATION: Activate this option to enable reverse proxy user authentication, please learn more from https://github.com/gogits/gogs/issues/165
- ENABLE_REVERSE_PROXY_AUTO_REGISTRATION: Activate this option to enable the automatic registration function of reverse proxy user authentication
- DISABLE_MINIMUM_KEY_SIZE_CHECK: Activate this option to prohibit checking the minimum key length of the response type
- ENABLE_CAPTCHA: Activate this option to require a verification code when the user registers
7. Web hook (webhook)
- TYPES: The type of web hook to start, which can be gogs, slack or discord
- DELIVER_TIMEOUT: The timeout period for sending notifications, in seconds
- SKIP_TLS_VERIFY: Indicates whether to allow notification to addresses with untrusted certificates
- PAGING_NUM: The number of records displayed on each page of the Web hook history page
8. Cache
- ADAPTER cache engine adapter, which can be momery, redis or memcache. If you are using redis or memcache, be sure to rebuild all dependencies using the -tags option, for example: go build -tags='redis'
- INTERVAL is for memory cache use only, the GC cycle, in seconds
- HOST is only available for redis and memcache, configure the host address and port number
9. Session
- PROVIDER Session: Engine provider, which can be memory, file, redis or mysql
- PROVIDER_CONFIG: If the provider is file, it is the file root directory; if it is another provider, it is the host address and port number
- COOKIE_SECURE: Activate this option to require all session operations to pass HTTPS
- GC_INTERVAL_TIME GC: Period, in seconds
10. Log
- ROOT_PATH: The root directory of the log file
- MODE: Logging mode, the default is console. If you want to enable multiple modes, please use commas to separate, for example: "console, file"
- LEVEL basic log level, the default is Trace