基础架构
主机名 | 角色 | ip |
HDSS7-11.host.com |
k8s代理节点1,zk1 |
10.4.7.11 |
HDSS7-12.host.com |
k8s代理节点2,zk2 |
10.4.7.12 |
HDSS7-21.host.com |
k8s运算节点1,zk3 |
10.4.7.21 |
HDSS7-22.host.com |
k8s运算节点2,jenkins |
10.4.7.22 |
HDSS7-200.host.com |
k8s运维节点(docker仓库) |
10.4.7.200 |
部署zookeeper
安装jdk1.8(3台zk角色主机)
jdk下载地址
jdk1.6
jdk1.7
jdk1.8
/opt/src
1 2 3 4 5 6 7 8 9
|
[root@hdss7-11 src]# ls -l|grep jdk -rw-r--r-- 1 root root 153530841 Jan 17 17:49 jdk-8u201-linux-x64.tar.gz [root@hdss7-11 src]# mkdir /usr/java [root@hdss7-11 src]# tar xf jdk-8u201-linux-x64.tar.gz -C /usr/java [root@hdss7-11 src]# ln -s /usr/java/jdk1.8.0_201 /usr/java/jdk [root@hdss7-11 src]# vi /etc/profile export JAVA_HOME=/usr/java/jdk export PATH=$JAVA_HOME/bin:$JAVA_HOME/bin:$PATH export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
|
安装zookeeper(3台zk角色主机)
zk下载地址
zookeeper
解压、配置
/opt/src
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
[root@hdss7-11 src]# ls -l|grep zoo -rw-r--r-- 1 root root 153530841 Jan 17 18:10 zookeeper-3.4.14.tar.gz [root@hdss7-11 src]# tar xf /opt/src/zookeeper-3.4.14.tar.gz -C /opt [root@hdss7-11 opt]# ln -s /opt/zookeeper-3.4.14/ /opt/zookeeper [root@hdss7-11 opt]# mkdir -pv /data/zookeeper/data /data/zookeeper/logs [root@hdss7-11 opt]# vi /opt/zookeeper/conf/zoo.cfg tickTime=2000 initLimit=10 syncLimit=5 dataDir=/data/zookeeper/data dataLogDir=/data/zookeeper/logs clientPort=2181 server.1=zk1.od.com:2888:3888 server.2=zk2.od.com:2888:3888 server.3=zk3.od.com:2888:3888
|
注意:各节点zk配置相同。
myid
HDSS7-11.host.com
上:
/data/zookeeper/data/myid
HDSS7-12.host.com
上:
/data/zookeeper/data/myid
HDSS7-21.host.com
上:
/data/zookeeper/data/myid
做dns解析
HDSS7-11.host.com
上
/var/named/od.com.zone
1 2 3
|
zk1 60 IN A 10.4.7.11 zk2 60 IN A 10.4.7.12 zk3 60 IN A 10.4.7.21
|
依次启动
1 2 3 4
|
[root@hdss7-11 opt]# /opt/zookeeper/bin/zkServer.sh start ZooKeeper JMX enabled by default Using config: /opt/zookeeper/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
|
部署jenkins
准备镜像
jenkins官网
jenkins镜像
在运维主机下载官网上的稳定版(这里下载2.164.1)
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
|
[root@hdss7-200 ~]# docker pull jenkins/jenkins:2.164.1 2.164.1: Pulling from jenkins/jenkins 22dbe790f715: Pull complete 0250231711a0: Pull complete 6fba9447437b: Pull complete c2b4d327b352: Pull complete cddb9bb0d37c: Pull complete b535486c968f: Pull complete f3e976e6210c: Pull complete b2c11b10291d: Pull complete f4c0181e1976: Pull complete 924c8e712392: Pull complete d13006b7c9dd: Pull complete fc80aeb92627: Pull complete 36a6e96ba1b5: Pull complete f50f33dc1d0a: Pull complete b10642432117: Pull complete 850c260511d8: Pull complete 47f95e65a629: Pull complete 3b33ce546dc6: Pull complete 051c7665e760: Pull complete fe379aecc538: Pull complete Digest: sha256:12fd14965de7274b5201653b2bffa62700c5f5f336ec75c945321e2cb70d7af0 Status: Downloaded newer image for jenkins/jenkins:2.164.1
[root@hdss7-200 ~]# docker tag 256cb12e72d6 harbor.od.com/public/jenkins:v2.164.1 [root@hdss7-200 ~]# docker push harbor.od.com/public/jenkins:v2.164.1
|
自定义Dockerfile
在运维主机HDSS7-200.host.com
上编辑自定义dockerfile
/data/dockerfile/jenkins/Dockerfile
1 2 3 4 5 6 7 8 9
|
FROM harbor.od.com/public/jenkins:v2.164.1 USER root RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone ADD id_rsa /root/.ssh/id_rsa ADD config.json /root/.docker/config.json ADD get-docker.sh /get-docker.sh RUN echo " StrictHostKeyChecking no" >> /etc/ssh/sshd_config && /get-docker.sh
|
这个Dockerfile里我们主要做了以下几件事
- 设置容器用户为root
- 设置容器内的时区
- 将ssh私钥加入(使用git拉代码时要用到,配对的公钥应配置在gitlab中)
- 加入了登录自建harbor仓库的config文件
- 修改了ssh客户端的
- 安装一个docker的客户端
生成ssh密钥对:
1
|
[root@hdss7-200 ~]# ssh-keygen -t rsa -b 2048 -C "stanley.wang.m@qq.com" -N "" -f /root/.ssh/id_rsa
|
1 2 3 4 5 6 7
|
{ "auths": { "harbor.od.com": { "auth": "YWRtaW46SGFyYm9yMTIzNDU=" } } }
|
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |