2010   11           13




       .    .   .    .   .   .
.
                                 Git
             etckeeper
.

            mkouhei@debian.or.jp
     all id: mkouhei


    2010 11     13
     2012 1     4




                         .   .    .    .   .   .
:       ,       @IT
                      ,        ,             KVM
(mkouhei)
                                           KVM
GPG KeyID :               :R&D,            (                                    )
4096R/7E37CE41
                                           @IT
Debian JP Project,                                   !CouchDB
          Debian                                            #5
                     Debian
                     Ubuntu                (                        )
                                           Git
                                                                (
                                                            )




                                       .         .      .       .       .   .
/etc




       .   .   .   .   .   .
.   .   .   .   .   .
tab




      .   .   .   .   .   .
rcs




      .   .   .   .   .   .
Subversion




             .   .   .   .   .   .
Git




      .   .   .   .   .   .
Git                                 ?


                Git


                    git add      index       git commit
                                                                                 git push
working directory             git checkout                    local repository              remote repository
                                                                                 git pull




                                                          1
                                                                                 index
    VCS                               Git                          VCS




1
           VCS                                                               .       .      .        .          .   .
etckeeper




            .   .   .   .   .   .
/etc   VCS

apt yum
cron
Git, mercurial, bazaar, darcs




                                .   .   .   .   .   .
2
                 Git
$ sudo apt-get install etckeeper




$ ls -ld /etc/.git
drwx------ 8 root root 4096 2010-11-12 07:48 /etc/.git




 2
     Debian                                   .    .     .       .   .   .
etckeeper               Git
     etckeeper init           git   config
     etckeeper commit         git   log
                              git   diff
                              git   remote add
                              git   push
                              git   pull




                                      .   .      .   .   .   .
Git                etckeeper
        git   init         etckeeper   init
        git   config        etckeeper   vcs config
        git   status       etckeeper   vcs status
        git   diff          etckeeper   vcs diff
index   git   add          etckeeper   vcs add
        git   commit       etckeeper   commit
        git   remote add   etckeeper   vcs remote add
        git   push         etckeeper   vcs push
        git   pull         etckeeper   vcs pull




                            .     .       .     .       .   .
ITIL

      変更履歴の確認                         etckeeper vcs log
                                                                          git log

    変更作業                      vi hoge.conf


                                                              vi hoge.conf
  変更内容確認                 etckeeper vcs diff




  変更状況確認               etckeeper vcs status                     git diff



コミットの事前登録                etckeeper vcs add
                                                               git status


  コミット                   etckeeper commit


                                                                 git add
 コミットログ確認                 etckeeper vcs log




                                  etckeeper vcs push           git commit
      バックアップ




                                                                     git log




                                                                           git push



                                                          .      .             .      .   .   .
.   .   .   .   .   .
Git




         user.name, user.email

      $ git config user.name=’Gonbeh Nanashi’
      $ git config user.email=’gonbeh@example.com’




                                                     .   .   .   .   .   .
etckeeper




   $ ls -ld /etc/.git
   drwx------ 8 root root 4096 2010-11-12 07:48 /etc/.git




                                                 .    .     .   .   .   .
Why?




       .   .   .   .   .   .
/etc/shadow
iptables
tripwire




              .   .   .   .   .   .
.   .   .   .   .   .
$ git log :/Initial
commit 0a6703b7ac1f521faff1a1b1c7d65a0b104301de
Author: Gonbeh Nanashi <gonbeh@example.com>
Date:   Mon May 3 02:08:50 2010 +0900
    Initial commit
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
(stdin):

                                              .   .   .   .   .   .
.
1



    $ cd /etc; sudo vi /etc/hosts


.
2



    $ sudo etckeeper vcs status
    $ sudo etckeeper vcs diff


.
3



    $ sudo etckeeper commit ’add new hosts entries.’




                                            .    .     .   .   .   .
