웹사이트 검색

Nginx와 함께 Gitea를 설치하는 방법 및 Ubuntu 20.04에서 무료 Lets Encrypt SSL


이 튜토리얼은 다음 OS 버전에 대해 존재합니다.

  • 우분투 18.04(바이오닉 비버)

이 페이지에서

  1. 전제 조건
  2. Git 설치
  3. MariaDB 설치 및 구성
  4. Gitea 설치 및 구성
  5. Gitea Systemd 서비스 파일 생성
  6. Gitea용 Nginx 구성
  7. Lets Encrypt SSL로 Gitea 보안
  8. Gitea 웹 인터페이스 액세스
  9. 결론

Gitea는 Go로 작성된 오픈 소스 및 자체 호스팅 버전 제어 시스템입니다. 간단하고 가벼우며 저전력 시스템에 설치할 수 있습니다. Gogs의 포크이며 GitHub 및 GitLab의 대안입니다. 리포지토리 파일 편집기, 프로젝트 문제 추적, 사용자 관리, 알림, 내장 위키 등 많은 기능이 함께 제공됩니다. Linux, macOS, Windows, ARM 및 PowerPC 아키텍처를 포함한 모든 최신 운영 체제에 설치할 수 있습니다.

이 튜토리얼에서는 Ubuntu 20.04에서 Nginx 및 Lets Encrypt SSL과 함께 Gitea Git 서비스를 설치하는 방법을 보여줍니다.

전제 조건

  • Ubuntu 20.04를 실행하는 서버.\n
  • 유효한 도메인 이름은 서버를 가리킵니다.\n
  • 서버에 루트 암호가 구성되어 있습니다.\n

힘내 설치

먼저 서버에 Git 패키지를 설치해야 합니다. 다음 명령을 실행하여 설치할 수 있습니다.

apt-get install git -y

Git 패키지가 설치되면 다음 단계로 진행할 수 있습니다.

MariaDB 설치 및 구성

기본적으로 MariaDB는 보안되지 않습니다. 따라서 먼저 보안을 유지해야 합니다. mysql_secure_installation 스크립트를 실행하여 보안을 설정할 수 있습니다.

mysql_secure_installation

이 스크립트는 아래와 같이 루트 암호를 설정하고, 익명 사용자를 제거하고, 원격으로 루트 로그인을 허용하지 않고, 테스트 데이터베이스를 제거합니다.

Enter current password for root (enter for none):
Set root password? [Y/n]: Y
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]:  Y
Reload privilege tables now? [Y/n]:  Y

MariaDB가 보호되면 다음 명령을 사용하여 MariaDB 셸에 로그인합니다.

mysql -u root -p

프롬프트가 표시되면 루트 비밀번호를 입력하십시오. 그런 다음 GLOBAL innodeb_file_per_table을 On으로 변경합니다.

MariaDB [(none)]>SET GLOBAL innodb_file_per_table = ON;

다음으로 다음 명령을 사용하여 Gitea에 대한 데이터베이스와 사용자를 생성합니다.

MariaDB [(none)]>CREATE DATABASE giteadb;
MariaDB [(none)]>CREATE USER 'gitea'@'localhost' IDENTIFIED BY 'password';

다음으로 gitedb 데이터베이스에 모든 권한을 부여합니다.

MariaDB [(none)]>GRANT ALL ON giteadb.* TO 'gitea'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

다음으로 다음 명령을 사용하여 데이터베이스 문자 집합을 업데이트합니다.

MariaDB [(none)]>ALTER DATABASE giteadb CHARACTER SET = utf8mb4 COLLATE utf8mb4_unicode_ci;

마지막으로 권한을 플러시하고 다음 명령을 사용하여 MariaDB 셸을 종료합니다.

MariaDB [(none)]>FLUSH PRIVILEGES;
MariaDB [(none)]>EXIT;

다음으로 MariaDB 기본 구성 파일을 편집하고 innodb 매개변수를 추가해야 합니다.

nano /etc/mysql/mariadb.conf.d/50-server.cnf

[mysqld] 섹션 안에 다음 줄을 추가합니다.

innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_default_row_format = dynamic

파일을 저장하고 닫습니다. 그런 다음 MariaDB 서비스를 다시 시작하여 변경 사항을 적용합니다.

systemctl restart mariadb

이 시점에서 MariaDB 데이터베이스가 구성되었습니다. 이제 다음 단계를 진행할 수 있습니다.

Gitea 설치 및 구성

