gitblit更新慢,功能支持少,不推荐
下载先到官网 下载Gitblit,
因为平台是Ubuntu 20.04 LTS,所以我们选择Download Gitblit GO (Linux/OSX)这个按钮下载Linux版。
当然,国外网站下载有点慢。
下载完成后将其上传到服务器上。
服务器资源占用
配置进入gitblit-1.9.3/data目录
会发现defaults.properties,这个是默认配置文件,我们将其复制一份并重命名为feater.top.properties。
并修改其内容
1 2 3 4 5 server.httpPort = 8080 ... server.httpBindInterface =
httpPort根据喜好修改
在服务器中执行命令
只有两个网卡,一个是localhost,一个是10.0开头IP,这个明显是局域网IP,但是腾讯云服务器都是提供官网IP的,也就是说这个中间有NAT的过程。
httpBindInterface值修改为局域网IP
进入服务器控制中心,放开指定端口
如果服务器安装了其他防火墙软件也要一并放开。
运行使用自定义配置文件
在gitblit/data目录中有gitblit.properties文件,其内容为
可见默认使用的配置文件是default.properties我们需要把它改为自定义的文件名。
Gitblit运行依赖Java8,先安装
1 sudo apt install openjdk-8-jdk
测试命令
服务器资源占用
域名访问此时Gitblit的基本环境算是搭完了,但是只能通过ip:port来访问。
本部分我们来通过域名访问gitblit内容
本站使用的是Nginx,所以在/etc/nginx/sites-enabled/default中增加
1 2 3 4 5 6 7 8 9 10 11 12 server{ listen 80; server_name git.feater.top; location / { proxy_pass http://10.0.4.15:8080/; proxy_set_header HOST $host; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
即把从外部访问http://git.feater.top
的请求重定向给http://10.0.4.15:8080/
,重定向的ip和端口就是gitblit配置文件中配置的http相关配置。
访问效果为
https访问在git.feater.top.properties中修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # Specify the interface for Jetty to bind the secure connector. # You may specify an ip or an empty value to bind to all interfaces. # Specifying localhost will result in Gitblit ONLY listening to requests to # localhost. # # SINCE 0.5.0 # RESTART REQUIRED server.httpsBindInterface = localhost # Alias of certificate to use for https/SSL serving. If blank the first # certificate found in the keystore will be used. # # SINCE 1.2.0 # RESTART REQUIRED server.certificateAlias = localhost
在nginx中配置
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 36 37 38 server{ listen 443 ; server_name git.feater.top; ssl_certificate /etc/ssl/certs/git.feater.top_nginx/git.feater.top_bundle.pem; ssl_certificate_key /etc/ssl/certs/git.feater.top_nginx/git.feater.top.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3 ; ssl_ciphers "TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-256-GCM-SHA384:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DSS" ; ssl_prefer_server_ciphers on ; ssl_session_timeout 1d ; ssl_session_cache shared:SSL:50m ; ssl_session_tickets on ; ssl_buffer_size 1400 ; ssl_stapling on ; ssl_stapling_verify on ; location / { proxy_pass https://localhost:8443/; proxy_set_header HOST $host ; proxy_set_header X-Forwarded-Proto $scheme ; proxy_set_header X-Real-IP $remote_addr ; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ; } }
然后就可以通过https访问了
ssh访问在gitblit中添加ssh公钥,然后clone地址,会提示
1 2 3 4 5 6 7 $ git clone ******.git Cloning into '***' ... Unable to negotiate with ip port : no matching host key type found. Their offer: ssh-rsa,ssh-dss fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
在操作系统的默认.ssh密钥存储目录,我的是/home/jackey/.ssh,添加config文件,内容是
1 2 3 4 5 6 7 Host git.feater.top HostName git.feater.top User jackey Port ** IdentityFile /home/jackey/.ssh/id_rsa HostKeyAlgorithms ssh-rsa PubkeyAcceptedKeyTypes ssh-rsa
开机启动添加或编辑/etc/systemd/system/multi-user.target.wants/gitblit.service
1 2 3 4 5 6 7 8 9 10 11 12 13 [Unit] Description=Gitblit Service [Service] Type=forking PrivateTmp=true ExecStart=sh /home/ubuntu/gitblit-1.9.3/start-gitblit.sh ExecStop=sh /home/ubuntu/gitblit-1.9.3/stop-gitblit.sh ExecReload=sh /home/ubuntu/gitblit-1.9.3/reload-gitblit.sh ExecRestart= sh /home/ubuntu/gitblit-1.9.3/reload-gitblit.sh [Install] WantedBy=multi-user.target