PGメモ

非エンジニアの記録

CentOS5.9にGitサーバーを立てる。

意気揚々とgitサーバを立てる事にする・・がパッケージがない。

# yum install git-daemon
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * extras: mirrors.hust.edu.cn
 * updates: ftp.tsukuba.wide.ad.jp
Setting up Install Process
No package git-daemon available.
Nothing to do

レポジトリを追加します。

# vim  /etc/yum.repos.d/epel.repo 
[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 5 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/5/$basearch/debug
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-5&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 5 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/5/SRPMS
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-5&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1

これでどうだ。

# yum install git-daemon

無事パッケージが見つかった。

# yum install git-daemon
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * epel: ftp.kddilabs.jp
 * extras: mirrors.hust.edu.cn
 * updates: ftp.tsukuba.wide.ad.jp
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package git-daemon.i386 0:1.8.2.1-1.el5 set to be updated
--> Processing Dependency: git = 1.8.2.1-1.el5 for package: git-daemon
--> Processing Dependency: xinetd for package: git-daemon
--> Running transaction check
--> Processing Dependency: git = 1.7.10.2-1.w5 for package: emacs-git
--> Processing Dependency: git = 1.7.10.2-1.w5 for package: git-svn
--> Processing Dependency: git = 1.7.10.2-1.w5 for package: git-gui
--> Processing Dependency: git = 1.7.10.2-1.w5 for package: git-email
--> Processing Dependency: git = 1.7.10.2-1.w5 for package: perl-Git
--> Processing Dependency: git = 1.7.10.2-1.w5 for package: git-cvs
--> Processing Dependency: git = 1.7.10.2-1.w5 for package: git-all
--> Processing Dependency: git = 1.7.10.2-1.w5 for package: gitk
---> Package git.i386 0:1.8.2.1-1.el5 set to be updated
---> Package xinetd.i386 2:2.3.14-20.el5_10 set to be updated
--> Running transaction check
---> Package emacs-git.i386 0:1.8.2.1-1.el5 set to be updated
---> Package git-all.i386 0:1.8.2.1-1.el5 set to be updated
--> Processing Dependency: git-p4 = 1.8.2.1-1.el5 for package: git-all
---> Package git-cvs.i386 0:1.8.2.1-1.el5 set to be updated
--> Processing Dependency: perl-DBD-SQLite for package: git-cvs
---> Package git-email.i386 0:1.8.2.1-1.el5 set to be updated
---> Package git-gui.i386 0:1.8.2.1-1.el5 set to be updated
---> Package git-svn.i386 0:1.8.2.1-1.el5 set to be updated
--> Processing Dependency: perl(Git::SVN::Utils) for package: git-svn
--> Processing Dependency: perl(Git::SVN::Ra) for package: git-svn
--> Processing Dependency: perl(Git::SVN::Prompt) for package: git-svn
--> Processing Dependency: perl(Git::SVN::Migration) for package: git-svn
[root@localhost www]# yum install git-daemon
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * epel: ftp.kddilabs.jp
 * extras: mirrors.hust.edu.cn
 * updates: ftp.tsukuba.wide.ad.jp
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package git-daemon.i386 0:1.8.2.1-1.el5 set to be updated
--> Processing Dependency: git = 1.8.2.1-1.el5 for package: git-daemon
--> Processing Dependency: xinetd for package: git-daemon
--> Running transaction check
--> Processing Dependency: git = 1.7.10.2-1.w5 for package: emacs-git
--> Processing Dependency: git = 1.7.10.2-1.w5 for package: git-svn
--> Processing Dependency: git = 1.7.10.2-1.w5 for package: git-gui
--> Processing Dependency: git = 1.7.10.2-1.w5 for package: git-email
--> Processing Dependency: git = 1.7.10.2-1.w5 for package: perl-Git
--> Processing Dependency: git = 1.7.10.2-1.w5 for package: git-cvs
--> Processing Dependency: git = 1.7.10.2-1.w5 for package: git-all
--> Processing Dependency: git = 1.7.10.2-1.w5 for package: gitk
---> Package git.i386 0:1.8.2.1-1.el5 set to be updated
---> Package xinetd.i386 2:2.3.14-20.el5_10 set to be updated
--> Running transaction check
---> Package emacs-git.i386 0:1.8.2.1-1.el5 set to be updated
---> Package git-all.i386 0:1.8.2.1-1.el5 set to be updated
--> Processing Dependency: git-p4 = 1.8.2.1-1.el5 for package: git-all
---> Package git-cvs.i386 0:1.8.2.1-1.el5 set to be updated
--> Processing Dependency: perl-DBD-SQLite for package: git-cvs
---> Package git-email.i386 0:1.8.2.1-1.el5 set to be updated
---> Package git-gui.i386 0:1.8.2.1-1.el5 set to be updated
---> Package git-svn.i386 0:1.8.2.1-1.el5 set to be updated
--> Processing Dependency: perl(Git::SVN::Utils) for package: git-svn
--> Processing Dependency: perl(Git::SVN::Ra) for package: git-svn
--> Processing Dependency: perl(Git::SVN::Prompt) for package: git-svn
--> Processing Dependency: perl(Git::SVN::Migration) for package: git-svn
--> Processing Dependency: perl(Git::SVN::Log) for package: git-svn
--> Processing Dependency: perl(Git::SVN::Fetcher) for package: git-svn
--> Processing Dependency: perl(Git::SVN::Editor) for package: git-svn
--> Processing Dependency: perl(Git::SVN) for package: git-svn
---> Package gitk.i386 0:1.8.2.1-1.el5 set to be updated
---> Package perl-Git.i386 0:1.8.2.1-1.el5 set to be updated
--> Running transaction check
---> Package git-p4.i386 0:1.8.2.1-1.el5 set to be updated
---> Package perl-DBD-SQLite.i386 0:1.14-3.el5 set to be updated
---> Package perl-Git-SVN.i386 0:1.8.2.1-1.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================================================================
 Package                                            Arch                                    Version                                                 Repository                                  Size
=====================================================================================================================================================================================================
Installing:
 git-daemon                                         i386                                    1.8.2.1-1.el5                                           epel                                       336 k
Installing for dependencies:
 git-p4                                             i386                                    1.8.2.1-1.el5                                           epel                                        77 k
 perl-DBD-SQLite                                    i386                                    1.14-3.el5                                              epel                                       287 k
 perl-Git-SVN                                       i386                                    1.8.2.1-1.el5                                           epel                                        84 k
 xinetd                                             i386                                    2:2.3.14-20.el5_10                                      updates                                    127 k
Updating for dependencies:
 emacs-git                                          i386                                    1.8.2.1-1.el5                                           epel                                        50 k
 git                                                i386                                    1.8.2.1-1.el5                                           epel                                       7.3 M
 git-all                                            i386                                    1.8.2.1-1.el5                                           epel                                        22 k
 git-cvs                                            i386                                    1.8.2.1-1.el5                                           epel                                       116 k
 git-email                                          i386                                    1.8.2.1-1.el5                                           epel                                        54 k
 git-gui                                            i386                                    1.8.2.1-1.el5                                           epel                                       282 k
 git-svn                                            i386                                    1.8.2.1-1.el5                                           epel                                       387 k
 gitk                                               i386                                    1.8.2.1-1.el5                                           epel                                       156 k
 perl-Git                                           i386                                    1.8.2.1-1.el5                                           epel                                        49 k

Transaction Summary
=====================================================================================================================================================================================================
Install       5 Package(s)
Upgrade       9 Package(s)

Total download size: 9.3 M
Is this ok [y/N]: 

もちろんyesですとも。

Downloading Packages:
(1/14): git-all-1.8.2.1-1.el5.i386.rpm                                                                                                                                        |  22 kB     00:00     
(2/14): perl-Git-1.8.2.1-1.el5.i386.rpm                                                                                                                                       |  49 kB     00:00     
(3/14): emacs-git-1.8.2.1-1.el5.i386.rpm                                                                                                                                      |  50 kB     00:00     
(4/14): git-email-1.8.2.1-1.el5.i386.rpm                                                                                                                                      |  54 kB     00:00     
(5/14): git-p4-1.8.2.1-1.el5.i386.rpm                                                                                                                                         |  77 kB     00:00     
(6/14): perl-Git-SVN-1.8.2.1-1.el5.i386.rpm                                                                                                                                   |  84 kB     00:00     
(7/14): git-cvs-1.8.2.1-1.el5.i386.rpm                                                                                                                                        | 116 kB     00:00     
(8/14): xinetd-2.3.14-20.el5_10.i386.rpm                                                                                                                                      | 127 kB     00:00     
(9/14): gitk-1.8.2.1-1.el5.i386.rpm                                                                                                                                           | 156 kB     00:00     
(10/14): git-gui-1.8.2.1-1.el5.i386.rpm                                                                                                                                       | 282 kB     00:00     
(11/14): perl-DBD-SQLite-1.14-3.el5.i386.rpm                                                                                                                                  | 287 kB     00:00     
(12/14): git-daemon-1.8.2.1-1.el5.i386.rpm                                                                                                                                    | 336 kB     00:00     
(13/14): git-svn-1.8.2.1-1.el5.i386.rpm                                                                                                                                       | 387 kB     00:00     
(14/14): git-1.8.2.1-1.el5.i386.rpm                                                                                                                                           | 7.3 MB     00:00     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                3.7 MB/s | 9.3 MB     00:02     
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 217521f6


GPG key retrieval failed: [Errno 5] OSError: [Errno 2] No such file or directory: '/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL'

キーが存在しなかったので入れる。

# cd /etc/pki/rpm-gpg/
# wget --no-check-certificate https://fedoraproject.org/static/217521F6.txt
# cp 217521F6.txt RPM-GPG-KEY-EPEL
# rm 217521F6.txt
# yum install git-daemon

再度挑戦。

Downloading Packages:
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 217521f6
epel/gpgkey                                                                                                                                                                   | 1.8 kB     00:00     
Importing GPG key 0x217521F6 "Fedora EPEL <epel@fedoraproject.org>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
Is this ok [y/N]: y
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : perl-DBD-SQLite                                                                                                                                                              1/23 
  Installing     : xinetd                                                                                                                                                                       2/23 
  Updating       : perl-Git                                                                                                                                                                     3/23 
  Updating       : git                                                                                                                                                                          4/23 
  Installing     : git-daemon                                                                                                                                                                   5/23 
  Updating       : gitk                                                                                                                                                                         6/23 
  Updating       : git-gui                                                                                                                                                                      7/23 
  Updating       : emacs-git                                                                                                                                                                    8/23 
  Updating       : git-email                                                                                                                                                                    9/23 
  Installing     : git-p4                                                                                                                                                                      10/23 
  Updating       : git-cvs                                                                                                                                                                     11/23 
  Installing     : perl-Git-SVN                                                                                                                                                                12/23 
  Updating       : git-svn                                                                                                                                                                     13/23 
  Updating       : git-all                                                                                                                                                                     14/23 
  Cleanup        : emacs-git                                                                                                                                                                   15/23 
  Cleanup        : git-email                                                                                                                                                                   16/23 
  Cleanup        : git-cvs                                                                                                                                                                     17/23 
  Cleanup        : perl-Git                                                                                                                                                                    18/23 
  Cleanup        : git-svn                                                                                                                                                                     19/23 
  Cleanup        : git                                                                                                                                                                         20/23 
  Cleanup        : git-all                                                                                                                                                                     21/23 
  Cleanup        : gitk                                                                                                                                                                        22/23 
  Cleanup        : git-gui                                                                                                                                                                     23/23 

Installed:
  git-daemon.i386 0:1.8.2.1-1.el5                                                                                                                                                                    

Dependency Installed:
  git-p4.i386 0:1.8.2.1-1.el5                  perl-DBD-SQLite.i386 0:1.14-3.el5                  perl-Git-SVN.i386 0:1.8.2.1-1.el5                  xinetd.i386 2:2.3.14-20.el5_10                 

Dependency Updated:
  emacs-git.i386 0:1.8.2.1-1.el5    git.i386 0:1.8.2.1-1.el5     git-all.i386 0:1.8.2.1-1.el5     git-cvs.i386 0:1.8.2.1-1.el5    git-email.i386 0:1.8.2.1-1.el5    git-gui.i386 0:1.8.2.1-1.el5   
  git-svn.i386 0:1.8.2.1-1.el5      gitk.i386 0:1.8.2.1-1.el5    perl-Git.i386 0:1.8.2.1-1.el5   

Complete!
# /etc/init.d/xinetd start
Starting xinetd:                                           [  OK  ]
# cp /etc/xinetd.d/git /etc/xinetd.d/git-daemon
# vim /etc/xinetd.d/git-daemon
# default: off
# description: The git d&#230;mon allows git repositories to be exported using \
#       the git:// protocol.

service git
{
        disable         = no      # <- 変更
        socket_type     = stream
        wait            = no
        user            = nobody
        server          = /usr/libexec/git-core/git-daemon
        server_args     = --base-path=/var/lib/git --export-all --user-path=public_git --syslog --inetd --verbose
        log_on_failure  += USERID
}
# /etc/rc.d/init.d/xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]

無事入ったのでリポジトリを作っていきます。

# cd /var/lib/git/
# mkdir public_git
# mkdir public_git/test.git
# cd public_git/test.git
# git init --bare --shared=true
Initialized empty shared Git repository in /var/lib/git/public_git/test.git/

コミットできるユーザーを作ります

# groupadd git
# adduser git
# passwd git
# chown -R root:git /var/lib/git/

コミットできるユーザーでクローン

# su git
$ cd
$ mkdir test
$ cd test
$ git clone ssh://git@<LOCAL_DOMAIN>:22/var/lib/git/public_git/test.git
Cloning into 'test'...
The authenticity of host '<LOCAL_DOMAIN> (<LOCAL_DOMAIN>)' can't be established.
RSA key fingerprint is df:54:05:12:a6:27:8c:f0:b4:ff:8e:1b:cd:8c:52:b9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '<LOCAL_DOMAIN>' (RSA) to the list of known hosts.

あとは編集していくだけ

$ git config --global user.email "xx@xxxx.xx"
$ git config --global user.name "git"
$ cd test
$ vim test.txt
$ git add test.txt
$ git commit -m "commit!"
$ git push 

出来ました!


[おまけ]よくあるエラー

ファイルをコミットしてない時に出る

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly
error: failed to push some refs to 'ssh://git@<LOCAL_DOMAIN>:22/var/lib/git/pupblic_git/test.git'


書き込み権限がないので、きちんとpushできるようにグループやユーザーに権限を与える事。

fatal: Unable to create '<PATH_TO_REPOS>/master.lock': Permission denied