首页 > 代码库 > redhat搭建git服务器

redhat搭建git服务器

以创建puppet仓库为例搭建git服务器

一、搭建git服务器

1、在服务器安装git包

#yum install git git-daemon

2、在服务器上创建专用账号,所有用户都通过此账号访问git库。选择git作为专用账号,并为账号设置密码。(也可以在配置完git服务后,可以将git修改为只允许公钥认证,以加强安全性。)

#adduser -s /bin/bash git 

#passwd git 

3、初始化puppet服务端git仓库,创建/git目录,并再/git目录下创建puppet repo目录,并赋予git用户权限:

创建/git目录

#mkdir /git

创建puppet repo目录

#mkdir /git/puppet.git

创建git仓库

#cd /git/puppet.git

#git --bare init

赋予git目录git用户权限

#chown git:git -R /git


4、启动git服务,

#/usr/libexec/git-core/git-daemon --base-path=/git --detach --user=git --group=git --listen=10.240.216.250 --export-all --enable=receive-pack --enable=upload-pack --enable=upload-archive


二、降puppet加入git

1、将puppet master上的/etc/puppet目录加入仓库,作为仓库的副本。

#cd /etc/

#mv puppet /tmp

把之前搭建的puppet仓库克隆到/etc目录下并在此目录下生产一个puppet的目录

#git clone git://10.240.216.250/puppet.git

#cd /etc/puppet

#cp /tmp/puppet/*

#git add *

#git commit -m "Add puppet to git repo"

#git push -u origin master

Counting objects: 2949, done.

Delta compression using up to 16 threads.

Compressing objects: 100% (2630/2630), done.

Writing objects: 100% (2949/2949), 1.57 MiB, done.

Total 2949 (delta 611), reused 0 (delta 0)

To git://10.240.216.250/puppet.git

 * [new branch]      master -> master


这样就在本地创建了一个master仓库,它包含了puppet的配置文件及清单。我们可以在不通的地方导出多个副本,提交变更之前在这些副本上的工作。列如,我们有一个系统管理员团队,他们每个人都可以在自己的电脑上创建一个副本进行修改等工作。


三、在系统管理员本地电脑上创建副本(即git客户端)

1、把puppet副本克隆到本地

root@ubuntu:# cd /tmp

root@ubuntu:/tmp# 

root@ubuntu:/tmp# git clone git://10.240.216.250/puppet.git

Cloning into ‘puppet‘...

remote: Counting objects: 2949, done.

remote: Compressing objects: 100% (2019/2019), done.

remote: Total 2949 (delta 611), reused 2949 (delta 611)

Receiving objects: 100% (2949/2949), 1.57 MiB | 0 bytes/s, done.

Resolving deltas: 100% (611/611), done.

Checking connectivity... done.

root@ubuntu:/tmp# 

root@ubuntu:/tmp# ls

puppet


2、修改想要修改的配置并提交至主分支“master”

root@ubuntu:/tmp# cd puppet 

root@ubuntu:/tmp/puppet# ls

aaa  auth.conf  environments  fileserver.conf  hieradata  hiera.yaml  manifests  modules  puppet.conf

root@ubuntu:/tmp/puppet# vi manifests/site.pp 

Package {

  allow_virtual => true,

}



node ‘bgw-os-node1‘ {

    include ::openstack::role::controller_master

}


node ‘bgw-os-node2‘ {

    include ::openstack::role::controller_standby

}

node ‘bgw-os-node11‘ {

    include ::openstack::role::compute

}

#node ‘bgw-os-node12‘ {                 #此处是要修改的内容,把node12节点注释掉

#    include ::openstack::role::compute

#}


node ‘bgw-os-node151‘ {

    include ::openstack::role::ceph_mon_and_osd

}


node ‘bgw-os-node152‘ {

    include ::openstack::role::ceph_mon_and_osd

}

node ‘bgw-os-node153‘ {

    include ::openstack::role::ceph_mon_and_osd

}


"puppet/manifests/site.pp" 31L, 544C written                                         

 

root@ubuntu:/tmp# git add puppet/manifests/site.pp 

