웹사이트 검색

Ubuntu 22.04에 Gitea를 설치하는 방법


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

  • Ubuntu 22.04(Jammy Jellyfish)
  • Ubuntu 18.04(Bionic Beaver)

이 페이지에서

  1. 전제 조건
  2. 시작하기\n
  3. MariaDB 설치 및 구성
  4. Gitea 설치 및 구성
  5. Gitea Systemd 서비스 파일 생성
  6. Nginx를 Gitea용 리버스 프록시로 구성\n
  7. Lets Encrypt SSL로 Gitea 보안
  8. Gitea 웹 인터페이스 액세스
  9. 결론

Gitea는 무료 오픈 소스 자체 호스팅 Git 서비스입니다. GO 언어로 작성되었으며 인터넷에서 자신의 버전 제어 시스템을 호스팅하는 더 쉬운 방법을 제공합니다. 간단하고 가벼우며 저전력 시스템에 설치할 수 있습니다. GitHub 및 GitLab과 매우 유사하며 리포지토리 파일 편집기, 프로젝트 문제 추적, 사용자 관리, 알림, 내장 위키 등과 같은 다양한 기능을 제공합니다. 크로스 플랫폼이며 Linux, macOS, Windows, ARM 및 PowerPC 아키텍처를 포함한 모든 주요 운영 체제에 설치할 수 있습니다.

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

전제 조건

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

시작하기

먼저 다음 명령을 실행하여 모든 시스템 패키지를 최신 버전으로 업데이트하고 업그레이드합니다.

apt update -y
apt upgrade -y

그런 다음 다음 명령을 실행하여 Git 패키지를 설치합니다.

apt-get install git -y

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

MariaDB 설치 및 구성

Gitea는 MariaDB를 데이터베이스 백엔드로 사용합니다. 따라서 서버에 설치해야 합니다. 다음 명령을 실행하여 설치할 수 있습니다.

apt install mariadb-server -y

설치 후. 따라서 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 gitea;
MariaDB [(none)]>CREATE USER 'gitea'@'localhost' IDENTIFIED BY 'password';

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

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

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

MariaDB [(none)]>ALTER DATABASE gitea 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 설치 및 구성

먼저 Gitea 다운로드 페이지를 방문하여 최신 버전을 선택하고 다음 명령을 사용하여 최신 Gitea 바이너리를 다운로드합니다.

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

다운로드가 완료되면 다운로드한 파일을 /usr/bin/ 디렉터리에 복사하고 실행 권한을 부여합니다.

cp gitea-1.17.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 서비스 파일 생성

다음으로 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 Sun 2022-08-21 12:19:23 UTC; 8s ago
   Main PID: 24766 (gitea)
      Tasks: 6 (limit: 2242)
     Memory: 121.2M
        CPU: 800ms
     CGroup: /system.slice/gitea.service
             ??24766 /usr/bin/gitea web -c /etc/gitea/app.ini

Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 ...s/install/setting.go:21:PreloadSettings() [I] AppPath: /usr/bin/gitea
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 ...s/install/setting.go:22:PreloadSettings() [I] AppWorkPath: /var/lib/gitea
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 ...s/install/setting.go:23:PreloadSettings() [I] Custom path: /var/lib/gitea/cus>
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 ...s/install/setting.go:24:PreloadSettings() [I] Log path: /var/lib/gitea/log
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 ...s/install/setting.go:25:PreloadSettings() [I] Configuration file: /etc/gitea/>
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 ...s/install/setting.go:26:PreloadSettings() [I] Prepare to run install page
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 ...s/install/setting.go:29:PreloadSettings() [I] SQLite3 is supported
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 cmd/web.go:217:listen() [I] [630222cb-6] Listen: http://0.0.0.0:3000
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 cmd/web.go:221:listen() [I] [630222cb-6] AppURL(ROOT_URL): http://localhost:3000/
Aug 21 12:19:23 ubuntu2204 gitea[24766]: 2022/08/21 12:19:23 ...s/graceful/server.go:61:NewServer() [I] [630222cb-6] Starting new Web server:>

다음으로 다음 명령을 사용하여 시스템 재부팅 시 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 git.example.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 서비스를 다시 시작하고 다음 명령을 사용하여 Nginx 서비스의 상태를 확인합니다.

systemctl restart 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 Sun 2022-08-21 12:21:23 UTC; 5s ago
       Docs: man:nginx(8)
    Process: 24799 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 24800 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 24801 (nginx)
      Tasks: 2 (limit: 2242)
     Memory: 4.5M
        CPU: 44ms
     CGroup: /system.slice/nginx.service
             ??24801 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
             ??24802 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Aug 21 12:21:23 ubuntu2204 systemd[1]: Starting A high performance web server and a reverse proxy server...
Aug 21 12:21:23 ubuntu2204 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이 설치되면 다음 명령을 실행하여 Gitea 웹사이트용 Lets Encrypt SSL을 다운로드하고 설치합니다.

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 2022-11-21. 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://git.example.com/을 입력합니다. 다음 페이지로 리디렉션됩니다.

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

결론

축하합니다! Nginx와 함께 Gitea를 성공적으로 설치했으며 Ubuntu 22.04 서버에 Lets Encrypt SSL을 사용했습니다. 이제 조직에 Gitea를 배포하고 Gitea로 첫 번째 리포지토리 생성을 시작할 수 있습니다. 자세한 내용은 Gitea 설명서를 참조하십시오.