红联Linux门户
Linux帮助

Ubuntu 16.04安装Bitbucket Server

发布时间:2016-09-19 09:40:26来源:topspeedsnail.com作者:斗大的熊猫
BitBucket是一个兼容Github API的git平台,使用它可以快速搭建自己的Github。BitBucket是使用Scala开发的开源软件,非常容易安装,界面和Github类似,还支持插件。
BitBucket源代码:https://github.com/gitbucket/gitbucket
 
Ubuntu 16.04 安装 Bitbucket
本文使用Nginx做GitBucket的反向代理。
安装依赖:
$ sudo apt install software-properties-common git vim wget
安装Java:
$ sudo apt install default-jdk default-jre
要安装Oracle Java,Ubuntu 16.04 安装 Oracle JDK9:
$ sudo apt install python-software-properties software-properties-common
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt update
$ sudo apt install oracle-java9-installer
Ubuntu 16.04安装Bitbucket Server
 
创建一个新用户,专门用来运行GitBucket:
$ sudo adduser --gecos 'GitBucket User' gitbucket
下载GitBucket;从Github(https://github.com/gitbucket/gitbucket/releases)下载最新版的gitbucket.war文件:
$ sudo wget -O /home/gitbucket/gitbucket.war https://github.com/gitbucket/gitbucket/releases/download/4.4/gitbucket.war
$ sudo chown -R gitbucket: /home/gitbucket
 
创建systemd服务,方便管理GitBucket:
$ sudo vim /etc/systemd/system/gitbucket.service
写入:
[Unit]
Description=GitBucket Service
After=syslog.target
After=network.target
[Service]
User=gitbucket
ExecStart=/usr/bin/java -jar /home/gitbucket/gitbucket.war --port=8080 --host=127.0.0.1
[Install]
WantedBy=multi-user.target
 
启动GitBucket:
$ sudo systemctl enable gitbucket
$ sudo systemctl start gitbucket
Ubuntu 16.04安装Bitbucket Server
可访问127.0.0.1:8080测试。
 
安装Nginx:
$ sudo apt install nginx
如果你没有其它SSL证书,使用自签名SSL证书:
$ sudo mkdir -p /etc/nginx/ssl
$ cd /etc/nginx/ssl
$ sudo openssl genrsa -des3 -passout pass:x -out gitbucket.pass.key 2048
$ sudo openssl rsa -passin pass:x -in gitbucket.pass.key -out gitbucket.key
$ sudo rm gitbucket.pass.key
$ sudo openssl req -new -key gitbucket.key -out gitbucket.csr
$ sudo openssl x509 -req -days 365 -in gitbucket.csr -signkey gitbucket.key -out gitbucket.crt
$ sudo openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
 
配置Nginx:
$ sudo vim /etc/nginx/sites-available/gitbucket.conf
写入如下内容:
server {
listen 443 ssl http2;
server_name your_domain.com;
location / {
proxy_pass              http://127.0.0.1:8080;
proxy_set_header        Host $host;
proxy_set_header        X-Real-IP $remote_addr;
proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout   150;
proxy_send_timeout      100;
proxy_read_timeout      100;
proxy_buffers           4 32k;
client_max_body_size    500m; # Big number is we can post big commits.
client_body_buffer_size 128k;
}
ssl on;
ssl_certificate     /etc/nginx/ssl/gitbucket.crt;
ssl_certificate_key /etc/nginx/ssl/gitbucket.key;
ssl_dhparam  /etc/nginx/ssl/dhparam.pem;
ssl_session_timeout 5m;
ssl_ciphers  EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
access_log  /var/log/nginx/gitbucket.access.log;
error_log   /var/log/nginx/gitbucket.error.log;
}
server {
listen      80;
server_name your_domain.com;
add_header Strict-Transport-Security max-age=2592000;
rewrite ^ https://$server_name$request_uri? permanent;
}
注意替换上面的域名。
 
使生效:
$ sudo ln -s /etc/nginx/sites-available/gitbucket.conf /etc/nginx/sites-enabled/gitbucket.conf
# $ sudo nginx -t
$ sudo systemctl restart nginx
测试,使用浏览器访问https://your_domain.com:
Ubuntu 16.04安装Bitbucket Server
默认管理员用户root,密码root。
Ubuntu 16.04安装Bitbucket Server
 
本文永久更新地址:http://www.linuxdiyf.com/linux/24279.html