如何在 Jelastic JPS 中获取或设置集群数据库用户名和密码
How to get or set the clustered database username and password in Jelastic JPS
我正在尝试按照 Setting Up Auto-Clusterization with Cloud Scripting 中的描述设置 Jelastic 集群数据库,但我没有看到描述如何设置或检索集群用户名和密码的文档。
我确实尝试将 db_user
和 db_pass
传递给集群,我在一些示例 JPS 文件中找到的名称,以及将它们作为设置,但凭据仍然只是 Jelastic生成的。
这是我正在尝试使用的 JPS;它包括一个简单的 Debian 容器,需要数据库凭据作为环境变量。在这种情况下,Docker 容器仅包含用于测试目的的 MariaDB 客户端,实际环境比这复杂一点,启动时 运行 个脚本需要数据库连接。
{
"version": "1.5",
"type": "install",
"name": "Database test",
"skipNodeEmails": true,
"globals":
{
"MYSQL_ROOT_USERNAME": "root",
"MYSQL_ROOT_PASSWORD": "${fn.password(20)}",
"MYSQL_USERNAME": "username",
"MYSQL_PASSWORD": "${fn.password(20)}",
"MYSQL_DATABASE": "database",
"MYSQL_HOSTNAME": "ProxySQL"
},
"nodes":
[
{
"image": "mireiawen/debian-sql",
"count": 1,
"cloudlets": 8,
"nodeGroup": "vds",
"displayName": "SQL worker",
"env":
{
"MYSQL_ROOT_USERNAME": "${globals.MYSQL_ROOT_USERNAME}",
"MYSQL_ROOT_PASSWORD": "${globals.MYSQL_ROOT_PASSWORD}",
"MYSQL_USERNAME": "${globals.MYSQL_USERNAME}",
"MYSQL_PASSWORD": "${globals.MYSQL_PASSWORD}",
"MYSQL_DATABASE": "${globals.MYSQL_DATABASE}",
"MYSQL_HOSTNAME": "${globals.MYSQL_HOSTNAME}"
}
},
{
"nodeType": "mariadb-dockerized",
"nodeGroup": "sqldb",
"count": "2",
"cloudlets": 16,
"cluster":
{
"scheme": "master"
}
}
]
}
这个 JPS 似乎正确启动了包含 ProxySQL 的 MariaDB master-master 集群,我只是缺少有关如何向数据库集群提供数据库凭据或检索生成的凭据的方法的文档用作 JPS 中的变量以将其发送到容器。
谢谢你提出的好问题。传递自定义凭据的机制应该并且很快就会得到改进。目前您可以使用下面的示例。简而言之,我们禁用自动集群并使用自定义用户名和密码再次启用它。
---
version: 1.5
type: install
name: Database test
skipNodeEmails: true
baseUrl: https://raw.githubusercontent.com/jelastic-jps/mysql-cluster/master
globals:
logic_jps: ${baseUrl}/addons/auto-clustering/scripts/auto-cluster-logic.jps
MYSQL_USERNAME: username
MYSQL_PASSWORD: ${fn.password(20)}
nodes:
- image: mireiawen/debian-sql
count: 1
cloudlets: 8
nodeGroup: extra
displayName: SQL worker
env:
MYSQL_USERNAME: ${globals.MYSQL_USERNAME}
MYSQL_PASSWORD: ${globals.MYSQL_PASSWORD}
- nodeType: mariadb-dockerized
nodeGroup: sqldb
count: 2
cloudlets: 16
cluster: false
onInstall:
install:
jps: ${globals.logic_jps}
envName: ${env.envName}
nodeGroup: sqldb
settings:
path: ${baseUrl}
scheme: master
logic_jps: ${globals.logic_jps}
db_user: ${globals.MYSQL_USERNAME}
db_pass: ${globals.MYSQL_PASSWORD}
repl_user: repl-${fn.random}
repl_pass: ${fn.password(20)}
环境准备就绪后,您可以在 docker 映像中执行以下命令来测试连接:
mysql -h proxy -u $MYSQL_USERNAME -p$MYSQL_PASSWORD
该机制已得到改进,现在您可以使用环境变量或集群设置将自定义凭据传递到集群:
type: install
name: env. variables
nodes:
nodeType: mariadb-dockerized
nodeGroup: sqldb
count: 2
cloudlets: 8
env:
DB_USER: customuser
DB_PASS: custompass
cluster:
scheme: master
或
type: install
name: cluster settings
nodes:
nodeType: mariadb-dockerized
nodeGroup: sqldb
count: 2
cloudlets: 8
cluster:
scheme: master
db_user: customuser
db_pass: custompass
我正在尝试按照 Setting Up Auto-Clusterization with Cloud Scripting 中的描述设置 Jelastic 集群数据库,但我没有看到描述如何设置或检索集群用户名和密码的文档。
我确实尝试将 db_user
和 db_pass
传递给集群,我在一些示例 JPS 文件中找到的名称,以及将它们作为设置,但凭据仍然只是 Jelastic生成的。
这是我正在尝试使用的 JPS;它包括一个简单的 Debian 容器,需要数据库凭据作为环境变量。在这种情况下,Docker 容器仅包含用于测试目的的 MariaDB 客户端,实际环境比这复杂一点,启动时 运行 个脚本需要数据库连接。
{
"version": "1.5",
"type": "install",
"name": "Database test",
"skipNodeEmails": true,
"globals":
{
"MYSQL_ROOT_USERNAME": "root",
"MYSQL_ROOT_PASSWORD": "${fn.password(20)}",
"MYSQL_USERNAME": "username",
"MYSQL_PASSWORD": "${fn.password(20)}",
"MYSQL_DATABASE": "database",
"MYSQL_HOSTNAME": "ProxySQL"
},
"nodes":
[
{
"image": "mireiawen/debian-sql",
"count": 1,
"cloudlets": 8,
"nodeGroup": "vds",
"displayName": "SQL worker",
"env":
{
"MYSQL_ROOT_USERNAME": "${globals.MYSQL_ROOT_USERNAME}",
"MYSQL_ROOT_PASSWORD": "${globals.MYSQL_ROOT_PASSWORD}",
"MYSQL_USERNAME": "${globals.MYSQL_USERNAME}",
"MYSQL_PASSWORD": "${globals.MYSQL_PASSWORD}",
"MYSQL_DATABASE": "${globals.MYSQL_DATABASE}",
"MYSQL_HOSTNAME": "${globals.MYSQL_HOSTNAME}"
}
},
{
"nodeType": "mariadb-dockerized",
"nodeGroup": "sqldb",
"count": "2",
"cloudlets": 16,
"cluster":
{
"scheme": "master"
}
}
]
}
这个 JPS 似乎正确启动了包含 ProxySQL 的 MariaDB master-master 集群,我只是缺少有关如何向数据库集群提供数据库凭据或检索生成的凭据的方法的文档用作 JPS 中的变量以将其发送到容器。
谢谢你提出的好问题。传递自定义凭据的机制应该并且很快就会得到改进。目前您可以使用下面的示例。简而言之,我们禁用自动集群并使用自定义用户名和密码再次启用它。
--- version: 1.5 type: install name: Database test skipNodeEmails: true baseUrl: https://raw.githubusercontent.com/jelastic-jps/mysql-cluster/master globals: logic_jps: ${baseUrl}/addons/auto-clustering/scripts/auto-cluster-logic.jps MYSQL_USERNAME: username MYSQL_PASSWORD: ${fn.password(20)} nodes: - image: mireiawen/debian-sql count: 1 cloudlets: 8 nodeGroup: extra displayName: SQL worker env: MYSQL_USERNAME: ${globals.MYSQL_USERNAME} MYSQL_PASSWORD: ${globals.MYSQL_PASSWORD} - nodeType: mariadb-dockerized nodeGroup: sqldb count: 2 cloudlets: 16 cluster: false onInstall: install: jps: ${globals.logic_jps} envName: ${env.envName} nodeGroup: sqldb settings: path: ${baseUrl} scheme: master logic_jps: ${globals.logic_jps} db_user: ${globals.MYSQL_USERNAME} db_pass: ${globals.MYSQL_PASSWORD} repl_user: repl-${fn.random} repl_pass: ${fn.password(20)}
环境准备就绪后,您可以在 docker 映像中执行以下命令来测试连接:
mysql -h proxy -u $MYSQL_USERNAME -p$MYSQL_PASSWORD
该机制已得到改进,现在您可以使用环境变量或集群设置将自定义凭据传递到集群:
type: install
name: env. variables
nodes:
nodeType: mariadb-dockerized
nodeGroup: sqldb
count: 2
cloudlets: 8
env:
DB_USER: customuser
DB_PASS: custompass
cluster:
scheme: master
或
type: install
name: cluster settings
nodes:
nodeType: mariadb-dockerized
nodeGroup: sqldb
count: 2
cloudlets: 8
cluster:
scheme: master
db_user: customuser
db_pass: custompass