Stages表示构建阶段,说白了就是上面提到的流程。我们可以在一次Pipeline中定义多个Stages,这些Stages会有以下特点
-
会按照顺序运行
-
所有Stages完成,构建任务才会成功
-
一个Stage失败,后面的Stages不会执行,构建任务失败。
复制代码
- Jobs(任务)
Jobs表示构建工作,表示某个Stage里面执行的工作。我们可以在Stages里面定义多个Jobs,这些Jobs会有以下特点:
-
相同Stage中的Jobs会并行执行
-
相同Stage中的Jobs都执行成功时,该Stage才会成功
-
如果任何一个Job失败,那么该Stage失败,即该构建任务失败
复制代码
==============================================================================================
- 创建GitLab Runner持续集成容器的docker-compose.yml
version: ‘3.1’
services:
gitlab-runner:
镜像构建操作(build:+目录名字)
build: environment
restart: always
container_name: gitlab-runner
以真正的root管理员权限登入操作容器
privileged: true
volumes:
-
/usr/local/docker/runner/config:/etc/gitlab-runner
-
/var/run/docker.sock:/var/run/docker.sock
复制代码
- 创建GitLab Runner持续集成镜像的Dockerfile
FROM gitlab/gitlab-runner:v11.0.2
MAINTAINER mrchen 365984197@qq.com
修改软件源
RUN echo ‘deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse’ > /etc/apt/sources.list && \
echo ‘deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse’ >> /etc/apt/sources.list && \
echo ‘deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse’ >> /etc/apt/sources.list && \
echo ‘deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse’ >> /etc/apt/sources.list && \
apt-get update -y && \
apt-get clean
安装Docker
RUN apt-get -y install apt-transport-https ca-certificates curl software-properties-common && \
apt-get update && apt-get install -y gnupg2 && \
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add - && \
curl -fsSL get.docker.com -o get-docker.sh && \
sh get-docker.sh --mirror Aliyun
COPY daemon.json /etc/docker/daemon.json
安装Docker Compose
WORKDIR /usr/local/bin
RUN curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.0/docker-compose-uname -s
-uname -m
> /usr/local/bin/docker-compose
RUN chmod +x docker-compose
安装Java
RUN mkdir -p /usr/local/java
WORKDIR /usr/local/java
COPY jdk-8u251-linux-x64.tar.gz /usr/local/java
RUN tar -zxvf jdk-8u251-linux-x64.tar.gz && \
rm -fr jdk-8u251-linux-x64.tar.gz
安装Maven
RUN mkdir -p /usr/local/maven
WORKDIR /usr/local/maven
#RUN wget https://raw.githubusercontent.com/topsale/resources/master/maven/apache-maven-3.5.3-bin.tar.gz
COPY apache-maven-3.6.3-bin.zip /usr/local/maven
RUN apt-get install unzip
RUN unzip apache-maven-3.6.3-bin.zip && \
rm -fr apache-maven-3.6.3-bin.zip
COPY settings.xml /usr/local/maven/apache-maven-3.6.3-bin.zip/conf/setting.xml
配置环境变量
ENV JAVA_HOME /usr/local/java/jdk1.8.0_251
ENV MAVEN_HOME /usr/local/maven/apache-maven-3.6.3
ENV PATH P A T H : PATH: PATH:JAVE_HOME/bin:$MAVEN_HOME/bin
WORKDIR /
复制代码
- 注册Runner
docker exec -it gitlab-runner gitlab-runner register
输入 GitLab 地址
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://47.112.215.6/
输入 GitLab Token
Please enter the gitlab-ci token for this runner:
1Lxq_f1NRfCfeNbE5WRh
输入 Runner 的说明
Please enter the gitlab-ci description for this runner:
可以为空
设置 Tag,可以用于指定在构建规定的 tag 时触发 ci
Please enter this gitlab-ci tags for this runner (comma separated):
选择 runner 执行器,这里我们选择的是 shell
Please enter the executor:virtualbox, docker+machine,parallels,shell,ssh,docker-ssh+machine,kubernetes,docker,docker-ssh:
shell
复制代码
- 在项目工程下创建.gitlab-ci.yml文件
- 增加Dockerfile文件
FROM openjdk:8-jre
MAINTAINER mrchen <365984197qq.com>
ENV APP_VERSION 1.0.0-SNAPSHOT
等待其它应用上线的插件
#ENV DOCKERIZE_VERSION v0.6.1
#RUN weget https://github.com/jwilder/dockerize/releases/download/ D O C K E R I Z E V E R S I O N / d o c k e r i z e − l i n u x − a m d 64 − DOCKERIZE_VERSION/dockerize-linux-amd64- DOCKERIZEVERSION/dockerize−linux−amd64−DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz
RUN mkdir /app
COPY itoken-config-$APP_VERSION.jar /app/app.jar
执行多个初始化命令
#ENTRYPOINT [“dockerize”, “-timeout”, “5m”, “-wait”, “tcp://192.168.75.128:8888”, “java”, “-Djava.security.egd=file:/dev/./urandom”, “-jar”, “”]
ENTRYPOINT [“java”, “-Djava.security.egd=file:/dev/./urandom”, “-jar”, “/app/app.jar”, “–spring.profiles.active=prod”]
EXPOSE 8888
复制代码
- 增加docker-compose.yml文件
version: ‘3.1’
services:
itoken-config:
restart: always
image: 47.112.215.6:5000/itoken-config
container_name: itoken-config
ports:
- 8888:8888
复制代码
- 增加.gitlab-ci.yml文件
stages:
-
build
-
push
-
run
-
clean
build:
stage: build
script:
-
/usr/local/maven/apache-maven-3.6.3/bin/mvn clean package
-
cp target/itoken-config-1.0.0-SNAPSHOT.jar docker/
-
cd docker
-
docker build -t 47.112.215.6:5000/itoken-config .
push:
stage: push
script:
- docker push 47.112.215.6:5000/itoken-config
run:
stage: run
script:
-
cd docker
-
docker-compose down
-
docker-compose up -d
clean:
stage: clean
script:
- docker rmi $(docker images -q -f dangling=true)
复制代码
-
将上述文件提交到gitLab即可触发脚本
-
启动多个runner项目需要更改networks
version: ‘3.1’
services:
itoken-eureka:
restart: always
image: 47.112.215.6:5000/itoken-eureka
container_name: itoken-eureka
ports:
- 8761:8761
networks:
- eureka-network
networks:
eureka-network:
复制代码
=============================================================================
-
使用linux的ln软链接命令
-
使用docker的镜像重启回滚到以前版本
===============================================================================
- 添加druid连接池和mysql数据库配置
- 添加pom.xml依赖
<spring-boot-alibaba-druid.version>1.1.10</spring-boot-alibaba-druid.version>
<mysql.version>5.1.46</mysql.version>
com.alibaba
druid-spring-boot-starter
${spring-boot-alibaba-druid.version}
mysql
mysql-connector-java
${mysql.version}
runtime
复制代码
- 增加application.yml的datasource配置
datasource:
druid:
url: jdbc:mysql://ip:port/dbname?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root
password: 123456
initial-size: 1
min-idle: 1
max-active: 20
test-on-borrow: true
driver-class-name: com.mysql.jdbc.Driver
复制代码
- 配置tk.mybatis简化mybatis开发
- 添加依赖包
tk.mybatis
mapper-spring-boot-starter
2.0.2
复制代码
- 添加mybatis配置
-
添加MyMapper接口
-
添加PageHelper类方法
-
配置代码自动生成插件
=======================================================================================
-
编写测试用例(登陆和注册的测试用例)
-
根据用例方法编写实现
============================================================================================
- 基于端口的虚拟主机配置
- 添加docker-compose.yml文件
version: ‘3.1’
services:
nginx:
restart: always
image: nginx
container_name: nginx
ports:
-
81:80
-
9000:9000
volumes:
-
./conf/nginx.conf:/etc/nginx/nginx.conf
-
./wwwroot:/usr/share/nginx/wwwroot
复制代码
- 添加nginx.conf配置文件
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
配置虚拟主机 192.168.75.145
server {
监听的ip和端口,配置 192.168.75.145:80
listen 80;
虚拟主机名称这里配置ip地址
server_name 192.168.75.145;
所有的请求都以 / 开始,所有的请求都可以匹配此 location
location / {
使用root 指令指定虚拟主机目录即网页存放目录
比如访问 http://ip/index.html 将找到 /usr/local/docker/nginx/wwwroot/html80/index.html
比如访问 http://ip/item/index.html 将找到 /usr/local/docker/nginx/wwwroot/html80/item/index.html
root /usr/share/nginx/html80;
指定欢迎页面,按从左到右顺序查找
index index.html index.html
}
#}
配置虚拟主机 192.168.75.245
server {
listen 8080;
server_name 192.168.75.145;
location / {
root /usr/share/nginx/wwwroot/html8080;
index index.html index.html;
}
}
}
复制代码
- nginx的反向代理配置
server {
listen 80;
server_name itoken.mrchen.com;
location / {
proxy_pass http://192.168.75.128:9090;
index index.html index.htm;
}
}
复制代码
- nginx的负载均衡
upstream myapp1 {
server 192.168.94.132:9090 weight=10;
server 192.168.94.132:9091 weight=10;
}
server {
listen 80;
server_name 192.168.94.132
location / {
proxy_pass http://myapp1;
index index.jsp index.html index.htm;
}
}
复制代码
- nginx反向代理负载均衡实现伪CDN服务器
===============================================================================
-
缓存(数据查询、短连接、新闻内容、商品内容等等)
-
通过Redis HA(Redis高可用)的方式部署Redis服务
Redis HA高可用实现的技术
-
keepalived
-
zookeeper
-
sentinel(官方推荐)
复制代码
- 搭建redis集群 编辑docker-compose.yml文件
version: ‘3.1’
services:
master:
image: redis
container_name: redis-master
ports:
- 6379:6379
slave1:
image: redis
container_name: redis-slave-1
ports:
- 6380:6379
command: redis-server --slaveof redis-master 6379
slave2:
image: redis
container_name: redis-slave-2
ports:
- 6381:6379
command: redis-server --slaveof redis-master 6379
复制代码
- 搭建sentinel高可用监控服务 编辑docker-compose.yml配置
version: ‘3.1’
services:
sentinel1:
image: redis
container_name: redis-sentinel-1
ports:
- 26379:26379
command: redis-sentinel /usr/local/etc/redis/sentinel.conf
values:
- ./sentinel1.conf:/usr/local/etc/redis/sentinel.conf
sentinel2:
image: redis
container_name: redis-sentinel-2
ports:
- 26380:26379
command: redis-sentinel /usr/local/etc/redis/sentinel.conf
values:
- ./sentinel2.conf:/usr/local/etc/redis/sentinel.conf
sentinel3:
image: redis
container_name: redis-sentinel-3
ports:
- 26381:26379
command: redis-sentinel /usr/local/etc/redis/sentinel.conf
values:
- ./sentinel3.conf:/usr/local/etc/redis/sentinel.conf
复制代码
- 添加sentinel.conf配置复制代码
port 26379
dir /tmp
自定义集群名,其中 127.0.0.1 为 redis-master 的 ip, 6379 redis-master 的端口,2 为最小投票数 (因为有 3 台 Sentinel 所以可以设置成 2)
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
复制代码
- 使用lettuce连上redis服务
========================================================================================
- 添加redis的pom配置
org.apache.commons
spring-boot-starter-data-redis
org.springframework.boot
spring-boot-starter-data-redis
复制代码
- 添加redis的application.yml配置
spring:
redis:
lettuce:
pool:
max-active: 8
max-idle: 8
max-wait: -1ms
min-idle: 0
sentinel:
master: mymaster
nodes: 47.112.215.6:26379,47.112.215.6:26380,47.112.215.6:26381
复制代码
============================================================================================
通过Cookie共享的方式
-
首先,应用群域名要统一
-
其次,应用群各系统使用的技术要相同
-
第三,cookie本身不安全
通过Redis记录登陆信息的方式
复制代码
=======================================================================================
- 使用CORS(跨资源共享)解决跨域问题
- IE浏览器版本不能低于10
服务器端实现CORS接口即可,在header中设置:Access-Control-Allow-Origin
复制代码
-
使用JSONP解决跨域问题
-
使用Nginx反向代理解决跨域问题
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
配置虚拟主机 192.168.75.245
server {
listen 80;
server_name 47.112.215.6;
location / {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
root /usr/share/nginx;
index index.html index.html;
总结
虽然我个人也经常自嘲,十年之后要去成为外卖专员,但实际上依靠自身的努力,是能够减少三十五岁之后的焦虑的,毕竟好的架构师并不多。
架构师,是我们大部分技术人的职业目标,一名好的架构师来源于机遇(公司)、个人努力(吃得苦、肯钻研)、天分(真的热爱)的三者协作的结果,实践+机遇+努力才能助你成为优秀的架构师。
如果你也想成为一名好的架构师,那或许这份Java成长笔记你需要阅读阅读,希望能够对你的职业发展有所帮助。
其次,应用群各系统使用的技术要相同
- 第三,cookie本身不安全
通过Redis记录登陆信息的方式
复制代码
=======================================================================================
- 使用CORS(跨资源共享)解决跨域问题
- IE浏览器版本不能低于10
服务器端实现CORS接口即可,在header中设置:Access-Control-Allow-Origin
复制代码
-
使用JSONP解决跨域问题
-
使用Nginx反向代理解决跨域问题
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
配置虚拟主机 192.168.75.245
server {
listen 80;
server_name 47.112.215.6;
location / {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
root /usr/share/nginx;
index index.html index.html;
总结
虽然我个人也经常自嘲,十年之后要去成为外卖专员,但实际上依靠自身的努力,是能够减少三十五岁之后的焦虑的,毕竟好的架构师并不多。
架构师,是我们大部分技术人的职业目标,一名好的架构师来源于机遇(公司)、个人努力(吃得苦、肯钻研)、天分(真的热爱)的三者协作的结果,实践+机遇+努力才能助你成为优秀的架构师。
如果你也想成为一名好的架构师,那或许这份Java成长笔记你需要阅读阅读,希望能够对你的职业发展有所帮助。
[外链图片转存中…(img-cZbfAj6R-1714451226692)]