微服务项目发布
1. 微服务项目发布
[流水线] [创建]
[下一步]
[创建]
1.1 mall-gateway
确认项目中的路由配置都正确
mall-gateway/src/main/resources/application.yml
如果不一样就批量替换一下,一共7处
1.2 mall-auth-server
mall-auth-server
1.3 mall-cart
1.4 mall-coupon
1.5 mall-member
1.6 mall-order
1.7 mall-product
1.8 mall-search
1.9 mall-seckill
1.10 mall-third-party
1.11 mall-ware
1.12 renren-fast-master
没有意外的话,renren-fast发布成功,可以看到没有报错信息.如果失败,检查数据库连接,数据库用户名密码,数据库是否关闭了ssl(配置文件中skip-sll)
1.13 renren-generator-master
1.14 服务发布验证
依次发布,等待全部完成
全部发布完成后可以在nacos上看到12个服务已经被注册
2. 前端代理服务部署
2.1 制作sangomall-proxy镜像
mkdir nginx-proxy/htmp -p
cd nginx-proxy
conf/default.conf
upstream sangomall {
server mall-gateway.sangomall.svc.cluster.local.:8072
}
server {
listen 80;
listen [::]:80;
server_name *.intra.com;
location /static/ {
root /usr/share/nginx/html;
}
location / {
proxy_set_header Host $host;
proxy_pass http://sangomall;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
html
root@ks-master:~/nginx-proxy# ls -l html/
total 4
drwxr-xr-x 2 root root 23 Dec 20 09:54 es
-rw-r--r-- 1 root root 22 Dec 20 09:54 index.html
drwxr-xr-x 9 root root 94 Dec 20 09:54 static
将html目录压缩
cd html
tar czf html.tar.gz *
mv html.tar.gz ../
Dockerfile
FROM nginx
MAINTAINER nextgo@126.com
RUN rm -rf /etc/nginx/conf.d/*
COPY conf/* /etc/nginx/conf.d/
ADD html.tar.gz /usr/share/nginx/html/
EXPOSE 80
ENTRYPOINT nginx -g "daemon off;"
镜像打包上传
docker build -t harbor.intra.com/sangomall/sangomall-proxy:v1.0 .
docker push harbor.intra.com/sangomall/sangomall-proxy:v1.0
2.2 创建sangomall-proxy-nginx服务
[创建] [无状态服务]
sangomall-proxy-nginx
harbor.intra.com/sangomall/sangomall-proxy:v1.0
[下一步] [下一步] [创建]
2.3 创建路由
根据mall-gateway/src/main/resources/application.yml中关于HOST的配置添加路由.(一个7条)
- Host=mall.intra.com
- Host=item.intra.com
- Host=seckill.intra.com
- Host=search.intra.com
- Host=auth.intra.com
- Host=cart.intra.com
- Host=order.intra.com
[应用负载] [应用路由] [创建]
sangomall-proxy-nginx-route
[下一步] [添加路由规则]
mall.intra.com sangomall-proxy-nginx 80
item.intra.com sangomall-proxy-nginx 80
seckill.intra.com sangomall-proxy-nginx 80
search.intra.com sangomall-proxy-nginx 80
auth.intra.com sangomall-proxy-nginx 80
cart.intra.com sangomall-proxy-nginx 80
order.intra.com sangomall-proxy-nginx 80
[下一步] [添加元数据]
kubernetes.io/ingress.class apisix
[创建]
2.4 路由配置确认
创建后可以在apisix-dashboard中看到创建的路由
2.5 添加路由
因为所有路由都是通过apisix转发的,所以需要获取到apisix-gateway的地址,并将7条域名解析到apisix-gateway上.
root@ks-master:~# kubectl get svc -n apisix-system |grep apisix-gateway|awk '{print $4}'
192.168.31.211
添加域名解析
在dns服务器/var/named/intra.zone
[root@centos7-1 ~]# cat /var/named/intra.zone
$TTL 1d
@ IN SOA intra.com. admin.intra.com. (
0;
1H;
5M;
1W;
1D);
@ NS ns.intra.com.
ns A 192.168.31.17
harbor A 192.168.31.104
gitlab A 192.168.31.199
kibana A 192.168.31.212
rabbitmq A 192.168.31.211
web1 A 192.168.31.211
nacos-server A 192.168.31.211
zipkin-server A 192.168.31.211
sentinel A 192.168.31.211
skywalking-ui A 192.168.31.211
rocketmq-dashboard A 192.168.31.211
mall-gateway A 192.168.31.213
# 追加以下7条微服务解析
mall.intra.com A 192.168.31.211
item.intra.com A 192.168.31.211
seckill.intra.com A 192.168.31.211
search.intra.com A 192.168.31.211
auth.intra.com A 192.168.31.211
cart.intra.com A 192.168.31.211
order.intra.com A 192.168.31.211
重启named服务
[root@centos7-1 ~]# systemctl restart named
访问商场页面
访问查询页面
3. 管理后台发布
3.1 创建Service
[指定工作负载]
mall-gateway-external
选择[mall-gateway]
[外部访问]
lb.kubesphere.io/v1alpha1: openelb
protocol.openelb.kubesphere.io/v1alpha1: layer2
eip.openelb.kubesphere.io/v1alpha2: layer3-eip
[创建] 创建后获取到外部访问地址 [192.168.31.213]
3.2 修改mall-gateway连接
renren-fast-vue-master/static/config/index-prod.js
/**
* 生产环境
*/
;(function () {
window.SITE_CONFIG = {};
// api接口请求地址
window.SITE_CONFIG['baseUrl'] = 'http://mall-gateway.intra.com:8072/app';
// cdn地址 = 域名 + 版本号
window.SITE_CONFIG['domain'] = './'; // 域名
window.SITE_CONFIG['version'] = ''; // 版本号(年月日时分)
window.SITE_CONFIG['cdnUrl'] = window.SITE_CONFIG.domain + window.SITE_CONFIG.version;
})();
编译renren-fast项目
npm install node-sass@4.14
npm install
npm run build
完成之后会生成一个dist的目录
3.3 准备容器镜像
将文件夹上传到服务器
mkdir renren-fast
cd renren-fast
tar czf dist.tar.gz *
mv dist.tar.gz ../
cd ../
配置Dockerfile
FROM nginx
ADD dist.tar.gz /usr/share/nginx/html
EXPOSE 80
ENTRYPOINT nginx -g "daemon off;"
制作并上传镜像
docker build -t harbor.intra.com/sangomall/sangomall-admin:v1 .
docker push harbor.intra.com/sangomall/sangomall-admin:v1
3.4 项目部署
[应用负载] [服务] [创建]
sangomall-admin
harbor.intra.com/sangomall/sangomall-admin:v1
[下一步] [下一步] [创建]
3.5 编辑外部访问
编辑外部访问
lb.kubesphere.io/v1alpha1: openelb
protocol.openelb.kubesphere.io/v1alpha1: layer2
eip.openelb.kubesphere.io/v1alpha2: layer3-eip
标签追加后就可以看到eip被分配上
将此ip进行域名解析
$TTL 1d
@ IN SOA intra.com. admin.intra.com. (
0;
1H;
5M;
1W;
1D);
@ NS ns.intra.com.
ns A 192.168.31.17
harbor A 192.168.31.104
gitlab A 192.168.31.199
kibana A 192.168.31.212
rabbitmq A 192.168.31.211
web1 A 192.168.31.211
nacos-server A 192.168.31.211
zipkin-server A 192.168.31.211
sentinel A 192.168.31.211
skywalking-ui A 192.168.31.211
rocketmq-dashboard A 192.168.31.211
mall-gateway A 192.168.31.213
mall A 192.168.31.211
item A 192.168.31.211
seckill A 192.168.31.211
search A 192.168.31.211
auth A 192.168.31.211
cart A 192.168.31.211
order A 192.168.31.211
admin A 192.168.31.214
重启named服务
systemctl restart named
访问后台管理页
admin
admin
输入验证码后登陆,就可以在管理页面对商品进行上下架等处理.
至此基于KubeSphere的sangomall微服务商场项目发布完成.