启用 Cassandra 身份验证

默认情况下,Cassandra 安装时不会启用身份验证。这意味着任何人都可以访问 Cassandra。您可以在安装 Edge 后或在安装过程中启用身份验证。

您可以使用 Cassandra CREATE/ALTER/DROP USER 语句添加、移除和修改用户。如需了解详情,请参阅 Cassandra SQL shell 命令

  • 请务必在用于安装或升级 Edge 组件的配置文件中更新有效的 Cassandra 用户名和密码。这样可以消除或最大限度地减少边缘操作期间的任何中断。
  • 在安装过程中启用 Cassandra 身份验证

    您可以在安装时启用 Cassandra 身份验证。

    如需在安装时启用 Cassandra 身份验证,请在所有 Cassandra 节点的配置文件中添加 CASS_AUTH 属性:

    CASS_AUTH=y # The default value is n.

    以下 Edge 组件会访问 Cassandra:

    • 管理服务器
    • 消息处理器
    • 路由器
    • Qpid 服务器
    • Postgres 服务器

    安装这些组件时,您必须在配置文件中设置用户名和密码:

    CASS_USERNAME=cassandra_username
    CASS_PASSWORD=cassandra_password

    安装 Cassandra 后,您可以更改 Cassandra 凭据。不过,如果您已安装管理服务器、消息处理器、路由器、Qpid 服务器或 Postgres 服务器,则还必须更新这些组件才能使用新凭据。

    如需在安装 Cassandra 后更改 Cassandra 凭据,请执行以下操作:

    1. 使用 cqlsh 工具和默认凭据登录任意 Cassandra 节点。您只需更改一个节点上的密码,该密码就会广播到环中的所有 Cassandra 节点:
      /opt/apigee/apigee-cassandra/bin/cqlsh cassIP 9042 -u cassandra_username -p cassandra_password

      其中:

      1. cassIP 是 Cassandra 节点的 IP 地址。
      2. 9042 是默认的 Cassandra 端口。
    2. cqlsh> 提示符处,执行以下命令以更新密码:
      ALTER USER cassandra_username/var> WITH PASSWORD 'new_cassandra_password';
    3. 退出 cqlsh 工具,如以下示例所示:
      exit
    4. 如果您尚未安装管理服务器、消息处理器、路由器、Qpid 服务器或 Postgres 服务器,请在配置文件中设置以下属性,然后安装这些组件:
      CASS_USERNAME=cassandra_username
      CASS_PASSWORD=new_cassandra_password
    5. 如果您已安装管理服务器、消息处理器、路由器、Qpid 服务器或 Postgres 服务器,请参阅重置 Edge 密码,了解如何更新这些组件以使用新密码。

    安装后启用 Cassandra 身份验证

    如需在安装后启用身份验证,请执行以下操作:

    更新连接到 Cassandra 的 Edge 组件

    请按照以下步骤使用新凭据更新与 Cassandra 通信的所有 Edge 组件。请注意,您需要先执行此步骤,然后才能实际更新 Cassandra 凭据:

    1. 在管理服务器节点上,运行以下命令:
      /opt/apigee/apigee-service/bin/apigee-service edge-management-server
        store_cassandra_credentials -u cassandra_username -p cassandra_password

      (可选)您可以向包含新用户名和密码的命令传递文件:

      apigee-service edge-management-server store_cassandra_credentials  -f configFile

      其中,configFile 包含以下内容:

      CASS_USERNAME=cassandra_username # Default is cassandra
      CASS_PASSWORD='cassandra_password' # Default is cassandra; wrap in single quotes if it includes special chars

      此命令会自动重启管理服务器。

    2. 对于以下每项服务,请重复第 1 步:
      • 所有消息处理器
      • 所有路由器
      • 所有 Qpid 服务器 (edge-qpid-server)
      • Postgres 服务器 (edge-postgres-server)

      为每项服务重复第 1 步时,请将上述命令中的 edge-management-server 替换为相应的服务名称。例如,在执行路由器服务的步骤时,请使用以下命令:

      /opt/apigee/apigee-service/bin/apigee-service edge-router
        store_cassandra_credentials -u cassandra -p cassandra

    启用身份验证

    请按照以下步骤启用 Cassandra 身份验证并设置用户名和密码:

    1. 创建一个静默配置文件,其中包含以下内容:
      # Specify IP address or DNS name of cassandra node
      IP1=192.168.1.1
      IP2=192.168.1.2
      IP3=192.168.1.3
      # Must resolve to IP address or DNS name of host
      HOSTIP=$(hostname -i)
      # Set to ‘y’ to enable Cassandra authentication.
      CASS_AUTH=y # Possible values are ‘y/n’
      # Cassandra username. If it does not exist, this user would be created as a SUPERUSER
      CASS_USERNAME=cassandra_username # Default value is cassandra - don't use for production
      # Cassandra Password. If CASS_USERNAME does not exist, create SUPERUSER with this as password
      CASS_PASSWORD=cassandra_password # Default value is cassandra - don't use for production
      # Space-separated IP/DNS names of the Cassandra hosts
      CASS_HOSTS="$IP1:1,1 $IP2:1,1 $IP3:1,1"
      
      # Username of an existing C* user. Only needed if you have disabled or changed details of the default cassandra user(‘cassandra’)
      CASS_EXISTING_USERNAME=existing_cassandra_username
      # Password of an existing C* user. Only needed if you have disabled or change password of the default cassandra user(‘cassandra’)
      CASS_EXISTING_PASSWORD=existing_cassandra_password
      # Cassandra port
      CASS_PORT=9042 # The default port is 9042.
    2. 登录第一个 Cassandra 节点并执行以下命令:

      apigee-service apigee-cassandra enable_cassandra_authentication -f CONFIG

      您可以选择将属性作为命令参数传递给脚本,如以下示例所示:

      CASS_AUTH=y HOSTIP=$(hostname -i) CASS_PORT=9042 CASS_EXISTING_USERNAME=existing_cassandra_username CASS_EXISTING_PASSWORD=existing_cassandra_password CASS_USERNAME=cassandra_username CASS_PASSWORD=cassandra_password  CASS_HOSTS="192.168.1.1:1,1 192.168.1.2:1,1 192.168.1.3:1,1" apigee-service apigee-cassandra enable_cassandra_authentication

      注意:

      • 对于默认的 Cassandra 凭据,上述命令会启用 Cassandra 身份验证并重启 Cassandra。
      • 对于非默认凭据,该命令还会更改复制因子、创建超级用户,并对 system_auth keyspace 运行修复操作。
    3. 对所有 Cassandra 节点重复第 1 步和第 2 步。