LoginSignup
1
3

More than 5 years have passed since last update.

CentOSに gitbucket をインストールする

Posted at

個人的なメモ。

  • jdk インストール
  • tomcat インストール
  • gitbucket インストール
  • firewall(iptables)設定

jdk インストール

sudo  yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel-1.8.0-devel

標準リポジトリになければepelリポジトリから追加する。

tomcat インストール

バイナリをダウンロードして配置する

cd /usr/local/src
sudo wget http://ftp.tsukuba.wide.ad.jp/software/apache/tomcat/tomcat-8/v8.5.9/bin/apache-tomcat-8.5.9.tar.gz
sudo tar -xvzf apache-tomcat-8.5.9.tar.gz
sudo useradd -r tomcat8 --shell /bin/false
sudo mv apache-tomcat-8.5.9 /usr/local/tomca8
sudo chown -R tomcat8 /usr/local/tomca8

サービス起動スクリプトを作成

sudo vi /etc/init.d/tomcat8

内容は以下

#!/bin/bash
#
# tomcat8
#
# chkconfig: - 80 20
#
### BEGIN INIT INFO
# Provides: tomcat8
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start:
# Default-Stop:
# Description: Tomcat 8
# Short-Description: start and stop tomcat
### END INIT INFO

## Source function library.
#. /etc/rc.d/init.d/functions
export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/
export JRE_HOME=/usr/lib/jvm/jre-1.8.0-openjdk.x86_64

export JAVA_OPTS="-Dfile.encoding=UTF-8 \
  -Dnet.sf.ehcache.skipUpdateCheck=true \
  -Djava.net.preferIPv4Stack=true  \
  -XX:+UseConcMarkSweepGC \
  -XX:+CMSClassUnloadingEnabled \
  -XX:+UseParNewGC \
  -XX:MaxPermSize=128m \
  -Xms512m -Xmx512m"
export PATH=$JAVA_HOME/bin:$PATH
TOMCAT_HOME=/usr/local/tomcat8
TOMCAT_USER=tomcat8
SHUTDOWN_WAIT=20

tomcat_pid() {
  echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`
}
start() {
  pid=$(tomcat_pid)
  if [ -n "$pid" ]
  then
    echo "Tomcat is already running (pid: $pid)"
  else
    # Start tomcat
    echo "Starting tomcat"
    ulimit -n 100000
    umask 007
    /bin/su -p -s /bin/sh $TOMCAT_USER $TOMCAT_HOME/bin/startup.sh
  fi


  return 0
}
stop() {
  pid=$(tomcat_pid)
  if [ -n "$pid" ]
  then
    echo "Stoping Tomcat"
    /bin/su -p -s /bin/sh $TOMCAT_USER $TOMCAT_HOME/bin/shutdown.sh

    let kwait=$SHUTDOWN_WAIT
    count=0;
    until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
    do
      echo -n -e "\nwaiting for processes to exit";
      sleep 1
      let count=$count+1;
    done

    if [ $count -gt $kwait ]; then
      echo -n -e "\nkilling processes which didn't stop after $SHUTDOWN_WAIT seconds"
      kill -9 $pid
    fi
  else
    echo "Tomcat is not running"
  fi

  return 0
}
case $1 in
start)
  start
;;
stop)
  stop
;;
restart)
  stop
  start
;;
status)
  pid=$(tomcat_pid)
  if [ -n "$pid" ]
  then
    echo "Tomcat is running with pid: $pid"
  else
    echo "Tomcat is not running"
  fi
;;
esac
exit 0

起動スクリプトを実行可能にする

sudo chmod +x /etc/init.d/tomcat8

サービス自動起動設定

sudo chkconfig tomcat8 on

サービス起動

sudo service tomcat8 start

サービス停止

sudo service tomcat8 stop

デフォルトでは起動ポートは8080

gitbucket インストール

  • バイナリ配布サイトから war ファイルをダウンロード
  • warファイルを tomcat webappディレクトリに配置
  • gitbucket データディレクトリを作成し、tomcat8ユーザーが読み書きできるようにする
  • gitbucket/WEB-INF/web.xml を編集し、gitbucket.home の値をgitbucket データディレクトリに設定する

以下のサイトからバイナリ配布サイトから war ファイルをダウンロード
https://github.com/gitbucket/gitbucket/releases

gitbucket データディレクトリを作成し、tomcat8ユーザーが読み書きできるようにする

mkdir /var/gitbucket
chown -R tomcat8 /var/gitbucket

gitbucket/WEB-INF/web.xml を編集し、gitbucket.home の値をgitbucket データディレクトリに設定する
以下を追加する

 <context-param>
    <param-name>gitbucket.home</param-name>
    <param-value>/var/gitbucket</param-value>
  </context-param>

firewall(iptables)設定

AJP でapacheと連携する場合は port 80、tomcat 8080 ポートのままつかうならport8080 へのアクセスを許可する。

CentOS7(firewall-cmdにより許可ポートを追加)

firewall-cmd --add-port=8080

CentOS6(/etc/sysconfig/iptablesを編集し以下を追加する)

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3