Docker主机3000端口运行grafana容器

[root@docker ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES
73f050ab8df1        grafana/grafana     "/run.sh"           12 days ago         Up 2 seconds        0.0.0.0:3000->3000/tcp   silly_dijkstra

修改hosts文件用于局域网测试nginx

10.0.1.10 grafana.c.com

10.0.1.10 nginx.c.com

修改nginx配置文件

[root@docker ~]# vim /etc/nginx/conf.d/default.conf

添加upstream和server段

#负载均衡可选
#upstream grafana{
#server 10.0.1.10:3000;
#}
server {
    listen 80;
    server_name grafana.c.com;
    location /{
    proxy_pass http://10.0.1.10:3000;
}

浏览器访问 nginx.c.com 显示默认页面

浏览器访问 grafana.c.com 显示grafana登录页面

错误信息 nginx显示502错误 查看错误日志

[root@docker ~]# cat /var/log/nginx/error.log

connect() to 10.0.1.10:3000 failed (13: Permission denied) while connecting to upstream

需要关闭SELINUX

负载均衡

策略:轮询

upstream lunxun{
    server localhost:8080;
    server localhost 8081;
}

权重

upstream quanzhong{
    server localhost:8080 weight=3 ;
    server localhost 8081 weight=1 ;
}

iphash

upstream quanzhong{
    ip_hash;
    server localhost:8080;
    server localhost 8081;
}

最少连接数

upstream quanzhong{
    least_conn;
    server localhost:8080;
    server localhost 8081;
}

fair

按后端服务器响应时间分配
upstream quanzhong{
    server localhost:8080;
    server localhost 8081;
    fair;
}

完整示例(轮询)

http {
    upstream lunxun {
    server localhost:8080;
    server localhost 8081;
    }

    server {
    listen 80;
    server_name localhost;

    localtion / {
      pross_pass http://lunxun;
    } 

    }
}
Last modification:February 20th, 2021 at 03:02 pm
If you think my article is useful to you, please feel free to appreciate