1 sqlite3

系统自带的版本太低需要升级

1.1 编译

1
2
3
4
5
wget https://sqlite.org/2022/sqlite-autoconf-3380000.tar.gz
tar -zxvf sqlite-autoconf-3380000.tar.gz
cd sqlite-autoconf-3380000
./configure --prefix=/usr/local
make && make install

1.2 替换

1
2
3
4
5
6
7
mv /usr/bin/sqlite3 /usr/bin/sqlite3_old
ln -s /usr/local/bin/sqlite3 /usr/bin/sqlite3
echo "/usr/local/lib" > /etc/ld.so.conf.d/sqlite3.conf
ldconfig
sqlite3 -version
3.38.0 2022-02-22 18:58:40 40fa792d359f84c3b9e9d6623743e1a59826274e221df1bde8f47086968a1bab
rm -rf /usr/bin/sqlite3_old

2 git

2.1 下载

1
2
3
wget -O gitea https://dl.gitea.io/gitea/1.16.3/gitea-1.16.3-linux-amd64
chmod +x gitea
sudo mv gitea /usr/local/bin/

2.2 添加用户

1
2
3
4
5
6
7
useradd \\
--system \\
--shell /bin/bash \\
--comment 'Git Version Control' \\
--create-home \\
--home /home/git \\
git

2.3 配置路径

1
2
3
4
5
6
7
8
sudo mv /tmp/gitea /usr/local/bin
sudo mv gitea /usr/local/bin/
sudo mkdir -p /var/lib/gitea/{custom,data,indexers,public} /var/log/gitea/
sudo chown git: /var/lib/gitea/{data,indexers} /var/log/gitea/
sudo chmod 750 /var/lib/gitea/{data,indexers}
sudo mkdir /etc/gitea
sudo chown root:git /etc/gitea
sudo chmod 770 /etc/gitea

2.4 配置 system

cat /etc/systemd/system/gitea.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target

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

[Install]
WantedBy=multi-user.target

2.5 启动服务

systemctl start gitea

systemctl enable gitea

3 Nginx 代理+ssl

cat /etc/nginx/conf.d/gitea.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
server {
listen 80;
server_name git.ccops.cc;
return 301 https://xx.ink$request_uri;
}
server {
listen 443 ssl http2;
server_name xx.ink;
proxy_read_timeout 720s;
proxy_connect_timeout 720s;
proxy_send_timeout 720s;
client_max_body_size 50m;

proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;

ssl_certificate /etc/nginx/cert/xx.crt; # 证书路径
ssl_certificate_key /etc/nginx/cert/xx.key; # key路径
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
#表示使用的加密套件的类型。
ssl_protocols TLSv1.2; #表示使用的TLS协议的类型。
ssl_prefer_server_ciphers on;
# 日志
access_log /var/log/nginx/git.ccops.cc.access.log;
error_log /var/log/nginx/git.ccops.cc.error.log;

# 转发
location / {
proxy_redirect off;
proxy_pass http://127.0.0.1:3000;
}
}

nginx -s reload

配置好 dns 访问,然后初始化 gitea,直接按照页面操作就可以比较简单

4 配置 git ssh

4.1 配置 gitea 的 ssh 服务

vim /etc/gitea/app.ini

1
2
3
4
5
6
7
8
9
10
11
12
[server]
SSH_DOMAIN = xx.ink
DOMAIN = xx.ink
HTTP_PORT = 3000
ROOT_URL = https://xx.ink/
DISABLE_SSH = false
SSH_PORT = 23 # 配置gitea自己的ssh端口,别与22冲突
LFS_START_SERVER = true
LFS_CONTENT_PATH = /var/lib/gitea/data/lfs
LFS_JWT_SECRET = Ic8_Io65nzi0xYnjbJAL3K882GDlfJZn4yiP6HEC1lc
OFFLINE_MODE = true
START_SSH_SERVER = true # 开启gitea自己的ssh

4.2 配置秘钥

ssh-keygen -t rsa -b 2048

4.2.1 拷贝结果

1
2
cat .ssh/id_rsa.pub
ssh-rsaxxxxxxxxxxxxogWoqz/260LjowF xxxx@x

image-20220330093833579

5 客户端使用 ssh

一定要有私钥**~/.ssh/id_rsa**

1
2
git config --global user.email "xx@xx.com"
git config --global user.name "xx"

5.1 测试

git clone ssh://git@xx.xx:23/test/new.git

以下结果表示正常

1
2
3
4
5
6
Cloning into 'new'...
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 8 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (8/8), done.