当前位置: > CentOS > CentOS教程 >

centos 6.5安装docker和jenkins

时间:2016-06-05 00:09来源:linux.it.net.cn 作者:IT
因公司项目的要求,让我在今天把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 kernel-lt-headers -y
或者安装kernel-ml(ml=mainline)
yum --enablerepo=elrepo-kernel install kernel-ml kernel-ml-headers -y

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

编辑grub.conf文件,修改Grub引导顺序
vi /etc/grub.conf
01 # grub.conf generated by anaconda
02 #
03 # Note that you do not have to rerun grub after making changes to this file
04 # NOTICE:  You have a /boot partition.  This means that
05 #          all kernel and initrd paths are relative to /boot/, eg.
06 #          root (hd0,0)
07 #          kernel /vmlinuz-version ro root=/dev/mapper/VolGroup-lv_root
08 #          initrd /initrd-[generic-]version.img
09 #boot=/dev/sda
10 default=0
11 timeout=5
12 splashimage=(hd0,0)/grub/splash.xpm.gz
13 hiddenmenu
14 title CentOS (3.10.94-1.el6.elrepo.x86_64)
15     root (hd0,0)
16     kernel /vmlinuz-3.10.94-1.el6.elrepo.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.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
17     initrd /initramfs-3.10.94-1.el6.elrepo.x86_64.img
18 title CentOS (2.6.32-431.el6.x86_64)
19     root (hd0,0)
20     kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.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
21     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回來的image的清单及简易的资讯內容.
好了,然后我们来启动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)

解决办法:
cp /etc/sysconfig/iptables /etc/sysconfig/iptables.bak
vi /etc/sysconfig/iptables
01 *nat
02 :PREROUTING ACCEPT [27:11935]
03 :INPUT ACCEPT [0:0]
04 :OUTPUT ACCEPT [598:57368]
05 :POSTROUTING ACCEPT [591:57092]
06 :DOCKER - [0:0]
07 -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
08 -A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
09 -A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE
10 COMMIT
11 # Completed on Sun Sep 20 17:35:31 2015
12 # Generated by iptables-save v1.4.21 on Sun Sep 20 17:35:31 2015
13 *filter
14 :INPUT ACCEPT [139291:461018923]
15 :FORWARD ACCEPT [0:0]
16 :OUTPUT ACCEPT [127386:5251162]
17 :DOCKER - [0:0]
18 -A FORWARD -o docker0 -j DOCKER
19 -A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
20 -A FORWARD -i docker0 ! -o docker0 -j ACCEPT
21 -A FORWARD -i docker0 -o docker0 -j ACCEPT
22 COMMIT

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

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

如果可以看到下图,那就表示你jenkins启动成功了.

点击查看原图

好了,docker+jenkins的配置就到这里了,剩下的请自己去探索研究了.


(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容