gpt4 book ai didi

nginx - 如何在 mlFlow 服务器上运行身份验证?

转载 作者:行者123 更新时间:2023-12-04 17:54:18 24 4
gpt4 key购买 nike

当我将我的整个模型和参数记录到 mlflow 中时,我认为将其置于用户名和密码下进行保护是个好主意。

我使用以下代码运行mlflow服务器
mlflow server --host 0.0.0.0 --port 11111完美运行,在我的浏览器中输入 myip:11111我看到了一切(最终是问题所在)

如果我理解文档和以下内容 https://groups.google.com/forum/#!topic/mlflow-users/E9QW4HdS8a8此处链接正确,我应该使用 nginx 来创建身份验证。

我安装了 nginx open sourcreapache2-utils
已创建 sudo htpasswd -c /etc/apache2/.htpasswd user1用户和密码。

我编辑了我的 /etc/nginx/nginx.conf到以下几点:

server {
listen 80;
listen 443 ssl;

server_name my_ip;
root NOT_SURE_WHICH_PATH_TO_PUT_HERE, THE VENV?;
location / {
proxy_pass my_ip:11111/;
auth_basic "Restricted Content";
auth_basic_user_file /home/path to the password file/.htpasswd;
}
}

但没有出现身份验证。

如果我改变 conf 来听 listen 11111我收到一个错误,该端口已在使用中(当然,由 mlflow 服务器....)

我的愿望是在任何人都可以使用浏览器通过 mlflow 输入之前有一个身份验证窗口。

很高兴听到任何建议。

最佳答案

这里的问题是 mlflownginx正在尝试在 上运行同一个端口 ...

  • 首先让我们处理nginx:

    1.1 在/etc/nginx/sites-enable 新建一个文件 sudo nano mlflow并删除现有的默认值。

    1.2 在 mlflow 文件中:
  • server {
    listen YOUR_PORT;
    server_name YOUR_IP_OR_DOMAIN;
    auth_basic “Administrator’s Area”;
    auth_basic_user_file /etc/apache2/.htpasswd; #read the link below how to set username and pwd in nginx

    location / {
    proxy_pass http://localhost:8000;
    include /etc/nginx/proxy_params;
    proxy_redirect off;
    }
    }

    1.3.重启nginx sudo systemctl restart nginx
  • 在您的服务器上运行 mlflow mlflow server --host localhost --port 8000

  • 现在,如果您尝试在浏览器中访问 YOUR_IP_OR_DOMAIN:YOUR_PORT ,应该会出现一个身份验证弹出窗口,输入您的主机并通过,现在您进入了 mlflow
  • 现在有 2 个选项可以告诉 mlflow 服务器有关它的信息:

    3.1 设置用户名和密码为环境变量export MLFLOW_TRACKING_USERNAME=user export MLFLOW_TRACKING_PASSWORD=pwd
    3.2 在您的 /venv/lib/python3.6/site-packages/mlflowpackages/mlflow/tracking/_tracking_service/utils.py 中编辑函数
  • def _get_rest_store(store_uri, **_):
    def get_default_host_creds():
    return rest_utils.MlflowHostCreds(
    host=store_uri,
    username=replace with nginx user
    password=replace with nginx pwd
    token=os.environ.get(_TRACKING_TOKEN_ENV_VAR),
    ignore_tls_verification=os.environ.get(_TRACKING_INSECURE_TLS_ENV_VAR) == 'true',
    )

    在您使用 mlflow 的 .py 文件中:
    import mlflow
    remote_server_uri = "YOUR_IP_OR_DOMAIN:YOUR_PORT" # set to your server URI
    mlflow.set_tracking_uri(remote_server_uri)
    mlflow.set_experiment("/my-experiment")
    with mlflow.start_run():
    mlflow.log_param("a", 1)
    mlflow.log_metric("b", 2)

    nginx 身份验证文档的链接 https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/

    关于nginx - 如何在 mlFlow 服务器上运行身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58956459/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com