diff --git a/README.md b/README.md index 47e5258f..ea7ad839 100644 --- a/README.md +++ b/README.md @@ -290,7 +290,7 @@ nacos_rust_client = "0.3.0" ![](https://github.com/r-nacos/r-nacos/raw/master/doc/assets/imgs/20231223222325.png) -系统会默认创建一个名为`admin`的用户,密码为`admin`。 +系统会默认创建一个名为`admin`的用户,密码为`admin`(也可以通过环境变量 RNACOS_INIT_ADMIN_USERNAME 和 RNACOS_INIT_ADMIN_PASSWORD 修改默认账号的账户名和密码)。 进去控制台后可按需管理用户。 diff --git a/book/src/cluster_deploy.md b/book/src/cluster_deploy.md index b92ac89d..7df5c50e 100644 --- a/book/src/cluster_deploy.md +++ b/book/src/cluster_deploy.md @@ -70,6 +70,8 @@ env01 ``` #file:env01 , Initialize with the leader node role RUST_LOG=warn +#RNACOS_INIT_ADMIN_USERNAME=admin +#RNACOS_INIT_ADMIN_PASSWORD=admin RNACOS_HTTP_PORT=8848 RNACOS_RAFT_NODE_ADDR=127.0.0.1:9848 RNACOS_CONFIG_DB_DIR=db01 @@ -83,6 +85,8 @@ env02: ``` #file:env02 , Initialize with the follower node role RUST_LOG=warn +#RNACOS_INIT_ADMIN_USERNAME=admin +#RNACOS_INIT_ADMIN_PASSWORD=admin RNACOS_HTTP_PORT=8849 RNACOS_RAFT_NODE_ADDR=127.0.0.1:9849 RNACOS_CONFIG_DB_DIR=db02 @@ -95,6 +99,8 @@ env03: ``` #file:env03 , Initialize with the follower node role RUST_LOG=warn +#RNACOS_INIT_ADMIN_USERNAME=admin +#RNACOS_INIT_ADMIN_PASSWORD=admin RNACOS_HTTP_PORT=8850 RNACOS_RAFT_NODE_ADDR=127.0.0.1:9850 RNACOS_CONFIG_DB_DIR=db03 diff --git a/book/src/deplay_env.md b/book/src/deplay_env.md index 2a27c6f4..878eb6ef 100644 --- a/book/src/deplay_env.md +++ b/book/src/deplay_env.md @@ -45,6 +45,8 @@ rnacos 运行时支持的环境变量,如果不设置则按默认配置运行 | 参数KEY|内容描述|默认值|示例|开始支持的版本| |--|--|--|--|--| +|RNACOS_INIT_ADMIN_USERNAME|rnacos默认管理员用户名|admin|rnacos|0.5.11| +|RNACOS_INIT_ADMIN_PASSWORD|rnacos默认管理员密码|admin|rnacos123456|0.5.11| |RNACOS_HTTP_PORT|rnacos监听http端口|8848|8848|0.1.x| |RNACOS_GRPC_PORT|rnacos监听grpc端口|默认是 HTTP端口+1000|9848|0.1.x| |RNACOS_HTTP_CONSOLE_PORT|r-nacos独立控制台端口|默认是 HTTP端口+2000;设置为0可不开启独立控制台|10848|0.4.x| diff --git a/book/src/quick-started.md b/book/src/quick-started.md index f5642d13..e9a87e92 100644 --- a/book/src/quick-started.md +++ b/book/src/quick-started.md @@ -152,7 +152,7 @@ curl "http://127.0.0.1:8848/nacos/v1/ns/instance/list?&namespaceId=public&servic ![](https://github.com/heqingpan/rnacos/raw/master/doc/assets/imgs/20231223222325.png) -系统会默认创建一个名为`admin`的用户,密码为`admin`。 +系统会默认创建一个名为`admin`的用户,密码为`admin`(也可以通过环境变量 RNACOS_INIT_ADMIN_USERNAME 和 RNACOS_INIT_ADMIN_PASSWORD 修改默认账号的账户名和密码)。 进去控制台后可按需管理用户。 diff --git a/doc/conf/.env.example b/doc/conf/.env.example index 37f3b8ce..c8be6512 100644 --- a/doc/conf/.env.example +++ b/doc/conf/.env.example @@ -3,6 +3,12 @@ # 2. 指定文件(放置于任意目录下, 通过 命令行参数“-e 文件路径”形式指定, 如“./rnacos -e /etc/rnacos/conf/default.cnf”) # 更多说明请参照 https://r-nacos.github.io/docs/notes/env_config +# r-nacos默认管理员用户名,默认值:admin +RNACOS_INIT_ADMIN_USERNAME=admin + +# r-nacos默认管理员密码,默认值:admin +RNACOS_INIT_ADMIN_PASSWORD=admin + # r-nacos监听http端口,默认值:8848 RNACOS_HTTP_PORT=8848 diff --git a/src/common/mod.rs b/src/common/mod.rs index 7e683890..63480d80 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -52,6 +52,8 @@ impl NamingSysConfig { #[derive(Default, Clone, Debug)] pub struct AppSysConfig { + pub admin_username: String, + pub admin_password: String, pub config_db_file: String, pub config_db_dir: String, pub config_max_content: usize, @@ -76,6 +78,10 @@ pub struct AppSysConfig { impl AppSysConfig { pub fn init_from_env() -> Self { + let admin_username = std::env::var("RNACOS_INIT_ADMIN_USERNAME") + .unwrap_or("admin".to_owned()); + let admin_password = std::env::var("RNACOS_INIT_ADMIN_PASSWORD") + .unwrap_or("admin".to_owned()); let config_db_file = std::env::var("RNACOS_CONFIG_DB_FILE").unwrap_or("config.db".to_owned()); let config_max_content = std::env::var("RNACOS_CONFIG_MAX_CONTENT") @@ -146,6 +152,8 @@ impl AppSysConfig { .map(Arc::new) .unwrap_or(constant::EMPTY_ARC_STRING.clone()); Self { + admin_username, + admin_password, config_db_dir, config_db_file, config_max_content, diff --git a/src/user/mod.rs b/src/user/mod.rs index 3e6f3652..edce01c5 100644 --- a/src/user/mod.rs +++ b/src/user/mod.rs @@ -1,3 +1,4 @@ +use crate::common::AppSysConfig; use std::{sync::Arc, time::Duration}; use actix::prelude::*; @@ -61,10 +62,11 @@ impl UserManager { }; if let TableManagerResult::PageListResult(count, _) = table_manager.send(req).await?? { if count == 0 { + let sys_config = AppSysConfig::init_from_env(); let user = UserDto { - username: Arc::new("admin".to_owned()), - nickname: Some("admin".to_owned()), - password: Some("admin".to_owned()), + username: Arc::new(sys_config.admin_username.to_string()), + nickname: Some(sys_config.admin_username.to_owned()), + password: Some(sys_config.admin_password.to_owned()), roles: Some(vec![USER_ROLE_MANAGER.clone()]), ..Default::default() }; diff --git a/test_cluster.sh b/test_cluster.sh index f372fd6e..fde20a6e 100755 --- a/test_cluster.sh +++ b/test_cluster.sh @@ -45,6 +45,8 @@ start_cluster() { cat >$env_file <$env_file <