centos 6.5安装docker和jenkins详解

 更新时间:2016-01-10 20:58:01   作者:佚名   我要评论(0)

下面我们来为各位介绍一篇关于centos 6.5安装docker和jenkins的例子,希望这篇文章能够帮助到各位朋友,有兴趣的朋友可以来看看吧.因公司项目的要求,让我在今天把docker和

下面我们来为各位介绍一篇关于centos 6.5安装docker和jenkins的例子,希望这篇文章能够帮助到各位朋友,有兴趣的朋友可以来看看吧.

因公司项目的要求,让我在今天把docker和jenkins搭建起来,我在搭建成功后,把其中遇到的问题和解决办法记录下来分享给大家.
 系统:centos 6.5(64位)
1.先查看内核是否是3.10
uname -r

如果不是3.10的执行下面的命令:
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -ivh http://www.elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm

安装kernel-lt(lt=long-term)
yum --enablerepo=elrepo-kernel install kernel-lt -y
或者安装kernel-ml(ml=mainline)
yum --enablerepo=elrepo-kernel install kernel-ml -y

ps:请自己根据需要来选择上面的内核.

编辑grub.conf文件,修改Grub引导顺序
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/mapper/VolGroup-lv_root
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (3.10.94-1.el6.elrepo.x86_64)
    root (hd0,0)
    kernel /vmlinuz-3.10.94-1.el6.elrepo.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS.utf-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
    initrd /initramfs-3.10.94-1.el6.elrepo.x86_64.img
title CentOS (2.6.32-431.el6.x86_64)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS.utf-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
    initrd /initramfs-2.6.32-431.el6.x86_64.img


确认刚安装好的内核在哪个位置,然后设置default值(从0开始),一般新安装的内核在第一个位置.所以设置default=0

2.安装docker
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
yum -y install docker-io*
service docker start
chkconfig docker on

如果启动docker出现如下错误:
/usr/bin/docker: relocation error: /usr/bin/docker: symbol dm_task_get_info_with_deferred_remove, version Base not defined in file libdevmapper.so.1.02 with link time reference

请执行下面的命令:
yum install device-mapper-event-libs

如果没问题了的话,我们来验证下docker,执行下面的命令:
docker --version
Docker version 1.7.1, build 786b29d/1.7.1

我这里显示的1.7.1的版本.好了,下面我们可以用docker来安装jenkins了.

3.docker安装jenkins
docker pull jenkinsci/jenkins

ps:因为我们项目指定了要这个

如果出现下面的错误:
unable to get remote tags: Get https://registry-1.docker.io/v1/repositories/library/jenkins/tags: dial tcp 218.93.250.18:443: connection timed out

请执行:
dig index.docker.io +noall +answer +nocomments
我这里看到有3个ip,如下:
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.5 <<>> index.docker.io +noall +answer +nocomments
;; global options: +cmd
index.docker.io.    251    IN    CNAME    elb-io.us-east-1.aws.dckr.io.
elb-io.us-east-1.aws.dckr.io. 530 IN    CNAME    us-east-1-elbio-rm5bon1qaeo4-623296237.us-east-1.elb.amazonaws.com.
us-east-1-elbio-rm5bon1qaeo4-623296237.us-east-1.elb.amazonaws.com. 31 IN A 54.164.250.255
us-east-1-elbio-rm5bon1qaeo4-623296237.us-east-1.elb.amazonaws.com. 31 IN A 54.152.78.181
us-east-1-elbio-rm5bon1qaeo4-623296237.us-east-1.elb.amazonaws.com. 31 IN A 52.0.10.162

我随便选了个ip加到hosts里
echo '54.208.179.150 registry-1.docker.io' >> /etc/hosts

然后再执行
docker pull jenkinsci/jenkins

如果下载成功了的话,我们来验证下:
docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
jenkinsci/jenkins   latest              bbb3fdd65bef        3 days ago          882.6 MB

ps:docker images 指令可以查询目前已pull回?淼?mage的清单及简易的资讯?热?
好了,然后我们来启动jenkins:
docker run -d -p 8080:8080 jenkinsci/jenkins
如果启动的时候报以下错误:
Cannot start container f12cdd095c6fcfc759e7986276b49d3647e02cc50e55ce9cf1559ed249617281: iptables failed: iptables -t nat -A DOCKER -p tcp -d 0/0 --dport 8080 -j DNAT --to-destination 172.17.0.8:8080 ! -i docker0: iptables: No chain/target/match by that name.\n (exit status 1)

解决办法:

*nat
:PREROUTING ACCEPT [27:11935]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [598:57368]
:POSTROUTING ACCEPT [591:57092]
:DOCKER - [0:0]
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
-A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
COMMIT
*filter
:INPUT ACCEPT [139291:461018923]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [127386:5251162]
:DOCKER - [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
COMMIT

然后保存退出并重启iptables.再来启动jenkins:
docker run -d -p 8080:8080 jenkinsci/jenkins

然后在浏览器里进行验证:
http://ip:8080


相关文章

  • centos 6.5安装docker和jenkins详解

    centos 6.5安装docker和jenkins详解

    下面我们来为各位介绍一篇关于centos 6.5安装docker和jenkins的例子,希望这篇文章能够帮助到各位朋友,有兴趣的朋友可以来看看吧.因公司项目的要求,让我在今天把docker和
    2016-01-10

最新评论