ユーザ用ツール

サイト用ツール


git:gitbucket

文書の過去の版を表示しています。


gitbucket

インストール

tomcat

GitBucket起動時にtomcatユーザのホームディレクトリをworkに設定するので、ディレクトリがないとエラーになります。 事前にユーザ作成を行っておくのが無難です。

# useradd -s /bin/false tomcat

インストール時にyum-plugin-prioritiesを要求されるので、事前にインストールします。

# yum install -y yum-plugin-priorities

公式リポジトリを追加してtomcatをインストールします。

# rpm -Uvh http://mirrors.dotsrc.org/jpackage/6.0/generic/free/RPMS/jpackage-release-6-3.jpp6.noarch.rpm
# yum install -y --nogpgcheck tomcat7-webapps tomcat7-admin-webapps

gitbucket

webappsディレクトリにgitbucket(warファイル)をDLします。

# cd /var/lib/tomcat7/webapps/
# wget https://github.com/takezoe/gitbucket/releases/download/3.2/gitbucket.war

apacheと連携するために、httpの8080ポートはコメントアウトして、ajpポートを8009→8089に変更します。 ※ajpポートの変更は、セットアップした環境の他のサービスと重複しているため。

# cp -a /etc/tomcat7/server.xml /etc/tomcat7/server.xml.bk
# vi /etc/tomcat7/server.xml

70d69
<     <!--
74d72
<     -->
94d91
<     <!--
96,97d92
<     -->
<     <Connector port="8089" protocol="AJP/1.3" redirectPort="8443" />

apacheのconfファイルを作成します。

# vi /etc/httpd/conf.d/gitbucket.conf

ProxyPass /gitbucket ajp://localhost:8089/gitbucket
ProxyPassReverse /gitbucket ajp://localhost:8089/gitbucket
ProxyRequests Off

サービス起動します。

# service tomcat7 start
# /etc/init.d/httpd restart

http://SERVER/gitbucket/ root / root

ユーザ設定

SSHキーを作成する。

# ssh-keygen                                                          
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): ←何も入力せずにEnter
Enter same passphrase again: ←何も入力せずにEnter
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
15:d8:0b:a9:d0:79:31:ff:7d:0d:8b:72:8c:33:51:22 root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|     . .E=o .    |
|    . o =+.+     |
|     . o .+.  .  |
|      .  ..= o o.|
|        S = = o o|
|           =   . |
|                 |
|                 |
|                 |
+-----------------+

作成したSSHキーを確認する。

# cat .ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAA ~省略~ cfapXHhBTa38zp50vS546sC+JB8vBXjG1Q== root@localhost.localdomain

GitBucketにログインする 右上のAccount Settings(人の影)をクリック 左のメニューからSSH Keysをクリック Add an SSH KeyのTitleは適当、Keyは作成したSSHキーを張り付ける。 以後のgitの操作はSSH接続で行う。 任意のリポジトリを開き、右の「HTTP clone URL」の項目でSSHをクリックすると、SSH接続のURLが表示されます。

Tips

CentOS6環境でコマンドラインからPUSHするとエラーになる

http経由でGitBucketにPUSHする際、デフォルトの設定では、匿名ユーザでアクセスしようとしてエラーが発生します。

[root@localhost pj]# git push                                                          
error: Cannot access URL http://192.168.56.14/gitbucket/git/user/pj.git/, return code 22
fatal: git-http-push failed

設定を変更してユーザ認証を強制することで、現象の回避が可能です。

  • 現在の設定を確認
    # git config -l                                                     
    ~省略~
    remote.origin.url=http://192.168.56.14/gitbucket/git/user/pj.git
  • 認証ユーザの設定
    git config remote.origin.url http://user@192.168.56.14/gitbucket/git/user/pj.git
  • push
    # git push
    Password: userのパスワード
    Counting objects: 5, done.
    Writing objects: 100% (3/3), 243 bytes, done.
    Total 3 (delta 0), reused 0 (delta 0)
    remote: Updating references: 100% (1/1)
    To http://user@192.168.56.14/gitbucket/git/user/pj.git
       6282168..78800c3  master -> master
    Edit

バックアップ

ユーザ直下の.gitbucketディレクトリを丸ごと保存。

# tar zcf /home/tomcat/gitbucket-`date +%Y-%m-%d`.tar.gz /home/tomcat/.gitbucket

必要なときに展開して設置。

# tar zxvf /home/tomcat/gitbucket-2015-05-15.tar.gz

jenkinsに定義して自動バックアップする。

  • jenkinsユーザにsudo権限付与(設定しないと、/home/tomcat/配下にアクセスできないのでエラーになる)
    # visudo
    
    コメントアウト
    #Defaults    requiretty
    
    追加
    jenkins ALL=(ALL)       NOPASSWD: /bin/ls, /bin/tar
  • jennkinsの「シェルの実行」に定義
    sudo tar zcf /var/backup/gitbucket-`date +%Y%m%d%H%M%S`.tar.gz /home/tomcat/.gitbucket

リストア

適当な場所で解凍して、オリジナルの場所に設置・上書きします。

# mkdir /tmp/_backup
# chmod 777 /tmp/_backup
# cd  /tmp/_backup

[_backup]# tar xzvf gitbucket-20150608093100.tar.gz 

[_backup]# /etc/init.d/tomcat7 stop
[_backup]# \cp -ar /tmp/_backup/home/tomcat/.gitbucket /home/tomcat/
[_backup]# /etc/init.d/tomcat7 start
[_backup]# /etc/init.d/httpd restart
git/gitbucket.1433732333.txt.gz · 最終更新: 2025/02/16 13:50 (外部編集)