(一)gitblit安装教程

(一)gitblit安装教程
(二) gitblit用户使用教程
(三) gitblit管理员手册

目录

  • 前言
  • 安装
    • 1.下载
      • Java Runtime Requirement
    • 2.设置环境变量
    • 3.gitblit内容
      • 3.1 gitblit文件夹内容
      • 3.2 defaults.properties 主要配置选项
    • 4 配置
      • 4.1 准备文件
      • 4.2 修改gitblit.properties
      • 4.3 修改authority.sh
      • 4.4 修改gitblit.sh
    • 5.生成SSL证书
      • 5.1`new certificate defaults`对话框
      • 5.2 password 对话框
      • 5.3 生成SSL证书
    • 6.部署到阿里云服务器ubuntu上.
  • 设置成服务运行
    • 1.修改脚本service-ubuntu.sh
    • 2.安装gitblit服务
    • 3.运行gitblit服务
    • 4.卸载

前言

gitblit和gitlab一样都是git仓库服务器,集中托管仓库.

gitlab一般大公司使用,功能全面,但是配置复杂,一般需要专门人员维护.gitblit在小公司使用,配置比较方便.

另外gitlab需要域名才能使用https,而gitblit使用https不需要申请域名,由于在阿里云上搭建git服务器,出于安全考虑使用https.

考虑简单方便,没有专门人员维护,和安全问题,暂时使用gitblit作为git服务器.

阿里云上ECS使用ubuntu20.04作为平台, 由于没有桌面,不能进行授权(authority)操作,需要先在本地linux桌面平台上进行授权操作,然后把本地的安装复制到阿里云ECS服务器上.

安装

1.下载

gitblit官网http://www.gitblit.com/, 下载Download Gitblit GO (Linux/OSX)版本.

Java Runtime Requirement

Gitblit requires a Java 7 Runtime Environment (JRE) or a Java 7 Development Kit (JDK).