먼저 Git 저장소에서 최신 버전의 Gitea 바이너리를 다운로드해야 합니다. 다음 명령으로 다운로드할 수 있습니다.

wget https://dl.gitea.io/gitea/1.12.1/gitea-1.12.1-linux-amd64

다음으로 다운로드한 파일을 /usr/bin/ 디렉토리에 복사하고 실행 권한을 부여합니다.

cp gitea-1.12.1-linux-amd64 /usr/bin/gitea
chmod 755 /usr/bin/gitea

다음으로 다음 명령을 사용하여 Gitea의 시스템 사용자를 생성합니다.

adduser --system --shell /bin/bash --group --disabled-password --home /home/git git

다음으로 다음 명령을 사용하여 Gitea의 디렉토리 구조를 생성합니다.

mkdir -p /etc/gitea /var/lib/gitea/{custom,data,indexers,public,log}
chown git:git /etc/gitea /var/lib/gitea/{custom,data,indexers,public,log}
chmod 750 /var/lib/gitea/{data,indexers,log}
chmod 770 /etc/gitea

완료되면 다음 단계로 진행할 수 있습니다.

Gitea Systemd 서비스 파일 생성

다음으로 Gitea 서비스를 관리하기 위한 systemd 서비스 파일을 생성해야 합니다. 다음 명령으로 만들 수 있습니다.

nano /etc/systemd/system/gitea.service

다음 줄을 추가합니다.

[Unit]
Description=Gitea
After=syslog.target
After=network.target
After=mysql.service

[Service]
RestartSec=2s
Type=simple
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/bin/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea

[Install]
WantedBy=multi-user.target

파일을 저장하고 닫습니다. 그런 다음 systemd 데몬을 다시 로드하고 다음 명령을 사용하여 Gitea 서비스를 시작합니다.

systemctl daemon-reload
systemctl start gitea

이제 다음 명령을 사용하여 Gitea 서비스의 상태를 확인할 수 있습니다.

systemctl status gitea

다음 출력이 표시되어야 합니다.

? gitea.service - Gitea
     Loaded: loaded (/etc/systemd/system/gitea.service; disabled; vendor preset: enabled)
     Active: active (running) since Thu 2020-06-25 08:23:01 UTC; 6s ago
   Main PID: 24046 (gitea)
      Tasks: 9 (limit: 2353)
     Memory: 134.3M
     CGroup: /system.slice/gitea.service
             ??24046 /usr/bin/gitea web -c /etc/gitea/app.ini