Git   index
add

                    (ry




                .         .   .   .   .   .
Git
      .
      1



          $ cd /etc; sudo vi /etc/hosts


      .
      2



          $ sudo git status
          $ sudo git diff


      . index
      3



          $ sudo git add hosts


      .
      4



          $ sudo git commit -sm ’add new hosts entries.’


                                                  .    .   .   .   .   .
etckeeper     Git


      Git    VCS
      commit               git commit -a
                                (init)             (commit)

      root

        1. git
        2. etckeeper vcs subcommand




                                           .   .    .   .     .   .
git




      .   .   .   .   .   .
etckeeper




      /etc

             apt yum
             cron




                       .   .   .   .   .   .
etckeeper




            .   .   .   .   .   .
.   .   .   .   .   .
.   .   .   .   .   .
/etc

                                                       etckeeper
        Srv0
        push



            Client
       198.51.100.100

        local repos




                                                Srv0                                                    Srv1                     Srv2                      Srv3
                                            198.51.100.1                                            198.51.100.11            198.51.100.12             198.51.100.13

       remote repos        local repos                                                                                        local repos               local repos
                                                                                                     local repos(/etc)
         (gitosis)            (/etc)                                                                                             (/etc)                    (/etc)


             git pull           git push                                         git push                         git push                  git push


                         remote repos       remote repos       remote repos       remote repos
       local repos
                        (Srv0 /etc bkup)   (Srv1 /etc bkup)   (Srv2 /etc bkup)   (Srv3 /etc bkup)




                                                                                                      .             .          .            .             .           .
sshd(/etc/ssh/sshd config)



     root    push                root
       PermitRootLogin yes




       PasswordAuthentication no
       ChallengeResponseAuthentication no




                                            .   .   .   .   .   .
ssh   root




             .   .   .   .   .   .
.   .   .   .   .   .
root                           (/root/.ssh/authorized keys)

                     IP
            from=’198.51.100.1?’




            no-pty




       from="198.51.100.1?",no-pty ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAx5v6Na2jwzE6xG
       ah8MVY0Odbi/1oMC6OYolFo3e//Ysacn8r7XOAXIiQvryuIUgzclmJag7EhnfB3pzpNxhu1Ai0c1th
       ciwdmdZyM+tGGwcrfXERrsipBPbQsr2eMiOX7oX0MQJEHF0qt97EZmIhZ60rS+KfyA1EzIWLDL8Avd
       h/2MoHwJG6YJqAwkqcvU61DHawLlyNN/XmrXEsObg+APJrvJNXGcu7u6iWBpjeKORuuOkX2rGoESWz
       OZHtJooZQbzdfjyu3pTrriQLnk9gdYV2Xj7ax8W853n9lZa8JBilleoRfBE192E4fDb4/mMjQPcMTp
       ywb7QQ== root@example.com



                                                     .    .    .    .    .    .
/var/lib/etckeeper/etc host
                         3


      $ sudo mkdir -p /var/lib/etckeeper/etc_Srv{0,1,2,3}
      $ sudo chmod 700 /var/lib/etckeeper/etc_Srv[0-3]




      $ cd /var/lib/etckeeper/etc_Srv0; sudo git init --bare
      $ cd ../etc_Srv1; (       )




3
    path                                      .    .    .      .   .   .
/etc



$ cd /etc
$ sudo git remote add backup ssh://Srv0/etc-Srv1


        (                                   )
$ sudo git push backup --all




                                        .       .   .   .   .   .
etckeeper




                                      =
                   sudo

      ssh   root




                          .   .   .       .   .   .
etckeeper




                                  4

         1




    4
        gitosis   .   .   .   .       .   .
Git
(         )



              .   .   .   .   .   .

インフラエンジニアのためのGit入門

  • 1.
    2010 11 13 . . . . . .
  • 2.
    . Git etckeeper . mkouhei@debian.or.jp all id: mkouhei 2010 11 13 2012 1 4 . . . . . .
  • 3.
    : , @IT , , KVM (mkouhei) KVM GPG KeyID : :R&D, ( ) 4096R/7E37CE41 @IT Debian JP Project, !CouchDB Debian #5 Debian Ubuntu ( ) Git ( ) . . . . . .
  • 4.
    /etc . . . . . .
  • 5.
    . . . . . .
  • 6.
    tab . . . . . .
  • 7.
    rcs . . . . . .
  • 8.
    Subversion . . . . . .
  • 9.
    Git . . . . . .
  • 10.
    Git ? Git git add index git commit git push working directory git checkout local repository remote repository git pull 1 index VCS Git VCS 1 VCS . . . . . .
  • 11.
    etckeeper . . . . . .
  • 12.
    /etc VCS apt yum cron Git, mercurial, bazaar, darcs . . . . . .
  • 13.
    2 Git $ sudo apt-get install etckeeper $ ls -ld /etc/.git drwx------ 8 root root 4096 2010-11-12 07:48 /etc/.git 2 Debian . . . . . .
  • 14.
    etckeeper Git etckeeper init git config etckeeper commit git log git diff git remote add git push git pull . . . . . .
  • 15.
    Git etckeeper git init etckeeper init git config etckeeper vcs config git status etckeeper vcs status git diff etckeeper vcs diff index git add etckeeper vcs add git commit etckeeper commit git remote add etckeeper vcs remote add git push etckeeper vcs push git pull etckeeper vcs pull . . . . . .
  • 16.
    ITIL 変更履歴の確認 etckeeper vcs log git log 変更作業 vi hoge.conf vi hoge.conf 変更内容確認 etckeeper vcs diff 変更状況確認 etckeeper vcs status git diff コミットの事前登録 etckeeper vcs add git status コミット etckeeper commit git add コミットログ確認 etckeeper vcs log etckeeper vcs push git commit バックアップ git log git push . . . . . .
  • 17.
    . . . . . .
  • 18.
    Git user.name, user.email $ git config user.name=’Gonbeh Nanashi’ $ git config user.email=’gonbeh@example.com’ . . . . . .
  • 19.
    etckeeper $ ls -ld /etc/.git drwx------ 8 root root 4096 2010-11-12 07:48 /etc/.git . . . . . .
  • 20.
    Why? . . . . . .
  • 21.
  • 22.
    . . . . . .
  • 23.
    $ git log:/Initial commit 0a6703b7ac1f521faff1a1b1c7d65a0b104301de Author: Gonbeh Nanashi <gonbeh@example.com> Date: Mon May 3 02:08:50 2010 +0900 Initial commit ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ (stdin): . . . . . .
  • 24.
    . 1 $ cd /etc; sudo vi /etc/hosts . 2 $ sudo etckeeper vcs status $ sudo etckeeper vcs diff . 3 $ sudo etckeeper commit ’add new hosts entries.’ . . . . . .
  • 25.
    Git index add (ry . . . . . .
  • 26.
    Git . 1 $ cd /etc; sudo vi /etc/hosts . 2 $ sudo git status $ sudo git diff . index 3 $ sudo git add hosts . 4 $ sudo git commit -sm ’add new hosts entries.’ . . . . . .
  • 27.
    etckeeper Git Git VCS commit git commit -a (init) (commit) root 1. git 2. etckeeper vcs subcommand . . . . . .
  • 28.
    git . . . . . .
  • 29.
    etckeeper /etc apt yum cron . . . . . .
  • 30.
    etckeeper . . . . . .
  • 31.
    . . . . . .
  • 32.
    . . . . . .
  • 33.
    /etc etckeeper Srv0 push Client 198.51.100.100 local repos Srv0 Srv1 Srv2 Srv3 198.51.100.1 198.51.100.11 198.51.100.12 198.51.100.13 remote repos local repos local repos local repos local repos(/etc) (gitosis) (/etc) (/etc) (/etc) git pull git push git push git push git push remote repos remote repos remote repos remote repos local repos (Srv0 /etc bkup) (Srv1 /etc bkup) (Srv2 /etc bkup) (Srv3 /etc bkup) . . . . . .
  • 34.
    sshd(/etc/ssh/sshd config) root push root PermitRootLogin yes PasswordAuthentication no ChallengeResponseAuthentication no . . . . . .
  • 35.
    ssh root . . . . . .
  • 36.
    . . . . . .
  • 37.
    root (/root/.ssh/authorized keys) IP from=’198.51.100.1?’ no-pty from="198.51.100.1?",no-pty ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAx5v6Na2jwzE6xG ah8MVY0Odbi/1oMC6OYolFo3e//Ysacn8r7XOAXIiQvryuIUgzclmJag7EhnfB3pzpNxhu1Ai0c1th ciwdmdZyM+tGGwcrfXERrsipBPbQsr2eMiOX7oX0MQJEHF0qt97EZmIhZ60rS+KfyA1EzIWLDL8Avd h/2MoHwJG6YJqAwkqcvU61DHawLlyNN/XmrXEsObg+APJrvJNXGcu7u6iWBpjeKORuuOkX2rGoESWz OZHtJooZQbzdfjyu3pTrriQLnk9gdYV2Xj7ax8W853n9lZa8JBilleoRfBE192E4fDb4/mMjQPcMTp ywb7QQ== root@example.com . . . . . .
  • 38.
    /var/lib/etckeeper/etc host 3 $ sudo mkdir -p /var/lib/etckeeper/etc_Srv{0,1,2,3} $ sudo chmod 700 /var/lib/etckeeper/etc_Srv[0-3] $ cd /var/lib/etckeeper/etc_Srv0; sudo git init --bare $ cd ../etc_Srv1; ( ) 3 path . . . . . .
  • 39.
    /etc $ cd /etc $sudo git remote add backup ssh://Srv0/etc-Srv1 ( ) $ sudo git push backup --all . . . . . .
  • 40.
    etckeeper = sudo ssh root . . . . . .
  • 41.
    etckeeper 4 1 4 gitosis . . . . . .
  • 42.
    Git ( ) . . . . . .