如上摘录官网,gitblit需要java支持,到oracle官网下载jdk-8u381-linux-x64.tar.gz,[https://www.oracle.com/java/technologies/downloads/](https://www.oracle.com/java/technologies/downloads/

把gitblt和java安装包复制到本地ubuntu或ubuntu虚拟机中.

.
├── gitblit-1.9.3.tar.gz
└── jdk-8u381-linux-x64.tar.gz

解压文件

tar -zxf jdk-8u381-linux-x64.tar.gz
tar -zxf gitblit-1.9.3.tar.gz

生成如下目录

/home/bin/
├── gitblit-1.9.3
└── jdk1.8.0_381

2.设置环境变量

设置环境变量

vim ~/.bashrc

export JAVA_HOME=/home/bin/jdk1.8.0_381
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:${JRE_HOME}/lib/security
export PATH=${JAVA_HOME}/bin:$PATH

使环境变量有效 source ~/.bashrc

检查java jdk是否安装成功

java -version
javac -version

显示版本信息说明安装成功

3.gitblit内容

按照如下导航可以查看安装步骤
(一)gitblit安装教程_第1张图片接下来的配置和安装都是参考这个文档.

3.1 gitblit文件夹内容

.
├── add-indexed-branch.sh
├── authority.sh
├── data
├── docs
├── ext
├── gitblit.jar
├── gitblit.sh
├── gitblit-stop.sh
├── install-service-centos.sh
├── install-service-fedora.sh
├── install-service-freebsd.sh
├── install-service-ubuntu.sh
├── java-proxy-config.sh
├── LICENSE
├── migrate-tickets.sh
├── NOTICE
├── reindex-tickets.sh
├── service-centos.sh
├── service-freebsd.sh
└── service-ubuntu.sh

比较重要的文件和文件夹是:authority.sh,gitblit.sh,data/

authority.sh内容

#!/bin/bash
java -cp "gitblit.jar:ext/*" com.gitblit.authority.GitblitAuthority --baseFolder data

gitblit.sh

#!/bin/bash
java -cp "gitblit.jar:ext/*" com.gitblit.GitBlitServer --baseFolder data

data/文件夹内容

data/
├── certs
├── defaults.properties
├── git
├── gitblit.properties
├── gitignore
├── groovy
├── projects.conf
└── users.conf

gitblit.properties
`

#
# GITBLIT.PROPERTIES
#
# Define your custom settings in this file and/or include settings defined in
# other properties files.
#

# Include Gitblit's 'defaults.properties' within your configuration.
#
# NOTE: Gitblit will not automatically reload "included" properties.  Gitblit
# only watches the 'gitblit.properties' file for modifications.
#
# Paths may be relative to the ${baseFolder} or they may be absolute.
#
# COMMA-DELIMITED
# SINCE 1.7.0
include = defaults.properties

#
# Define your overrides or custom settings below
#

可见gitblit.properties调用defaults.properties.

3.2 defaults.properties 主要配置选项

# Base folder for repositories.
# This folder may contain bare and non-bare repositories but Gitblit will only
# allow you to push to bare repositories.
# Use forward slashes even on Windows!!
# e.g. c:/gitrepos
#
# SINCE 0.5.0
# RESTART REQUIRED
# BASEFOLDER
git.repositoriesFolder = ${baseFolder}/git

# Location of Groovy scripts to use for Pre and Post receive hooks.
# Use forward slashes even on Windows!!
# e.g. c:/groovy
#
# RESTART REQUIRED
# SINCE 0.8.0
# BASEFOLDER
groovy.scriptsFolder = ${baseFolder}/groovy

# Specify the directory Grape uses for downloading libraries.
# http://groovy.codehaus.org/Grape
#
# RESTART REQUIRED
# SINCE 1.0.0
# BASEFOLDER
groovy.grapeFolder = ${baseFolder}/groovy/grape

# Either the full path to a user config file (users.conf)
# OR a fully qualified class name that implements the IUserService interface.
#
# Any custom user service implementation must have a public default constructor.
#
# SINCE 0.5.0
# RESTART REQUIRED
# BASEFOLDER
realm.userService = ${baseFolder}/users.conf

# You may specify a different logo image for the header but it must be 120x45px.
# If the specified file does not exist, the default Gitblit logo will be used.
#
# SINCE 1.3.0
# BASEFOLDER
web.headerLogo = ${baseFolder}/logo.png

# Enforce date checks on client certificates to ensure that they are not being
# used prematurely and that they have not expired.
#
# SINCE 1.2.0
git.enforceCertificateValidity = true

# Specify the list of acceptable transports for pushes.
# If this setting is empty, all transports are acceptable.
#
# Valid choices are: GIT HTTP HTTPS SSH
#
# SINCE 1.5.0
# SPACE-DELIMITED
git.acceptedPushTransports = HTTP HTTPS SSH


# Allow an authenticated user to create a destination repository on a push if
# the repository does not already exist.
#
# Administrator accounts can create a repository in any project.
# These repositories are created with the default access restriction and authorization
# control values.  The pushing account is set as the owner.
#
# Non-administrator accounts with the CREATE role may create personal repositories.
# These repositories are created as VIEW restricted for NAMED users.
# The pushing account is set as the owner.
#
# SINCE 1.2.0
git.allowCreateOnPush = true

# Require admin authentication for the admin functions and pages
#
# SINCE 0.5.0
# RESTART REQUIRED
web.authenticateAdminPages = true

# Allow deletion of non-empty repositories. This is enforced for all delete vectors.
#
# SINCE 1.6.0
web.allowDeletingNonEmptyRepositories = true

#
# Gitblit Web Settings
#
# If blank Gitblit is displayed.
#
# SINCE 0.5.0
web.siteName =

# Standard http port to serve.  <= 0 disables this connector.
# On Unix/Linux systems, ports < 1024 require root permissions.
# Recommended value: 80 or 8080
#
# SINCE 0.5.0
# RESTART REQUIRED
server.httpPort = 0

# Specify the interface for Jetty to bind the standard 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.httpBindInterface =

# Secure/SSL https port to serve. <= 0 disables this connector.
# On Unix/Linux systems, ports < 1024 require root permissions.
# Recommended value: 443 or 8443
#
# SINCE 0.5.0
# RESTART REQUIRED
server.httpsPort = 8443

# 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 =

# 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

# Password for SSL keystore.
# Keystore password and certificate password must match.
# This is provided for convenience, its probably more secure to set this value
# using the --storePassword command line parameter.
#
# If you are using the official JRE or JDK from Oracle you may not have the
# JCE Unlimited Strength Jurisdiction Policy files bundled with your JVM.  Because
# of this, your store/key password can not exceed 7 characters.  If you require
# longer passwords you may need to install the JCE Unlimited Strength Jurisdiction
# Policy files from Oracle.
#
# http://www.oracle.com/technetwork/java/javase/downloads/index.html
#
# Gitblit and the Gitblit Certificate Authority will both indicate if Unlimited
# Strength encryption is available.
#
# SINCE 0.5.0
# RESTART REQUIRED
server.storePassword = gitblit

4 配置

配置目标:

  1. 把配置信息和git仓库放在数据盘中,并且分别存放,方便维护用户信息和git仓库.
  2. 只使用开启https访问
  3. git仓库访问支持所有方式,例如https,git,ssh等.

4.1 准备文件

mkdir -p /data/gitblit/
cp -ravf /home/bin/gitblit-1.9.3/data/ /data/gitblit/
cd /data/gitblit/data
mv git ../

4.2 修改gitblit.properties

vim /data/gitblit/data/gitblit.properties

git.acceptedPushTransports =
web.siteName =
git.repositoriesFolder = ${baseFolder}/../git
web.allowDeletingNonEmptyRepositories = false

4.3 修改authority.sh

vim /home/bin/gitblit-1.9.3/authority.sh

#!/bin/bash
java -cp "gitblit.jar:ext/*" com.gitblit.authority.GitblitAuthority --baseFolder /data/gitblit/data

4.4 修改gitblit.sh

vim /home/bin/gitblit-1.9.3/gitblit.sh

#!/bin/bash
java -cp "gitblit.jar:ext/*" com.gitblit.GitBlitServer --baseFolder /data/gitblit/data

5.生成SSL证书

一定要在ubuntu内部运行命令,不能使用ssh远程访问.

cd /home/bin/gitblit-1.9.3
./authority.sh

5.1new certificate defaults对话框

(一)gitblit安装教程_第2张图片
validity中输入36500天,按OK按钮

5.2 password 对话框

(一)gitblit安装教程_第3张图片

输入server.storePassword对于的密码,按OK按钮.

5.3 生成SSL证书

(一)gitblit安装教程_第4张图片
如图点击红色按钮,弹出如下对话框
(一)gitblit安装教程_第5张图片
hostname: 输入阿里云公网IP地址

expires:设置有效日期

serve https with this certificate:确定选上.

点击OK,提示生成SSL证书
(一)gitblit安装教程_第6张图片

6.部署到阿里云服务器ubuntu上.

.bashrc,jdk,gitblit和gitblit配置文件全部复制到服务器上即可.

设置成服务运行

需要把gitblit设置成守护进程运行,不然关闭远程连接控制台gitblit就会停止.

1.修改脚本service-ubuntu.sh

#1.设置用户信息目录
GITBLIT_BASE_FOLDER=/data/gitblit/data

#2.设置java,使用deb包安装不需要java设置
#在PATH=/sbin:/bin:/usr/bin:/usr/sbin后面增加
JAVA_HOME=/home/bin/jdk1.8.0_381
JRE_HOME=${JAVA_HOME}/jre
CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:${JRE_HOME}/lib/security
PATH=${JAVA_HOME}/bin:$PATH

#3./usr/bin/java 替换成 你安装 java 绝对路径 ${JAVA_HOME}/bin/java

#4.设置gitblit应用程序目录
GITBLIT_PATH=/home/bin/gitblit-1.9.3

#5.修改用户
#也可以保持gitblit用户,需要使用useradd或者adduser工具建立这个用户.
GITBLIT_USER="root"

2.安装gitblit服务

./install-service-ubuntu.sh

3.运行gitblit服务

sudo service gitblit restart
#查看运行状态
sudo service gitblit status

4.卸载

#停止服务
sudo service gitblit stop

#卸载服务
cd /etc/init.d/
sudo rm gitblit 
sudo update-rc.d gitblit remove

#删除gitblit应用程序
rm -rvf /home/bin/gitblit-1.9.3
#删除gitblit配置文件和git库
rm -rvf /data/gitblit

你可能感兴趣的:(git,git)