fatal: Not a git repository (or any of the parent directories): .git


root@ubuntu:/tmp/puppet# git add manifests/site.pp

root@ubuntu:/tmp/puppet# git commit -m "Add site.pp"


*** Please tell me who you are.


Run


  git config --global user.email "you@example.com"

  git config --global user.name "Your Name"


to set your account‘s default identity.

Omit --global to set the identity only in this repository.


fatal: unable to auto-detect email address (got ‘root@ubuntu.(none)‘)

上面出现报错,需要添加用户及用户的邮箱

root@ubuntu:/tmp/puppet# git config --global user.name "lizhanguo" 

root@ubuntu:/tmp/puppet# git config --global user.email "lizhanguo@jiayuan.com"


再次提交成功

root@ubuntu:/tmp/puppet# git commit -m "Add site.pp"                           

[master 894da1e] Add site.pp

 1 file changed, 3 insertions(+), 3 deletions(-)

root@ubuntu:/tmp/puppet# 


把本地的内容push 到git server端

root@ubuntu:/tmp/puppet# git push

warning: push.default is unset; its implicit value has changed in

Git 2.0 from ‘matching‘ to ‘simple‘. To squelch this message

and maintain the traditional behavior, use:


  git config --global push.default matching


To squelch this message and adopt the new behavior now, use:


  git config --global push.default simple


When push.default is set to ‘matching‘, git will push local branches

to the remote branches that already exist with the same name.


Since Git 2.0, Git defaults to the more conservative ‘simple‘

behavior, which only pushes the current branch to the corresponding

remote branch that ‘git pull‘ uses to update the current branch.


See ‘git help config‘ and search for ‘push.default‘ for further information.

(the ‘simple‘ mode was introduced in Git 1.7.11. Use the similar mode

‘current‘ instead of ‘simple‘ if you sometimes use older versions of Git)


Counting objects: 4, done.

Delta compression using up to 2 threads.

Compressing objects: 100% (3/3), done.

Writing objects: 100% (4/4), 376 bytes | 0 bytes/s, done.

Total 4 (delta 2), reused 0 (delta 0)

To git://10.240.216.250/puppet.git

   5ad9866..894da1e  master -> master

root@ubuntu:/tmp/puppet# 

四、git 服务端,在puppet master的/etc/puppet目录下运行git pull,将其更新到最新版本。

[root@bgw-cobbler puppet]# git pull

remote: Counting objects: 7, done.

remote: Compressing objects: 100% (3/3), done.

remote: Total 4 (delta 2), reused 0 (delta 0)

Unpacking objects: 100% (4/4), done.

From git://10.240.216.250/puppet

   5ad9866..894da1e  master     -> origin/master

Updating 5ad9866..894da1e

Fast-forward

 manifests/site.pp |    6 +++---

 1 files changed, 3 insertions(+), 3 deletions(-)


查看刚才客户端的修改提交是否生效

[root@bgw-cobbler puppet]# cat manifests/site.pp 


Package {

  allow_virtual => true,

}



node ‘bgw-os-node1‘ {

    include ::openstack::role::controller_master

}


node ‘bgw-os-node2‘ {

    include ::openstack::role::controller_standby

}

node ‘bgw-os-node11‘ {

    include ::openstack::role::compute

}

#node ‘bgw-os-node12‘ {              #已生效

#    include ::openstack::role::compute

#}


node ‘bgw-os-node151‘ {

    include ::openstack::role::ceph_mon_and_osd

}


node ‘bgw-os-node152‘ {

    include ::openstack::role::ceph_mon_and_osd

}

node ‘bgw-os-node153‘ {

    include ::openstack::role::ceph_mon_and_osd

}


2、为了保证实时更新,我们可以在cron增加定时任务以保证/etc/puppet副本的内容为每分钟更新一次。

[root@bgw-cobbler ~]# crontab -e

no crontab for root - using an empty one


*/1 * * * * cd /etc/puppet ; git pull


本文出自 “zhanguo1110” 博客,请务必保留此出处http://zhanguo1110.blog.51cto.com/5750817/1603671

redhat搭建git服务器