■Squeezeにgitサーバを立てる
「SOURCEFORGE.JP」には、所属プロジェクトに上げる前に、
「作業部屋」を使うことでワンクッション置く事が出来る。
この作業部屋の更にワンクッション置く為に、練習用のgitサーバを立てる。
上記によって、作業部屋を練習台に使わなくて済むようになる。
gitサーバはsqueeze(仮想マシンのNAT環境)とする。
gitクライアントはsqueeze(ローカル)/lenny(もう一台の仮想マシン/サーバと同じNAT環境)とする。
■squeezeに導入
$ sudo apt-get install git-core git-daemon-run
■デーモンとして稼動、ポート「9418」の確認(sshの場合は使わない)
$ ps -ef | grep git-daemon | grep -v grep | cut -c 49-
runsv git-daemon
svlogd -tt /var/log/git-daemon
/usr/lib/git-core/git-daemon --verbose --reuseaddr --base-path=/var/cache /var/cache/git
$ grep 9418 /etc/services
git 9418/tcp
$ netstat -an | grep 9418 | grep -v tcp6
tcp 0 0 0.0.0.0:9418 0.0.0.0:* LISTEN
■「git-daemon-run」(gitサーバ)を確認
$ apropos git-daemon
git-daemon (1) - A really simple server for git repositories
$ dpkg -L git-daemon-run | grep '/etc/sv/'
/etc/sv/git-daemon
/etc/sv/git-daemon/run
/etc/sv/git-daemon/log
/etc/sv/git-daemon/log/run
$ grep base /etc/sv/git-daemon/run
--base-path=/var/cache /var/cache/git
$ ls -ld /var/cache/git
drwxr-xr-x 2 root root 4096 2011-09-23 06:26 /var/cache/git
□gitユーザの作成がまだなら
$ GITACCOUNT=gituser
$ sudo adduser --home /var/cache --no-create-home ${GITACCOUNT}
$ sudo passwd ${GITACCOUNT}
■「/var/cache/git」にアクセスする設定
$ sudo mkdir /var/cache/git/${GITACCOUNT}
$ sudo chown -R ${GITACCOUNT}:${GITACCOUNT} /var/cache/git/${GITACCOUNT}
$ cd /var/cache/git/${GITACCOUNT}
$ git clone --bare smallfirewall smallfirewall.git
Cloning into bare repository smallfirewall.git...
warning: You appear to have cloned an empty repository.
□2012/06/19追記---start
アップデート用の設定
$ touch /var/cache/git/${GITACCOUNT}/git-daemon-export-ok
$ git push ssh://${GITACCOUNT}@`hostname -f`:22/var/cache/git/${GITACCOUNT}/smallfirewall.git master
$ man git-daemon | grep -A 3 " \-\-export\-all\$"
--export-all
Allow pulling from all directories that look like GIT repositories
(have the objects and refs subdirectories), even if they do not
have the git-daemon-export-ok file.
□2012/06/19追記---end
■自サーバへのアクセス方法
git [command] ssh://`hostname -s`/var/cache/git/labunix/smallfirewall.git
■ローカルクライアントからのアクセス
$ git config --global user.name "labunix"
$ git config --global user.email "labunix@`hostname -f`"
$ mkdir git_work;cd git_work
$ git clone ssh://labunix@`hostname -s`/var/cache/git/labunix/smallfirewall.git
Cloning into smallfirewall...
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 13 (delta 3), reused 0 (delta 0)
Receiving objects: 100% (13/13), 977 bytes, done.
Resolving deltas: 100% (3/3), done.
$ cd smallfirewall
$ echo 1 > new
$ git add new
$ git commit new -m "test 1"
[master (root-commit) e9307c7] test 1
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 new
$ git push ssh://labunix@`hostname -s`/var/cache/git/labunix/smallfirewall.git
Counting objects: 6, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 479 bytes, done.
Total 5 (delta 1), reused 0 (delta 0)
To ssh://labunix@xxxxx/var/cache/git/labunix/smallfirewall.git
9eb41c9..c9136d7 master -> master
■lennyからのアクセス
$ sudo apt-get install git-core
$ git config --global user.name "labunix"
$ git config --global user.email "labunix@`hostname -f`"
$ mkdir git_work;cd git_work
$ git clone ssh://labunix@${SQUEEZE-IP}/var/cache/git/labunix/smallfirewall.git
$ echo "from lenny" > hello.world
$ git add hello.world
$ git commit -a -m "Hello squeeze ,from lenny"
Created commit ee79d24: Hello squeeze ,from lenny
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 hello.world
$ git push
labunix@squeeze password:
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 364 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To ssh://squeeze/var/cache/git/labunix/smallfirewall.git
533c3fa..ee79d24 master -> master
■squeezeからの取得、変更
$ git pull
labunix@squeeze password:
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From ssh://squeeze/var/cache/git/labunix/smallfirewall
533c3fa..ee79d24 master -> origin/master
Updating 533c3fa..ee79d24
Fast-forward
hello.world | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 hello.world
$ cat hello.world
from lenny
$ echo "from squeeze" > hello.world
$ git add .
$ git commit -a -m "Hello Lenny ,from squeeze"
[master b38ce14] Hello Lenny ,from squeeze
1 files changed, 1 insertions(+), 1 deletions(-)
■Lennyからの取得
$ git pull
labunix@xxxxxs password:
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From ssh://192.168.132.169/var/cache/git/labunix/smallfirewall
ee79d24..b38ce14 master -> origin/master
Updating ee79d24..b38ce14
Fast forward
hello.world | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
$ cat hello.world
from squeeze
■Lenny/squeezeからのログの取得
どちらも最新であれば、同じ表示になるはず。
$ git log | awk '{print}'
commit b38ce14d0df2eee739d5c3c4d78eb68243ebc074
Author: labunix <labunix@squeeze.localdomain>
Date: Sat Feb 25 21:38:00 2012 +0900
Hello Lenny ,from squeeze
■smallfirewallでgitのポートの通信をDROPする。
「/etc/smallfirewall」内でデフォルトのiptablesコマンドが記述出来るよう配慮した。
※今のところsqueeze専用。
lennyや、CentOSでは修正が必要だが、動作する事は確認済み。
修正しなくても動作するよう調整中。
http://labunix.hateblo.jp/entry/2012/02/25/223816
iptables -A INPUT -p tcp --dport 9418 -j DROP
iptables -A OUTPUT -p tcp --sport 9418 -j DROP