Kubernetes1.13.1 ingress traefik
一.traefick简介
Traefik是一个用Golang开发的轻量级的Http反向代理和负载均衡器。由于可以自动配置和刷新backend节点,目前可以被绝大部分容器平台支持,例如Kubernetes,Swarm,Rancher等。由于traefik会实时与Kubernetes API交互,所以对于Service的节点变化,traefik的反应会更加迅速。总体来说traefik可以在Kubernetes中完美的运行.
简单来说它就是用来作反向代理和负载均衡的,比较适用于微服务化的场景,支持多种分布式的Key-Value存储系统,支持容器技术,下面这个图诠释了它的工作
二.配置步骤
1.traefik.yaml的内容如下
apiVersion: v1 kind: ServiceAccount metadata: name: ingress namespace: kube-system --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: ingress subjects: - kind: ServiceAccount name: ingress namespace: kube-system roleRef: kind: ClusterRole name: cluster-admin apiGroup: rbac.authorization.k8s.io --- apiVersion: v1 kind: Service metadata: name: traefik-web-ui namespace: kube-system spec: selector: k8s-app: traefik-ingress-lb ports: - name: web port: 80 targetPort: 8580 --- apiVersion: extensions/v1beta1 kind: Ingress metadata: name: traefik-web-ui namespace: kube-system spec: rules: - host: traefik-ui.local http: paths: - path: / backend: serviceName: traefik-web-ui servicePort: web --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: traefik-ingress-lb namespace: kube-system labels: k8s-app: traefik-ingress-lb spec: replicas: 1 template: metadata: labels: k8s-app: traefik-ingress-lb name: traefik-ingress-lb spec: terminationGracePeriodSeconds: 60 hostNetwork: true restartPolicy: Always serviceAccountName: ingress nodeSelector: ingress: traefik containers: - image: traefik name: traefik-ingress-lb resources: limits: cpu: 20000m memory: 512Mi requests: cpu: 100m memory: 20Mi ports: - name: http containerPort: 80 hostPort: 80 - name: admin containerPort: 8580 hostPort: 8580 args: - --web - --web.address=: 8580 - --kubernetes |
2.给k8s node(该文档中为10.46.228.139)打标签
kubectl get no
kubectl label no 10.46.228.139 ingress=traefik
3.zxy9的traefik配置文件zxy9.yaml内容如下
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: traefik-ingress spec: rules: - host: datatest.zhixueyun.com http: paths: - path: /api/v1/system/ backend: serviceName: system-web-server servicePort: 8080 - path: /api/v1/course-study/ backend: serviceName: cs-web-server servicePort: 8080 - path: /api/v1/human/ backend: serviceName: human-resource-web servicePort: 8080 - path: /api/v1/exam/ backend: serviceName: exam-web-server servicePort: 8080 - path: /api/v1/training/ backend: serviceName: training-web-server servicePort: 8080 - path: /api/v1/microclass/ backend: serviceName: microclass-web-server servicePort: 8080 - path: /api/v1/ask-bar/ backend: serviceName: ask-bar-web-server servicePort: 8080 - path: /oauth/ backend: serviceName: oauth-provider servicePort: 8080 - path: /api/v1/zxy-log/ backend: serviceName: zxy-log-web-server servicePort: 8080 - path: /security-center/ backend: serviceName: security-center servicePort: 8080 - path: /api/v1/live/ backend: serviceName: live-web-server servicePort: 8080 - path: /api/v1/cloud-center/ backend: serviceName: cloud-web-server servicePort: 8080 - path: /api/v1/hr-sync/ backend: serviceName: hr-sync-web-server servicePort: 8080 - path: /api/v1/history/ backend: serviceName: history-web-server servicePort: 8080 - path: /api/v1/message/ backend: serviceName: message-send servicePort: 8080 - path: /api/v1/help-center/ backend: serviceName: help-center-web-server servicePort: 8080 |
由于quick-report-web的链接不规范,无法使用traefik负载均衡,比如有静态资源请求以quick-report-web开头,然后动态请求又有以quick-report-web开头,所以quick-report模块暂时不用traefik
4.启动服务
kubectl create -f traefik.yaml
kubectl create -f zxy9.yaml
5.启动之后原来通过nodePort代理的方式,可以改成代理到虚拟主机的方式,这样就不用记nodePort,然后配置还是动态更新,比如多一个docker容器,traefik会动态更新后端服务器
location /api/v1/human {
proxy_pass http://10.46.228.139:31146;
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $http_x_forwarded_for;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /api/v1/human { proxy_pass http://datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
6.zxy9 使用traefik代理之后,nginx的最终配置
user root; worker_processes 16 ; error_log logs/error-old.log warn; pid logs/nginx-old.pid; events { worker_connections 65535 ; } http { include /app/nginx/conf/mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128 ; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_body_timeout 600s; client_max_body_size 5000m; access_log on; sendfile on; tcp_nopush on; keepalive_timeout 600s; tcp_nodelay on; server_tokens off; fastcgi_connect_timeout 600s; fastcgi_send_timeout 600s; fastcgi_read_timeout 600s; fastcgi_buffer_size 128k; fastcgi_buffers 8 128k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; ##cache## proxy_connect_timeout 600s; proxy_read_timeout 600s; proxy_send_timeout 600s; proxy_buffer_size 32k; proxy_buffers 8 128k; proxy_busy_buffers_size 256k; proxy_temp_file_write_size 256k; proxy_temp_path /app/nginx/temp; proxy_cache_path /app/nginx/cache levels= 1 : 2 keys_zone=cache_one:200m inactive=1d max_size=30g; ##end## gzip on; gzip_min_length 1k; gzip_buffers 4 8k; gzip_http_version 1.1 ; gzip_types application/json text/plain application/x-javascript text/css application/xml; gzip_disable "MSIE [1-6]\." ; upstream fastdfs_address{ server localhost: 10402 ; } upstream zxy-scorm_address{ server localhost: 8000 ; } upstream fileInfo_address{ server localhost: 9000 ; } #server { # listen 80 ; # server_name *.zhixueyun.com; # default_type 'text/html' ; # charset utf- 8 ; # return 301 https: //$host$request_uri; # } server { listen 449 ; server_name_in_redirect off; port_in_redirect off; access_log /dev/ null ; error_log /dev/ null ; server_name *.zhixueyun.com; root /app/content/http/data/; add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS; location /testlogs { root /app/nginx/html/; autoindex on; autoindex_exact_size on; autoindex_localtime on; } location /installer { root /app/nginx/html/; } location /zxy-libs { root /app/nginx/html/; } location ~/fileInfo { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http: //fileInfo_address; } location /api/v1/security-center { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/hr-sync { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /oauth { proxy_set_header X-Forwarded-Scheme $scheme; root /app/nginx/html; #index_oauth index index-49dd2a6796.html; } location ~^/ default /M00/ { root /app/content/http/data/; } location /data { proxy_pass http: //data.zhixueyun.com; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /dashboard { root /app/nginx/html; } location /browser { root /app/nginx/html/; } location /subject { root /app/nginx/html; } location /quick-report-web { root /app/nginx/html; } location /vue-admin/ { alias /app/nginx/html/quick-report-web/; } location / { #upgrade_page.html # root /app/nginx/html/; # index upgrade_page.html; root /app/nginx/html/student; # #index_student index index-25a1429dd1.html; } location /admin { root /app/nginx/html/; #index_admin index index-5e065093a4.html; } location /live{ root /app/nginx/html/; } location /app{ root /app/nginx/html/; } location ~/hls{ root /app/nginx/html/; } location ~/mp4{ root /app/nginx/html/; } location ~/js-sdk{ root /app/nginx/html/; } location ~/scorm-file { root /app/content/; } location /pc/share/ { #如果是app if ($http_user_agent ~ "^((.*MIDP.*)|(.*WAP.*)|(.*UP.Browser.*)|(.*Smartphone.*)|(.*Obigo.*)|(.*Mobile.*)|(.*AU.Browser.*)|(.*wxd.Mms.*)|(.*WxdB.Browser.*)|(.*CLDC.*)|(.*UP.Link.*)|(.*KM.Browser.*)|(.*UCWEB.*)|(.*SEMC\-Browser.*)|(.*Mini.*)|(.*Symbian.*)|(.*Palm.*)|(.*Nokia.*)|(.*Panasonic.*)|(.*MOT\-.*)|(.*SonyEricsson.*)|(.*NEC\-.*)|(.*Alcatel.*)|(.*Ericsson.*)|(.*BENQ.*)|(.*BenQ.*)|(.*Amoisonic.*)|(.*Amoi\-.*)|(.*Capitel.*)|(.*PHILIPS.*)|(.*SAMSUNG.*)|(.*Lenovo.*)|(.*Mitsu.*)|(.*Motorola.*)|(.*SHARP.*)|(.*WAPPER.*)|(.*LG\-.*)|(.*LG/.*)|(.*EG900.*)|(.*CECT.*)|(.*Compal.*)|(.*kejian.*)|(.*Bird.*)|(.*BIRD.*)|(.*G900/V1.0.*)|(.*Arima.*)|(.*CTL.*)|(.*TDG.*)|(.*Daxian.*)|(.*DAXIAN.*)|(.*DBTEL.*)|(.*Eastcom.*)|(.*EASTCOM.*)|(.*PANTECH.*)|(.*Dopod.*)|(.*Haier.*)|(.*HAIER.*)|(.*KONKA.*)|(.*KEJIAN.*)|(.*LENOVO.*)|(.*Soutec.*)|(.*SOUTEC.*)|(.*SAGEM.*)|(.*SEC\-.*)|(.*SED\-.*)|(.*EMOL\-.*)|(.*INNO55.*)|(.*ZTE.*)|(.*iPhone.*)|(.*Android.*)|(.*Windows CE.*)|(java.*)|(Opera.*))$" ) { rewrite ^ https: //$host/app/share; } #如果是pc rewrite ^ https: //$host; } # location ^~ /oauth/api/v1/app-login/ { # proxy_set_header X-Forwarded-Scheme $scheme; # proxy_pass http: //datatest.zhixueyun.com/oauth/api/v1/app-login-old/; # proxy_set_header Host $host; # proxy_set_header X-Real-Ip $http_x_forwarded_for; # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # proxy_set_header Upgrade $http_upgrade; # proxy_set_header Connection "upgrade" ; # proxy_set_header X-Forwarded-URI $request_uri; # } location ^~ /oauth/api/v1 { proxy_set_header X-Forwarded-Scheme $scheme; proxy_pass http: //datatest.zhixueyun.com/oauth; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; proxy_set_header X-Forwarded-URI $request_uri; } location ^~ /oauth/auth { proxy_set_header X-Forwarded-Scheme $scheme; proxy_pass http: //datatest.zhixueyun.com/oauth/auth; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; proxy_set_header X-Forwarded-URI $request_uri; } location /api/v1/microclass { proxy_pass http: //10.46.228.139:31176; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/ { proxy_set_header X-Forwarded-Scheme $scheme; proxy_pass http: //datatest.zhixueyun.com/; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /auth { proxy_set_header X-Forwarded-Scheme $scheme; proxy_pass http: //datatest.zhixueyun.com/auth; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /quick-report-web/api/ { proxy_pass http: //10.46.228.139:31168/; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location / static / { proxy_pass http: //10.46.228.139:31168/static/; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /quick-report-web/compute/ { proxy_pass http: //10.46.228.139:31168/compute/; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /quick-report-web/reportInfo/ { proxy_pass http: //10.46.228.139:31168/reportInfo/; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /quick-report { proxy_pass http: //10.46.228.139:31168; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /node/api/v1/ { proxy_pass http: //10.46.228.139:31186/; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /logs { root /app/nginx/html/; autoindex on; autoindex_exact_size on; autoindex_localtime on; # auth_basic "secret" ; # auth_basic_user_file /app/nginx/conf/.logs_passwd.db; } location ~/zxy-scorm { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http: //zxy-scorm_address; } location ^~ /scorm-unzip { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http: //zxy-scorm_address; } location ^~ /demo { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http: //zxy-scorm_address; } location ^~ /videojs { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http: //zxy-scorm_address; } location /admin/ default /M00 { alias /app/content/http/data/ default /M00; } location ~^/ default /M00/.*(?<!\.mp4|/)$ { root /app/content/http/data/; ngx_fastdfs_module; } location ~^/ default /M00/.*\.(mp4)$ { mp4; } error_page 500 404 / 404 .html; location = / 404 .html { root /app/nginx/html; internal; } error_page 400 = 200 @400 ; location @400 { root /app/content/http/data; } location /cloud { root /app/nginx/html; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/human { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/help-center { proxy_pass http: //10.46.228.139:31183; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/history { proxy_set_header X-Forwarded-Scheme $scheme; proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/system { access_log logs/system.logs; proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/message { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/zxy-log { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/report { proxy_pass http: //10.46.228.139:31166; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /api/v1/exam/ws { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /api/v1/exam { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /api/v1/course-study { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/ask-bar { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/ask-bar/ws { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /api/v1/training { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/training/ws { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /api/v1/cloud-center { proxy_pass http: //10.46.228.139:31154; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/cloud-center/ws { proxy_pass http: //10.46.228.139:31154; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /api/v1/live { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /ws/live/ { proxy_pass http: //10.46.228.139:31192/; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } ############## 443 #################### server { listen 443 ; server_name_in_redirect off; port_in_redirect off; access_log /dev/ null ; error_log /dev/ null ; server_name *.zhixueyun.com; root /app/content/http/data/; add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS; ssl on; ssl_certificate /app/nginx/conf/server.crt; ssl_certificate_key /app/nginx/conf/server.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1. 1 TLSv1. 2 ; ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; ssl_prefer_server_ciphers off; location /zxy-libs { root /app/nginx/html/; } location ~/fileInfo { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http: //fileInfo_address; } location /api/v1/security-center { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/hr-sync { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /oauth { proxy_set_header X-Forwarded-Scheme $scheme; root /app/nginx/html; #index_oauth index index-49dd2a6796.html; } location ~^/ default /M00/ { root /app/content/http/data/; } location /data { proxy_pass http: //data.zhixueyun.com; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /dashboard { root /app/nginx/html; } location /browser { root /app/nginx/html/; } location /subject { root /app/nginx/html; } location /quick-report-web { root /app/nginx/html; } location /vue-admin/ { alias /app/nginx/html/quick-report-web/; } location / { root /app/nginx/html/student; # #index_student index index-25a1429dd1.html; } location /admin { root /app/nginx/html/; #index_admin index index-5e065093a4.html; } location /live{ root /app/nginx/html/; } location /app{ root /app/nginx/html/; } location ~/hls{ root /app/nginx/html/; } location ~/scorm-file { root /app/content/; } location /pc/share/ { #如果是app if ($http_user_agent ~ "^((.*MIDP.*)|(.*WAP.*)|(.*UP.Browser.*)|(.*Smartphone.*)|(.*Obigo.*)|(.*Mobile.*)|(.*AU.Browser.*)|(.*wxd.Mms.*)|(.*WxdB.Browser.*)|(.*CLDC.*)|(.*UP.Link.*)|(.*KM.Browser.*)|(.*UCWEB.*)|(.*SEMC\-Browser.*)|(.*Mini.*)|(.*Symbian.*)|(.*Palm.*)|(.*Nokia.*)|(.*Panasonic.*)|(.*MOT\-.*)|(.*SonyEricsson.*)|(.*NEC\-.*)|(.*Alcatel.*)|(.*Ericsson.*)|(.*BENQ.*)|(.*BenQ.*)|(.*Amoisonic.*)|(.*Amoi\-.*)|(.*Capitel.*)|(.*PHILIPS.*)|(.*SAMSUNG.*)|(.*Lenovo.*)|(.*Mitsu.*)|(.*Motorola.*)|(.*SHARP.*)|(.*WAPPER.*)|(.*LG\-.*)|(.*LG/.*)|(.*EG900.*)|(.*CECT.*)|(.*Compal.*)|(.*kejian.*)|(.*Bird.*)|(.*BIRD.*)|(.*G900/V1.0.*)|(.*Arima.*)|(.*CTL.*)|(.*TDG.*)|(.*Daxian.*)|(.*DAXIAN.*)|(.*DBTEL.*)|(.*Eastcom.*)|(.*EASTCOM.*)|(.*PANTECH.*)|(.*Dopod.*)|(.*Haier.*)|(.*HAIER.*)|(.*KONKA.*)|(.*KEJIAN.*)|(.*LENOVO.*)|(.*Soutec.*)|(.*SOUTEC.*)|(.*SAGEM.*)|(.*SEC\-.*)|(.*SED\-.*)|(.*EMOL\-.*)|(.*INNO55.*)|(.*ZTE.*)|(.*iPhone.*)|(.*Android.*)|(.*Windows CE.*)|(java.*)|(Opera.*))$" ) { rewrite ^ https: //$host/app/share; } #如果是pc rewrite ^ https: //$host; } location ^~ /oauth/api/v1/app-login/ { proxy_set_header X-Forwarded-Scheme $scheme; proxy_pass http: //datatest.zhixueyun.com/oauth/api/v1/app-login-old/; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; proxy_set_header X-Forwarded-URI $request_uri; } location ^~ /oauth/api/v1 { proxy_set_header X-Forwarded-Scheme $scheme; proxy_pass http: //datatest.zhixueyun.com/oauth; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; proxy_set_header X-Forwarded-URI $request_uri; } location ^~ /oauth/auth { proxy_set_header X-Forwarded-Scheme $scheme; proxy_pass http: //datatest.zhixueyun.com/oauth/auth; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; proxy_set_header X-Forwarded-URI $request_uri; } location /api/v1/microclass { proxy_pass http: //10.46.228.139:31176; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/ { proxy_set_header X-Forwarded-Scheme $scheme; proxy_pass http: //datatest.zhixueyun.com/; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /auth { proxy_set_header X-Forwarded-Scheme $scheme; proxy_pass http: //datatest.zhixueyun.com/auth; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /quick-report-web/api/ { proxy_pass http: //10.46.228.139:31168/; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location / static / { proxy_pass http: //10.46.228.139:31168/static/; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /quick-report-web/compute/ { proxy_pass http: //10.46.228.139:31168/compute/; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /quick-report-web/reportInfo/ { proxy_pass http: //10.46.228.139:31168/reportInfo/; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /quick-report { proxy_pass http: //10.46.228.139:31168; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /node/api/v1/ { proxy_pass http: //10.46.228.139:31186/; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /logs { root /app/nginx/html/; autoindex on; autoindex_exact_size on; autoindex_localtime on; auth_basic "secret" ; auth_basic_user_file /app/nginx/conf/.logs_passwd.db; } location ~/zxy-scorm { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http: //zxy-scorm_address; } location ^~ /scorm-unzip { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http: //zxy-scorm_address; } location ^~ /demo { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http: //zxy-scorm_address; } location ^~ /videojs { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http: //zxy-scorm_address; } location /admin/ default /M00 { alias /app/content/http/data/ default /M00; } location ~^/ default /M00/.*(?<!\.mp4|/)$ { root /app/content/http/data/; ngx_fastdfs_module; } location ~^/ default /M00/.*\.(mp4)$ { mp4; } error_page 500 404 / 404 .html; location = / 404 .html { root /app/nginx/html; internal; } error_page 400 = 200 @400 ; location @400 { root /app/content/http/data; } location /cloud { root /app/nginx/html; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/human { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/help-center { proxy_pass http: //10.46.228.139:31183; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/history { proxy_set_header X-Forwarded-Scheme $scheme; proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/system { #access_log logs/system.logs; proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/message { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/zxy-log { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/report { proxy_pass http: //10.46.228.139:31166; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /api/v1/exam/ws { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /api/v1/exam { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /api/v1/course-study { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/ask-bar { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/ask-bar/ws { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /api/v1/training { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/training/ws { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /api/v1/cloud-center { proxy_pass http: //10.46.228.139:31154; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /api/v1/cloud-center/ws { proxy_pass http: //10.46.228.139:31154; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_http_version 1.1 ; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; } location /api/v1/live { proxy_pass http: //datatest.zhixueyun.com; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location /ws/live/ { proxy_pass http: //10.46.228.139:31192/; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade" ; proxy_set_header Host $host; proxy_set_header X-Real-Ip $http_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } server { listen 443 ; server_name_in_redirect off; port_in_redirect off; access_log /dev/ null ; server_name localhost; root /app/nginx/html/; location /testlogs { root /app/nginx/html/; autoindex on; autoindex_exact_size on; autoindex_localtime on; } } } |
6.traefik的控制台链接
7.修改nginx服务器配置/etc/hosts(10.46.228.139为traefik-ingress-controller的运行服务器ip),添加虚拟主机datatest.zhixueyun.com对应的ip:10.46.228.139
10.46.228.139 datatest.zhixueyun.com
8.经性能测试发现,traefik负载均衡性能良好,比使用nodePort做负载均衡可以提升10个tps,但是跟自己安装的haproxy比起来,性能还是不行,可以参考如下文档,搭建haproxy
7.1 使用自己搭建的haproxy,测试出来的考试性能
7.2 使用ingress traefik测试出来的考试性能,traefik在高并发的场景下,会出现假死的情况