设为首页 收藏本站
查看: 1846|回复: 0

[经验分享] pupput加入git版本控制线上环境部署及使用说明

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-4-17 09:23:08 | 显示全部楼层 |阅读模式
                      注:本文侧重于pupput使用git版本控制在线上环境的部署步骤详解。
1:线上puppet加入git版本控制
详细步骤:
1
2
3
4
5
6
7
8
9
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment]
root@pts/0 # git init ; cd ..; git clone --bar environment /var/puppet/environment.git
Initialized empty Git repository in /etc/puppet/multi-environment/yydev/environment/.git/
Initialized empty Git repository in /var/puppet/environment.git/
warning: You appear to have cloned an empty repository.
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/application]
root@pts/0 # git init
Initialized empty Git repository in /etc/puppet/multi-environment/yydev/application/.git/
warning: You appear to have cloned an empty repository.




将项目添加到git:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/application] 2015-04-15 17:37:53
root@pts/0 # git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       modules/
nothing added to commit but untracked files present (use "git add" to track)
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/application] 2015-04-15 17:37:56
root@pts/0 # git add modules
root@pts/0 # git commit -a -m "init repo"
[master (root-commit) 8ef11ef] init repo
Committer: root <root@pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

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

If the identity used for this commit is wrong, you can fix it with:

    git commit --amend --author='Your Name <you@example.com>'

2 files changed, 24 insertions(+), 0 deletions(-)
create mode 100644 modules/httpd/files/1.txt
create mode 100644 modules/httpd/manifests/init.pp




配置提交信息:
1
2
3
4
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/application] 2015-04-15 17:38:47
root@pts/0 # git config --global user.name "wangyanliang"
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/application] 2015-04-15 17:39:10
root@pts/0 # git config --global user.email "wangyl@youyuan.com"




配置git远程节点名称:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment] 2015-04-15 17:51:10
root@pts/0 # git remote add origin /var/puppet/environment.git
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment] 2015-04-15 17:52:17
root@pts/0 # cd ../application
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/application] 2015-04-15 17:52:35
root@pts/0 # git remote add app_origin /var/puppet/application.git
root@pts/0 # git remote -v
app_origin      /var/puppet/application.git (fetch)
app_origin      /var/puppet/application.git (push)
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/application] 2015-04-15 17:53:36
root@pts/0 # cd ../environment/; git remote -v
origin  /var/puppet/environment.git (fetch)
origin  /var/puppet/environment.git (push)
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment] 2015-04-15 17:57:08
root@pts/0 # git remote rm origin
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment] 2015-04-15 17:57:18
root@pts/0 # git remote add env_origin /var/puppet/environment.git
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment] 2015-04-15 17:57:34
root@pts/0 # git remote -v
env_origin      /var/puppet/environment.git (fetch)
env_origin      /var/puppet/environment.git (push)




将更改推送到git仓库:
1
2
3
4
5
6
7
8
9
10
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/application] 2015-04-15 17:59:05
root@pts/0 # git push app_origin master:master
Counting objects: 8, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (8/8), 705 bytes, done.
Total 8 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (8/8), done.
To /var/puppet/application.git
* [new branch]      master -> master




操作yytest目录:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2015-04-15 18:00:55
root@pts/0 # git clone /var/puppet/environment.git environment
fatal: destination path 'environment' already exists and is not an empty directory.
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yytest] 2015-04-15 18:01:10
root@pts/0 # rm -rf environment
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yytest] 2015-04-15 18:01:38
root@pts/0 # git clone /var/puppet/environment.git environment
Initialized empty Git repository in /etc/puppet/multi-environment/yytest/environment/.git/root@pts/0 # git clone /var/puppet/application.git application
Initialized empty Git repository in /etc/puppet/multi-environment/yytest/application/.git/
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yytest] 2015-04-15 18:02:56
root@pts/0 # cd environment/modules/ ;ls
ssh  test
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yytest/environment] 2015-04-16 12:52:53
root@pts/0 # git remote rm origin
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yytest/environment] 2015-04-16 12:53:02
root@pts/0 # git remote add env_origin /var/puppet/environment.git
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yytest/environment] 2015-04-16 12:53:23
root@pts/0 # cd ../application ; git remote rm origin; git remote add app_origin /var/puppet/application.git
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yytest/application] 2015-04-16 12:53:54
root@pts/0 # git remote -v
app_origin      /var/puppet/application.git (fetch)
app_origin      /var/puppet/application.git (push)



同样的操作yyprd目录:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yytest]
root@pts/0 # git clone /var/puppet/application.git application
Initialized empty Git repository in /etc/puppet/multi-environment/yyprd/application/.git/
root@pts/0 # git remote rm origin
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yyprd/application] 2015-04-16 12:48:31
root@pts/0 # git remote add app_origin /var/puppet/application.git
root@pts/0 # git clone /var/puppet/environment.git environment
Initialized empty Git repository in /etc/puppet/multi-environment/yyprd/environment/.git/
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yyprd] 2015-04-16 11:54:32
root@pts/0 # ls environment/modules/
ssh  test
root@pts/0 # git remote rm origin
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yyprd/environment] 2015-04-16 12:49:19
root@pts/0 # git remote add env_origin /var/puppet/environment.git





