Add (docker/Dockerfile) or modify: springcloud docker cluster / spring base / spring Eureka / SRC / main / docker/Dockerfile
/root/111/gitee_cangku/rancher_springcloud / is the path of the local warehouse:
Due to direct download java:8 image jenkins Card owner~Here, download the image and transfer it to the private warehouse, dockerfile Modify get from private warehouse docker pull java:8 docker tag java:8 192.168.109.137:5000/java:8 docker push 192.168.109.137:5000/java:8
vim /root/111/gitee_cangku/rancher_springcloud/spring-base/spring-eureka/src/main/docker/Dockerfile
FROM 192.168.109.137:5000/java:8 RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/timezone #Mount the local folder to the current container #VOLUME /tmp ADD spring-eureka-0.0.1-SNAPSHOT.jar app.jar #RUN ["/bin/bash","-c","touch /app.jar"] #Specify JAVA environment variables #ENV JAVA_HOME /jdk/jre #ENV PATH $PATH:$JAVA_HOME/bin #ENV CLASSPATH .:$JAVA_HOME/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar #Open 8000 ports EXPOSE 8000 #Configure the commands to be executed after the container starts ENTRYPOINT ["java","-jar","/app.jar"]
Modify in code dockerfile File (and resubmit and package it, which can be submitted together with the following) And modify: /root/111/gitee_cangku/rancher_springcloud/spring-base/spring-eureka/src/main/resources/Under directory Mutual registration: i.e application.yml Using active: 141(Namely application-141.yml),If the selected deployment machine tag is 138, then application-141.yml in hostname:ip It should be 139 machines My arrangement here is:141 corresponding application-141.yml (hostname:192.168.109.138)The deployment machine is 139 application-141.yml application-142.yml Medium hostname:ip address
spring: profiles: # active: 141 active: 142
server: port: 8000 eureka: client: service-url: defaultZone: http://${customConfig.security.username}:${customConfig.security.password}@${customConfig.eureka.server.hostname}:${server.port}/eureka/ register-with-eureka: true fetch-registry: true server: peer-node-read-timeout-ms: 2000 #The timeout for reading peer node server replication, in milliseconds. The default is 200 spring: application: name: spring-eureka security: user: name: ${customConfig.security.username} password: ${customConfig.security.password} management: endpoint: health: show-details: always #Health status-Show all details, otherwise show only status information customConfig: eureka: server: #Configuration of eureka hostname: 192.168.109.138 security: #security configuration username: admin password: admin123 #Eureka Server will create a scheduled task when it is started. By default, services in the current list that have timed out (90 seconds by default) and have not been renewed are excluded at regular intervals (60 seconds by default).
server: port: 8000 eureka: client: service-url: defaultZone: http://${customConfig.security.username}:${customConfig.security.password}@${customConfig.eureka.server.hostname}:${server.port}/eureka/ register-with-eureka: true fetch-registry: true server: peer-node-read-timeout-ms: 2000 #The timeout for reading peer node server replication, in milliseconds. The default is 200 spring: application: name: spring-eureka security: user: name: ${customConfig.security.username} password: ${customConfig.security.password} management: endpoint: health: show-details: always #Health status-Show all details, otherwise show only status information customConfig: eureka: server: #Configuration of eureka hostname: 192.168.109.139 security: #security configuration username: admin password: admin123 #Eureka Server will create a scheduled task when it is started. By default, services in the current list that have timed out (90 seconds by default) and have not been renewed are excluded at regular intervals (60 seconds by default).
Push the modified code according to the self environment to the remote:
git add .
git commit -m "description"
git push origin master # (git push origin local branch name: refs/remotes / remote branch name) just push the code to the remote
Build on jenkins:
Create a new task (spring cloud Eureka) -- build a maven project -- OK
Source code management (git, and configuration)
Remove tick from build trigger
spring-base/spring-eureka/pom.xml
clean package -Dmaven.test.skip=true
Click maven's advanced button
DEFAULT
Settings fileselect the setting s file in the file system
/var/jenkins_home/tools/hudson.tasks.Maven_MavenInstallation/jenkins-in-maven/conf/settings.xml
Select from add post build setup (execute shell)--
cp /var/jenkins_home/workspace/springcloud-eureka/spring-base/spring-eureka/src/main/docker/Dockerfile /var/jenkins_home/workspace/springcloud-eureka/spring-base/spring-eureka/target/
preservation
Install the cloud docker plug-in in jenkins:
System settings - add a Cloud docker (in my version, The cloud configuration has moved to a separate configuration page.) Click new page configuration -- add -- docker--Docker Cloud details, Put the docker Sock text
File written to Docker Host URL: unix:///var/run/docker.sock , click test, and you can see the version number after the test is successful; preservation
Continue to configure springcloud Eureka: configure the image construction of docker
Post Steps--Add post-build setp--Build/Publish Docker Image
Directory for dockerfile: / var/jenkins_home/workspace/springcloud-eureka/spring-base/spring-eureka/target/
Cloud select the name of the previously added docker cloud configuration: docker
Image: 192.168.109.137:5000/spring-eureka
Push image tick
Check Clean local images
preservation
Then jenkins builds it
View image after success: curl -XGET http://192.168.109.137:5000/v2/_catalog
rancher deploys eureka services and deploys workloads
spring-eureka
192.168.109.137:5000/spring-eureka
Port 8000 TCP HostPort 8000
Host scheduling deploy=worker because eureka needs to register with each other, so the previous label is not used here. We change it to iprange=138
Advanced options: whether the host network is selected for the network (yes). The -- net=host command will be added at startup in the background, indicating that the virtual network is not available
After eureka on 138 is started, we need to modify the configuration file in 139 code and repackage it;
My arrangement here is: 142 corresponds to application-142 YML (hostname:192.168.109.139) is deployed on 138 machines
vim /root/111/gitee_cangku/rancher_springcloud/spring-base/spring-eureka/src/main/resources/application.yml comment active: 141, enable active: 142
Submission Code:
git add .
git commit -m "modify configuration deployment 138"
git push origin master
jenkins repackages, 139 because the old version of the local package has been deployed, restarting will not affect, but will only change the image package of the warehouse
rancher clones a spring Eureka service and modifies it:
spring-eureka-138
Host scheduling: iprange = 138
Delete the image on 138 machine: docker RMI 192.168.109.137:5000 / spring Eureka: latest
Then start
Check:
1. Log view
2. When rancher visits the eureka registration page, he can see that DS Replicas is the mutual address, and both stations have been registered successfully, as follows:
SPRING-EUREKA n/a (2) (2) UP (2) - 192.168.109.138:spring-eureka:8000 , 192.168.109.139:spring-eureka:8000
The eureka cluster is now complete