CentOS build Gogs

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
Insert picture description here

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:
Insert picture description here

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
Insert picture description hereclick OK after completing the filling. The following interface indicates that the installation is successful

Insert picture description here

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
Insert picture description here
. The content of the configuration file is as follows:

Insert picture description hereAfter editing the configuration file and saving it, you need to restart gogs to take effect

service gogs restart

Insert picture description here

Interpretation of each parameter of the configuration file

1 Overview:

  1. APP_NAME: App name, you can change the organization or company name
  2. 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.
  3. 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

  1. PROTOCOL: protocol, select http or https
  2. DOMAIN: server domain name
  3. ROOT_URL: public full URL path
  4. HTTP_ADDR: Application HTTP listening address
  5. HTTP_PORT: Application HTTP listening port number
  6. 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
  7. DISABLE_SSH: It can be disabled when the SSH function is not available
  8. START_SSH_SERVER: Enable this option to start the built-in SSH server
  9. SSH_DOMAIN: The domain name that allows public networks to access SSH
  10. SSH_PORT: SSH port number, the default is 22, if the SSH port number is not 22, change it to the actual port number
  11. SSH_LISTEN_HOST: The address monitored by the built-in SSH server
  12. SSH_LISTEN_PORT: The port monitored by the built-in SSH server
  13. SSH_ROOT_PATH: SSH root directory, generally ~/.ssh, but must be filled in as /home/git/.ssh
  14. SSH_KEY_TEST_PATH: Temporary directory for testing SSH public keys
  15. SSH_KEYGEN_PATH: The path of the ssh-keygen program, the default is ssh-keygen, which means searching through the system path
  16. MINIMUM_KEY_SIZE_CHECK: Specify the minimum key size of different types of public keys
  17. DISABLE_ROUTER_LOG: Activate this option to disable routing log printing
  18. CERT_FILE: HTTPS authorization file path
  19. KEY_FILE: HTTPS key file path
  20. STATIC_ROOT_PATH: The parent directory of template files and static files, the default is the location of the application binary
  21. APP_DATA_PATH: The storage directory of application internal data
  22. LANDING_PAGE: Set the default homepage for users who are not logged in, which can be home or explore (discovery page)

3. Warehouse (repository)

  1. ROOT: The root directory of user warehouse storage, must be an absolute path, the default is ~//gogs-repositories
  2. SCRIPT_TYPE: system script type, generally bash
  3. ANSI_CHARSET: The default character set used when encountering an unrecognized character set
  4. FORCE_PRIVATE: It is mandatory that all newly created warehouses are private
  5. MAX_CREATION_LIMIT: The global default limit for each user to create a warehouse, -1 means unlimited
  6. PREFERRED_LICENSES: Recommend the user's preferred authorization type
  7. 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
  8. 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

  1. DB_TYPE: database type, it can be mysql, postgres, mssql or sqlite3
  2. HOST: database host address and port
  3. NAME: database name
  4. USER: database user name
  5. PASSWD: database user password

5. Security

  1. 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)
  2. 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)
  3. LOGIN_REMEMBER_DAYS: Record the number of days logged in
  4. COOKIE_USERNAME: The name of the cookie that records the username
  5. COOKIE_REMEMBER_NAM: The name of the cookie that records the user's automatic login information

6. Service

  1. ACTIVE_CODE_LIVE_MINUTES: The validity period of the activation code, in minutes
  2. RESET_PASSWD_CODE_LIVE_MINUTES: the validity period of the reset password, in minutes
  3. REGISTER_EMAIL_CONFIRM: Activate this option to require registered users to verify their mailbox and require Mailer to be enabled
  4. DISABLE_REGISTRATION: Activate this option to prohibit the user registration function, only the administrator can create an account
  5. SHOW_REGISTRATION_BUTTON: Used to indicate whether to display the registration button
  6. REQUIRE_SIGNIN_VIEW: Activate this option to require users to log in to view any page
  7. ENABLE_CACHE_AVATAR: Activate this option to cache Gravatar’s avatar
  8. ENABLE_NOTIFY_MAIL: Activate this option to send notification emails to followers, for example, when creating an issue, the Mailer must be enabled
  9. ENABLE_REVERSE_PROXY_AUTHENTICATION: Activate this option to enable reverse proxy user authentication, please learn more from https://github.com/gogits/gogs/issues/165
  10. ENABLE_REVERSE_PROXY_AUTO_REGISTRATION: Activate this option to enable the automatic registration function of reverse proxy user authentication
  11. DISABLE_MINIMUM_KEY_SIZE_CHECK: Activate this option to prohibit checking the minimum key length of the response type
  12. ENABLE_CAPTCHA: Activate this option to require a verification code when the user registers

7. Web hook (webhook)

  1. TYPES: The type of web hook to start, which can be gogs, slack or discord
  2. DELIVER_TIMEOUT: The timeout period for sending notifications, in seconds
  3. SKIP_TLS_VERIFY: Indicates whether to allow notification to addresses with untrusted certificates
  4. PAGING_NUM: The number of records displayed on each page of the Web hook history page

8. Cache

  1. 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'
  2. INTERVAL is for memory cache use only, the GC cycle, in seconds
  3. HOST is only available for redis and memcache, configure the host address and port number

9. Session

  1. PROVIDER Session: Engine provider, which can be memory, file, redis or mysql
  2. 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
  3. COOKIE_SECURE: Activate this option to require all session operations to pass HTTPS
  4. GC_INTERVAL_TIME GC: Period, in seconds

10. Log

  1. ROOT_PATH: The root directory of the log file
  2. MODE: Logging mode, the default is console. If you want to enable multiple modes, please use commas to separate, for example: "console, file"
  3. LEVEL basic log level, the default is Trace

Guess you like

Origin blog.csdn.net/xiguashixiaoyu/article/details/108766606