Jun 25 08:23:02 ubuntu20 gitea[24046]: 2020/06/25 08:23:02 routers/init.go:127:GlobalInit() [I] Delete all repository archives
Jun 25 08:23:02 ubuntu20 gitea[24046]: 2020/06/25 08:23:02 ...dules/setting/log.go:233:newLogService() [I] Gitea v1.12.1 built with GNU Make 4>
Jun 25 08:23:02 ubuntu20 gitea[24046]: 2020/06/25 08:23:02 ...dules/setting/log.go:279:newLogService() [I] Gitea Log Mode: Console(Console:inf>
Jun 25 08:23:02 ubuntu20 gitea[24046]: 2020/06/25 08:23:02 ...les/setting/cache.go:70:newCacheService() [I] Cache Service Enabled
Jun 25 08:23:02 ubuntu20 gitea[24046]: 2020/06/25 08:23:02 ...les/setting/cache.go:81:newCacheService() [I] Last Commit Cache Service Enabled
Jun 25 08:23:02 ubuntu20 gitea[24046]: 2020/06/25 08:23:02 ...s/setting/session.go:63:newSessionService() [I] Session Service Enabled
Jun 25 08:23:02 ubuntu20 gitea[24046]: 2020/06/25 08:23:02 routers/init.go:165:GlobalInit() [I] SQLite3 Supported
Jun 25 08:23:02 ubuntu20 gitea[24046]: 2020/06/25 08:23:02 routers/init.go:51:checkRunMode() [I] Run Mode: Development
Jun 25 08:23:03 ubuntu20 gitea[24046]: 2020/06/25 08:23:03 cmd/web.go:161:runWeb() [I] Listen: http://0.0.0.0:3000
Jun 25 08:23:03 ubuntu20 gitea[24046]: 2020/06/25 08:23:03 ...s/graceful/server.go:55:NewServer() [I] Starting new server: tcp:0.0.0.0:3000 on>
lines 1-19/19 (END)

다음으로 다음 명령을 사용하여 시스템 재부팅 시 Gitea 서비스가 시작되도록 활성화합니다.

systemctl enable gitea

이 시점에서 Gitea가 시작되고 포트 3000에서 수신 대기합니다. 이제 다음 단계를 진행할 수 있습니다.

Gitea용 Nginx 구성

기본적으로 Gitea는 포트 3000에서 수신 대기합니다. 따라서 포트를 지정하지 않고 Gitea에 액세스하려면 Nginx를 리버스 프록시로 구성해야 합니다.

먼저 다음 명령을 실행하여 Nginx 웹 서버를 설치합니다.

apt-get install nginx -y

설치가 완료되면 Gitea용 새 Nginx 가상 호스트 구성 파일을 생성합니다.

nano /etc/nginx/sites-available/gitea

다음 줄을 추가합니다.

upstream gitea {
    server 127.0.0.1:3000;
}

server {
    listen 80;
    server_name gitea.linuxbuz.com;
    root /var/lib/gitea/public;
    access_log off;
    error_log off;

    location / {
      try_files maintain.html $uri $uri/index.html @node;
    }

    location @node {
      client_max_body_size 0;
      proxy_pass http://localhost:3000;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_max_temp_file_size 0;
      proxy_redirect off;
      proxy_read_timeout 120;
    }
}

파일을 저장하고 닫습니다. 그런 다음 다음 명령을 사용하여 Nginx 가상 호스트 구성 파일을 활성화합니다.

ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/

마지막으로 다음 명령을 사용하여 Nginx 서비스를 다시 시작합니다.

systemctl restart nginx

다음 명령을 사용하여 Nginx 서비스의 상태를 확인할 수도 있습니다.

systemctl status nginx

다음 출력이 표시되어야 합니다.

? nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2020-06-25 08:26:00 UTC; 1min 24s ago
       Docs: man:nginx(8)
    Process: 24866 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 24877 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 24879 (nginx)
      Tasks: 3 (limit: 2353)
     Memory: 3.6M
     CGroup: /system.slice/nginx.service
             ??24879 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ??24880 nginx: worker process
             ??24881 nginx: worker process

Jun 25 08:25:59 ubuntu20 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 25 08:26:00 ubuntu20 systemd[1]: Started A high performance web server and a reverse proxy server.

이 시점에서 Nginx는 Gitea를 제공하도록 구성됩니다. 이제 다음 단계를 진행할 수 있습니다.

Lets Encrypt SSL로 Gitea 보호

먼저 시스템에 Lets Encrypt SSL을 설치하고 관리하려면 Certbot 클라이언트를 설치해야 합니다. 다음 명령을 실행하여 설치할 수 있습니다.

apt-get install certbot python3-certbot-nginx -y

Certbot이 설치되면 다음 명령을 실행하여 Lets Encrypt SSL for Gitea 웹사이트를 다운로드하고 설치합니다.

certbot --nginx -d gitea.linuxbuz.com

이메일 주소를 제공하고 아래와 같이 서비스 약관에 동의하십시오.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for gitea.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/gitea

다음으로 아래와 같이 HTTP 트래픽을 HTTPS로 리디렉션할지 여부를 선택합니다.

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

2를 입력하고 Enter 키를 눌러 아래와 같이 인증서를 설치합니다.

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/gitea

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://gitea.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=gitea.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/gitea.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/gitea.linuxbuz.com/privkey.pem
   Your cert will expire on 2020-09-23. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

이제 귀하의 Gitea 웹사이트는 Lets Encrypt SSL로 보호됩니다. 이제 다음 단계를 진행할 수 있습니다.

Gitea 웹 인터페이스에 액세스

이제 웹 브라우저를 열고 URL https://gitea.linuxbuz.com/install을 입력하십시오. 다음 페이지로 리디렉션됩니다.

Gitea 데이터베이스 이름, 사용자 이름, 암호, 리포지토리 경로, 사용자 이름으로 실행, 수신 포트, Gitea 기본 URL, 로그 경로, Gitea 관리자 사용자 이름, 암호를 제공하고 Gitea 설치 버튼을 클릭합니다. 설치가 완료되면 다음 화면에 Gitea 대시보드가 표시됩니다.

결론

축하합니다! Nginx와 함께 Gitea를 성공적으로 설치했으며 Ubuntu 20.04 서버에서 SSL을 암호화합니다. 이제 Gitea를 탐색하고 Gitea로 첫 번째 리포지토리를 만들 수 있습니다. 자세한 내용은 Gitea 문서를 참조하세요.