至此puppet线上部署完成:多环境配置统一,并加入git,包含开发,测试,生产。让我看看我们这个环境是怎么协同工作的吧!

2:协同开发
我们假设用户user1,user2
user1负责写crontab模块。
user2负责写httpd模块。

usr1的实施步骤:
进入开发环境建git开发特性分支 env/crontab
git branch env/crontab
1
2
3
4
5
6
7
8
9
10
11
root@pts/0 # git branch
* master
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment/modules] 2015-04-16 13:39:50
root@pts/0 # git branch env/crontab
root@pts/0 # git branch -v
  env/crontab c10ee1d init env
* master      c10ee1d init env
root@pts/0 # git checkout env/crontab
Switched to branch 'env/crontab'
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment/modules] 2015-04-16 13:42:55
root@pts/0 # mkdir cron/{files,manifests,templates} -p




模块命令已经写好:(虽然错误百出,哈哈, 正确的在下面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
root@pts/0 # cat  init.pp install.pp service.pp crontab.pp
class cron {
        include cron::install,cron::service,cron::crontab
}
class cron::install {
        package { "crontabs":
        ensure => present,
        }
}
class cron::service {
        service { "crond":
                ensure => running,
}
class cron::crontab {
    cron {"ntp time":
        ensure =>   present,
        command =>   "/sbin/ntpdate 192.168.0.2",
        user =>   'root',
        minute => 0,
        hour =>   '6-13/3',
        month =>   *;
}




提交代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
root@pts/0 # ls
cron  ssh  test
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment/modules] 2015-04-16 14:27:21
root@pts/0 # git add *
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment/modules] 2015-04-16 14:27:29
root@pts/0 # git status
# On branch env/cron
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   cron/manifests/crontab.pp
#       new file:   cron/manifests/init.pp
#       new file:   cron/manifests/install.pp
#       new file:   cron/manifests/service.pp
#
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment/modules] 2015-04-16 14:27:46
root@pts/0 # git commit -m "add cron" .   
[env/cron ef19965] add cron
4 files changed, 20 insertions(+), 0 deletions(-)
create mode 100644 modules/cron/manifests/crontab.pp
create mode 100644 modules/cron/manifests/init.pp
create mode 100644 modules/cron/manifests/install.pp
create mode 100644 modules/cron/manifests/service.pp



特性分支合并到主分支:
1
2
3
4
5
6
7
root@pts/0 # git checkout master
Switched to branch 'master'
root@pts/0 # git merge env/cron
Already up-to-date.
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment/modules] 2015-04-16 14:35:52
root@pts/0 # ls
cron  ssh  test



删除特性分支:
1
2
3
4
5
6
root@pts/0 # git branch -v
  env/cron beb0b03 modify service.pp
* master   4f5ff10 modify crontab
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment/modules] 2015-04-16 15:03:49
root@pts/0 # git branch -d env/cron
Deleted branch env/cron (was beb0b03).



开发环境测试:
1: 配置开发测试的主机:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev] 2015-04-16 14:22:43
root@pts/0 # ls
application  environment  manifests
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev] 2015-04-16 14:22:43
root@pts/0 # cd manifests/
nodes/   site.pp  
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev] 2015-04-16 14:22:43
root@pts/0 # cat manifests/site.pp  
import "nodes/*.pp"
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev] 2015-04-16 14:22:56
root@pts/0 # cat manifests/nodes/test.pp
class base {
        include ssh
        include cron
}
node 'ppttest_wangsu_bj_192.168.3.67.centos.yypuppet.com' {
        include base
        include test
        include httpd
}




2: 开发测试主机上测试:
出错1:
1
2
3
4
root@pts/0 # puppet agent -t --environment=yydev  --noop --no-daemonize --verbose
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find class cron for ppttest_wangsu_bj_192.168.3.67.centos.yypuppet.com at /etc/puppet/multi-environment/yydev/manifests/nodes/test.pp:3 on node ppttest_wangsu_bj_192.168.3.67.centos.yypuppet.com
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run



错误排查:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
root@pts/0 # git checkout master
Switched to branch 'master'
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment/modules/cron] 2015-04-16 14:42:44
root@pts/0 # ls
files  templates
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment/modules/cron] 2015-04-16 14:42:44
root@pts/0 # git checkout env/cron
Switched to branch 'env/cron'
root@pts/0 # git merge master
Already up-to-date.
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment/modules/cron] 2015-04-16 14:43:40
root@pts/0 # git checkout env/cron
Already on 'env/cron'
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment/modules/cron] 2015-04-16 14:43:49
root@pts/0 # ls
files  manifests  templates



出错2:
1
2
3
4
root@pts/0 # puppet agent -t --environment=yydev  --noop --no-daemonize --verbose
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Syntax error at end of file; expected '}' at /etc/puppet/multi-environment/yydev/environment/modules/cron/manifests/service.pp:5 on node ppttest_wangsu_bj_192.168.3.67.centos.yypuppet.com
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run



