实验环境是通过SVN提交代码,使用Jenkins一键发布到测试环境进行镜像build和站点安装测试,将DOCKER镜像上传到 私有镜像仓库,最终通过jenkins一键发布到正式环境
192.168.157.130 Jenkins svn registry
192.168.157.131 测试节点 docker
192.168.157.132 正式节点 docker
yum install -y subversion mkdir /home/svn #创建仓库目录 svnadmin create /home/svn/repos vi /home/svn/repos/conf/svnserve.conf anon-access = none auth-access = write password-db = passwd authz-db = authz vi /home/svn/repos/conf/passwd svnuser = 123456 vi /home/svn/repos/conf/authz [repos:/] svnuser = rw svnserve -d -r /home/svn ss -anltup | grep svn tcp LISTEN 0 7 *:3690 *:* users:(("svnserve",pid=10888,fd=3)) 仓库地址:svn://192.168.157.130/repos
使用客户端连接并上传一个测试的index.html文件,文件内容为 hello world!
2.1 Docker安装(所有节点)
cd /etc/yum.repos.d wget https://download.docker.com/linux/centos/docker-ce.repo yum install docker-ce -y systemctl start docker systemctl enable docker
2.2 私有镜像仓库安装
docker run -d / -v /opt/registry:/var/lib/registry / -p 5000:5000 / --restart=always / --name registry / Registry
2.3 所有节点 修改配置文件使之Pull镜像到我们的私有仓库
在部署节点配置Docker可信任私有仓库:
vi /etc/docker/daemon.json {"registry-mirrors": ["http://04be47cf.m.daocloud.io"],"insecure-registries":["192.168.157.130:5000"]} systemctl daemon-reload systemctl restart docker
2.4测试 是否可以访问
curl http://192.168.157.130:5000/v2/_catalog {"repositories":[]} 说明成功
3.1安装包下载地址:
http://mirrors.jenkins.io/war-stable/ http://maven.apache.org/download.cgi http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
3.2 安装jdk 和 maven
tar xf jdk-8u45-linux-x64.tar.gz tar xf apache-maven-3.5.0-bin.tar.gz mv jdk1.8.0_45/ /usr/local/jdk1.8 mv apache-maven-3.5.0 /usr/local/maven3.5 vim /etc/profile JAVA_HOME=/usr/local/jdk1.8 CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar MAVEN_HOME=/usr/local/maven3.5 PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH export JAVA_HOME CLASSPATH MAVEN_HOME PATH source /etc/profile 查看java版本 java -version
3.3安装启动Tomcat
tar zxvf apache-tomcat-8.0.46.tar.gz cd apache-tomcat-8.0.46/webapps rm -rf ROOT/* unzip /root/jenkins.war -d ROOT #启动tomcat ../bin/startup.sh Using CATALINA_BASE: /root/apache-tomcat-8.0.46 Using CATALINA_HOME: /root/apache-tomcat-8.0.46 Using CATALINA_TMPDIR: /root/apache-tomcat-8.0.46/temp Using JRE_HOME: /usr/local/jdk1.8 Using CLASSPATH: /root/apache-tomcat-8.0.46/bin/bootstrap.jar:/root/apache-tomcat-8.0.46/bin/tomcat-juli.jar Tomcat started. 说明Tomcat已经启动
3.4 配置Jenkins
Jenkins 访问地址:
http://192.168.157.130:8080
查看密码
cat /root/.jenkins/secrets/initialAdminPassword 4a5be2f79ecd4dd5b2e713db64a2a834
登陆进去后 选择自定义安装插件
增加管理员账号
Jenkins 配置
系统管理->系统设置:主要配置workspace目录,全局环境变量,邮件通知,其他插件配置等。
系统管理->Global Tool Configuration:主要配置JDK、Maven等工具。
在系统设置里面先配置好SSH连接各个部署节点信息,在创建项目中使用。
创建 ssh的连接凭据: 作用 发布版本需元远程连接 服务器 是ssh的用户和密码
系统设置
全局工具配置
制作nginx 镜像 和 php 镜像并上传到私有仓库,mysql镜像使用官方镜像即可
Nginx 和 php 的相关Dockerfile 文件和 软件包,配置文件放在一个名为Dockerfile-lnmp的文件夹中
目录结构
1.1 Nginx 的Dockerfile文件内容:
cat Dockerfile FROM centos:6 MAINTAINER zzzz RUN yum install -y gcc gcc-c++ make openssl-devel pcre-devel && / yum clean all ADD nginx-1.12.1.tar.gz /tmp RUN cd /tmp/nginx-1.12.1 && / ./configure --prefix=/usr/local/nginx && / make -j 2 && make install && / rm -rf /tmp/nginx-1.12.1 COPY nginx.conf /usr/local/nginx/conf EXPOSE 80 CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"]
1.2 Nginx 配置文件设置
cat nginx.conf user root; worker_processes auto; error_log logs/error.log info; pid logs/nginx.pid; events { use epoll; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; root html; index index.php index.html; location ~ /.php$ { root html; fastcgi_pass php-cgi:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }
1.3 build nginx镜像
docker build -t 192.168.157.130:5000/lnmp-nginx:base .
1.4 上传镜像到私有仓库
docker push 192.168.157.130:5000/lnmp-nginx:base
2.1 Php 的Dockerfile文件内容:
cat Dockerfile FROM centos:6 MAINTAINER zzzz RUN yum install -y gcc gcc-c++ gd-devel libxml2-devel / libcurl-devel libjpeg-devel libpng-devel openssl-devel && / yum clean all ADD php-5.6.31.tar.gz /tmp/ RUN cd /tmp/php-5.6.31 && / ./configure --prefix=/usr/local/php / --with-config-file-path=/usr/local/php/etc / --with-mysql --with-mysqli / --with-openssl --with-zlib --with-curl --with-gd / --with-jpeg-dir --with-png-dir --with-iconv / --enable-fpm --enable-zip --enable-mbstring && / make -j 4 && make install && / cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf && / sed -i "s/127.0.0.1/0.0.0.0/" /usr/local/php/etc/php-fpm.conf && / cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm && / chmod +x /etc/init.d/php-fpm && / rm -rf /tmp/php-5.6.31 COPY php.ini /usr/local/php/etc EXPOSE 9000 CMD /etc/init.d/php-fpm start && tail -F /var/log/messages
2.2 php.ini 文件内容都是默认的设置未做改变(可以直接从其他的php服务器中拷贝)
2.3 build php私有镜像
docker build -t 192.168.157.130:5000/lnmp-php:base
2.4 上传镜像到私有仓库
docker push 192.168.157.130:5000/lnmp-php:base
curl -L https://github.com/docker/compose/releases/download/1.22.0-rc2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose docker-compose -version docker-compose version 1.22.0-rc2, build 6817b533
aaaaaaaaaaaa