centos 6.5安装docker和jenkins

post by rocdk890 / 2015-12-25 10:58 Friday linux技术
 因公司项目的要求,让我在今天把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
# 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 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
    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 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
    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
*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
# Completed on Sun Sep 20 17:35:31 2015
# Generated by iptables-save v1.4.21 on Sun Sep 20 17:35:31 2015
*filter
:INPUT ACCEPT [139291:461018923]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [127386:5251162]
:DOCKER - [0:0]
-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

如果可以看到下图,那就表示你jenkins启动成功了.
点击查看原图
好了,docker+jenkins的配置就到这里了,剩下的请自己去探索研究了.
夜空- 本站版权
1、本站所有主题由该文章作者发表,该文章作者与夜空享有文章相关版权
2、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和夜空的同意
3、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、原文链接:blog.slogra.com/post-620.html

标签: centos iptables 安装 docker jenkins

  1. 2017-02-17 11:49
    @铁匠运维网:安装好后进jenkins是没有密码的,除非你自己设置过了.
  1. gravatar 铁匠运维网
    2017-02-16 16:05
    浏览器ip:8080这个地方进来后,需要输入jenkins的密码。这个密码是在哪里存放的呢?或者说,这个密码是什么嗯?

评论: