gitea 安裝筆記

gitea

安裝 mariadb

sudo apt-get install mariadb-server
sudo systemctl start mysqld
sudo mysql_secure_installation

如果已設密碼,但用無法登入 (MySQL Workbench / Sequel Pro)

mysql -u root -p
UPDATE mysql.user SET plugin = '' WHERE user = 'root' AND host = 'localhost';
FLUSH PRIVILEGES;

建立 gitea 資料庫

mysql -u root -p
CREATE DATABASE gitea` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;

建立使用者 gitea 並賦予 gitea 資料庫權限

mysql -u root -p
CREATE USER 'gitea'@'localhost' IDENTIFIED BY 'newpassword';
GRANT ALL PRIVILEGES ON gitea.* TO 'gitea'@'localhost';

安裝 gitea

使用一般 user 登入

mkdir gitea
cd gitea
wget -O gitea https://dl.gitea.io/gitea/1.3.2/gitea-1.3.2-linux-amd64
chmod +x gitea
./gitea web

測試 http://{your_ip}:3000

第一個註冊使用者為最高權限

安裝 nginx

sudo apt-get install nginx

在 /etc/nginx/sites-available 建立一個網站設定檔 gitea.conf

vi gitea.conf

server {
        listen 80;
        listen [::]:80;
        server_name your.host.name;

        root /var/www/html;
        index index.html;
        location / {
                proxy_pass http://127.0.0.1:3000;
        }

連結到啟動區 並移除預設網站 重新啟動 nginx

cd /etc/nginx/site-enable
sudo ln -s ../sites-available/gitea.conf gitea.conf
sudo rm default
sudo systemctl restart nginx

設置 https

安裝 certbot 並執行 certbot

sudo apt-get install python-certbot-nginx
sudo certbot --authenticator webroot --installer nginx

gitea 關閉註冊

cd gitea/custom/conf/
vi app.ini

DISABLE_REGISTRATION  = true

改為服務啟動

/etc/system/gitea.service

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

[Service]
Type=simple
User=alexw
WorkingDirectory=/home/your_id/gitea/
ExecStart=/home/your_id/gitea/gitea web
Restart=always
RestartSec=2s

[Install]
WantedBy=multi-user.target

啟動服務

sudo systemctl start gitea.service

設定開機自動啟動服務

sudo systemctl enable gitea.service

Leave a Comment