报错排查,可见是语法错误:
service.pp少了个“}”,再次修复。

开发测试机成功。
1
2
3
4
5
6
7
root@pts/0 # puppet agent -t --environment=yydev  --noop --no-daemonize --verbose
info: Caching catalog for ppttest_wangsu_bj_192.168.3.67.centos.yypuppet.com
info: Applying configuration version '1429167566'
notice: /Stage[main]/Cron::Crontab/Cron[ntp time]/ensure: current_value absent, should be present (noop)
notice: Class[Cron::Crontab]: Would have triggered 'refresh' from 1 events
notice: Stage[main]: Would have triggered 'refresh' from 1 events
notice: Finished catalog run in 1.07 seconds



2:测试:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
root@pts/0 # crontab -l
ppttest_wangsu_bj_192.168.3.67.centos.yypuppet.com [~] 2015-04-16 15:10:57
root@pts/0 # puppet agent -t --environment=yydev --no-daemonize --verbose
info: Caching catalog for ppttest_wangsu_bj_192.168.3.67.centos.yypuppet.com
info: Applying configuration version '1429168261'
notice: /Stage[main]/Cron::Crontab/Cron[ntp time]/ensure: created
notice: Finished catalog run in 1.10 seconds
ppttest_wangsu_bj_192.168.3.67.centos.yypuppet.com [~] 2015-04-16 15:11:04
root@pts/0 # crontab -l
# HEADER: This file was autogenerated at Thu Apr 16 15:11:03 +0800 2015 by puppet.
# HEADER: While it can still be managed manually, it is definitely not recommended.
# HEADER: Note particularly that the comments starting with 'Puppet Name' should
# HEADER: not be deleted, as doing so could cause duplicate cron jobs.
# Puppet Name: ntp time
30 */2 * * * /sbin/ntpdate 192.168.0.2



提交代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
root@pts/0 # git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   crontab.pp
#
no changes added to commit (use "git add" and/or "git commit -a")
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment/modules/cron/manifests] 2015-04-16 15:01:04
root@pts/0 # git commit -a -m "modify crontab"
[master 4f5ff10] modify crontab
1 files changed, 7 insertions(+), 6 deletions(-)



最终版本:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
root@pts/0 # cat init.pp install.pp service.pp crontab.pp
class cron {
        include cron::install,cron::service,cron::crontab
}
class cron::install {
        package { "crontabs":
        ensure => present,
        }
}
class cron::service {
        service { "crond":
                ensure => running,
}
}
class cron::crontab {
        cron {"ntp time":
        ensure => present,
        command =>  "/sbin/ntpdate 192.168.0.2",
        user => 'root',
        minute => 30,
        hour => '*/2',
}
}




提交代码到仓库中:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment/modules] 2015-04-16 15:33:36
root@pts/0 # ls
cron  ssh  test
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment/modules] 2015-04-16 15:33:36
root@pts/0 # git remote -v
env_origin      /var/puppet/environment.git (fetch)
env_origin      /var/puppet/environment.git (push)
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yydev/environment/modules] 2015-04-16 15:33:52
root@pts/0 # git push env_origin
Counting objects: 36, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (24/24), done.
Writing objects: 100% (34/34), 2.84 KiB, done.
Total 34 (delta 6), reused 0 (delta 0)
Unpacking objects: 100% (34/34), done.
To /var/puppet/environment.git
   c10ee1d..112c636  master -> master




yytest环境更新本地库:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
root@pts/0 # git branch
* master
pptserver_wangsu_bj_192.168.3.68.centos.yypuppet.com [/etc/puppet/multi-environment/yytest/environment/modules] 2015-04-16 15:40:11
root@pts/0 # git pull env_origin master
From /var/puppet/environment
* branch            master     -> FETCH_HEAD
Updating c10ee1d..112c636
Fast-forward
modules/cron/manifests/crontab.pp |    9 +++++++++
modules/cron/manifests/init.pp    |    3 +++
modules/cron/manifests/install.pp |    5 +++++
modules/cron/manifests/service.pp |    5 +++++
4 files changed, 22 insertions(+), 0 deletions(-)
create mode 100644 modules/cron/manifests/crontab.pp
create mode 100644 modules/cron/manifests/init.pp
create mode 100644 modules/cron/manifests/install.pp
create mode 100644 modules/cron/manifests/service.pp



user1的cron开发完毕!

让我们来总结下这个过程:
1:user1建立一个特性分支env/cron。
2:user1在env/cron中写cron的代码,此时与主干分支是完全隔离的。
3:代码书写完毕,合并到master分支。
4:此时env/cron便可以删除了。
5:开发环境测试。修复cron的代码。
6:开发测试环境测试成功后,提交cron的代码到仓库中。
7: 测试环境测试及线上环境进行上线。

user2的实施步骤和user1步骤一致:
1:进入开发环境建立git开发分支 app/httpd
。。。
。。。

puppet模板文档:
http://docs.puppetlabs.com/references/latest/type.html#file
                   
                       


   

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-57978-1-1.html 上篇帖子: CentOS 6.4x64安装git和gitolite服务器 下篇帖子: [Docker]学习笔记--搭建gitlab 控制线
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表