Hướng dẫn create user mongodb centos 7 - tạo người dùng mongodb centos 7

Tài liệu về nhà → Hướng dẫn sử dụng MongoDBMongoDB Manual

Show

Trên trang này

  • Điều kiện tiên quyết
  • Thủ tục
  • Kết nối và xác thực
  • Tạo người dùng bổ sung để triển khai của bạn
  • Kết nối với thể hiện và xác thực là myTester
  • Chèn một tài liệu là myTester
  • Ví dụ bổ sung
  • Xác thực tên người dùng/mật khẩu
  • Xác thực Kerberos
  • Xác thực LDAP
  • X.509 Xác thực chứng chỉ khách hàng
  • Bước tiếp theo

Với Access Control được bật, người dùng được yêu cầu tự xác định. Bạn phải cấp cho người dùng một hoặc nhiều vai trò. Vai trò cấp một đặc quyền của người dùng để thực hiện một số hành động nhất định trên tài nguyên MongoDB.

Mỗi ứng dụng và người dùng của một hệ thống MongoDB nên ánh xạ tới người dùng riêng biệt. Nguyên tắc cách ly truy cập này tạo điều kiện cho việc thu hồi truy cập và bảo trì người dùng liên tục. Để đảm bảo một hệ thống ít đặc quyền nhất, chỉ cấp cho tập hợp các đặc quyền tối thiểu cần thiết cho người dùng.

Để có thể tạo người dùng, bạn cần phải:

  • Bật điều khiển truy cập

  • Tạo quản trị viên người dùng

Đối với việc tạo người dùng thường xuyên, bạn phải có các quyền sau:

  • Để tạo người dùng mới trong cơ sở dữ liệu, bạn phải có createUserAction trên tài nguyên cơ sở dữ liệu đó.

  • Để cấp vai trò cho người dùng, bạn phải có hành động grantRole trên cơ sở dữ liệu của vai trò.

Vai trò tích hợp ____10 và

db.foo.insertOne( { x: 1, y: 1 } )

1 cung cấp các hành động createUsergrantRole trên các tài nguyên tương ứng của chúng.

Ghi chú

Quy trình sau sử dụng xác thực Scram. Để biết thêm thông tin về các cơ chế xác thực khác, hãy xem các ví dụ bổ sung.Additional Examples.

Ghi chú

Quy trình sau sử dụng xác thực Scram. Để biết thêm thông tin về các cơ chế xác thực khác, hãy xem các ví dụ bổ sung.Additional Examples.

Bước sau sử dụng xác thực Scram. Để biết thêm thông tin về các cơ chế xác thực khác, hãy xem các ví dụ bổ sung.

Sau khi xác thực làm quản trị viên người dùng, hãy sử dụng phương thức

db.foo.insertOne( { x: 1, y: 1 } )

4 để tạo thêm người dùng. Bạn có thể gán bất kỳ vai trò tích hợp hoặc vai trò do người dùng xác định cho người dùng.

use test
db.createUser(
{
user: "myTester",
pwd: passwordPrompt(), // or cleartext password
roles: [ { role: "readWrite", db: "test" },
{ role: "read", db: "reporting" } ]
}
)

Hoạt động sau đây thêm người dùng myTester vào cơ sở dữ liệu db.foo.insertOne( { x: 1, y: 1 } )6, người có vai trò db.foo.insertOne( { x: 1, y: 1 } )7 trong cơ sở dữ liệu db.foo.insertOne( { x: 1, y: 1 } )6 cũng như vai trò db.foo.insertOne( { x: 1, y: 1 } )9 trong cơ sở dữ liệu use reportingdb.createUser( { user: "reportsUser", pwd: passwordPrompt(), // or cleartext password roles: [ { role: "read", db: "reporting" }, { role: "read", db: "products" }, { role: "read", db: "sales" }, { role: "readWrite", db: "accounts" } ] })0.

Mẹo

Phương thức

use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
1 nhắc bạn nhập mật khẩu. Bạn cũng có thể chỉ định mật khẩu của mình trực tiếp dưới dạng chuỗi. Chúng tôi khuyên bạn nên sử dụng phương thức
use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
1 để tránh hiển thị mật khẩu trên màn hình của bạn và có khả năng rò rỉ mật khẩu vào lịch sử shell của bạn.

Cơ sở dữ liệu nơi bạn tạo người dùng (trong ví dụ này,

db.foo.insertOne( { x: 1, y: 1 } )

6) là cơ sở dữ liệu xác thực của người dùng. Mặc dù người dùng xác thực vào cơ sở dữ liệu này, người dùng có thể có vai trò trong các cơ sở dữ liệu khác. Cơ sở dữ liệu xác thực của người dùng không giới hạn các đặc quyền của người dùng.
use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
4

Sau khi tạo người dùng bổ sung, thoát use reportingdb.createUser( { user: "reportsUser", pwd: passwordPrompt(), // or cleartext password roles: [ { role: "read", db: "reporting" }, { role: "read", db: "products" }, { role: "read", db: "sales" }, { role: "readWrite", db: "accounts" } ] })4

Quan trọng

use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
4 session. Authenticating as a different user means the session has the privileges of both authenticated users. To switch between users exit and relaunch
use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
4

Không thể chuyển đổi giữa người dùng trong cùng một phiên

use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
4. Xác thực như một người dùng khác có nghĩa là phiên có đặc quyền của cả hai người dùng được xác thực. Để chuyển đổi giữa người dùng thoát và khởi chạy lại
use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
4
use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
4
as
use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
8, reconnect as myTester:

Sau khi thoát

use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
4 dưới dạng
use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
8, kết nối lại là myTester:

db.foo.insertOne( { x: 1, y: 1 } )

Hoạt động sau đây thêm người dùng myTester vào cơ sở dữ liệu db.foo.insertOne( { x: 1, y: 1 } )6, người có vai trò db.foo.insertOne( { x: 1, y: 1 } ) (adsbygoogle = window.adsbygoogle || []).push({}); 7 trong cơ sở dữ liệu db.foo.insertOne( { x: 1, y: 1 } )6 cũng như vai trò db.foo.insertOne( { x: 1, y: 1 } )9 trong cơ sở dữ liệu use reportingdb.createUser( { user: "reportsUser", pwd: passwordPrompt(), // or cleartext password roles: [ { role: "read", db: "reporting" }, { role: "read", db: "products" }, { role: "read", db: "sales" }, { role: "readWrite", db: "accounts" } ] })0.

Mẹo

Phương thức

use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
1 nhắc bạn nhập mật khẩu. Bạn cũng có thể chỉ định mật khẩu của mình trực tiếp dưới dạng chuỗi. Chúng tôi khuyên bạn nên sử dụng phương thức
use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
1 để tránh hiển thị mật khẩu trên màn hình của bạn và có khả năng rò rỉ mật khẩu vào lịch sử shell của bạn.

Hoạt động sau đây thêm người dùng myTester vào cơ sở dữ liệu db.foo.insertOne( { x: 1, y: 1 } )6, người có vai trò db.foo.insertOne( { x: 1, y: 1 } )7 trong cơ sở dữ liệu db.foo.insertOne( { x: 1, y: 1 } )6 cũng như vai trò db.foo.insertOne( { x: 1, y: 1 } )9 trong cơ sở dữ liệu use reportingdb.createUser( { user: "reportsUser", pwd: passwordPrompt(), // or cleartext password roles: [ { role: "read", db: "reporting" }, { role: "read", db: "products" }, { role: "read", db: "sales" }, { role: "readWrite", db: "accounts" } ] })0.

Mẹo

use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)

Phương thức

use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
1 nhắc bạn nhập mật khẩu. Bạn cũng có thể chỉ định mật khẩu của mình trực tiếp dưới dạng chuỗi. Chúng tôi khuyên bạn nên sử dụng phương thức
use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
1 để tránh hiển thị mật khẩu trên màn hình của bạn và có khả năng rò rỉ mật khẩu vào lịch sử shell của bạn.

Cơ sở dữ liệu nơi bạn tạo người dùng (trong ví dụ này,

db.foo.insertOne( { x: 1, y: 1 } )

6) là cơ sở dữ liệu xác thực của người dùng. Mặc dù người dùng xác thực vào cơ sở dữ liệu này, người dùng có thể có vai trò trong các cơ sở dữ liệu khác. Cơ sở dữ liệu xác thực của người dùng không giới hạn các đặc quyền của người dùng.

Sau khi tạo người dùng bổ sung, thoát

use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
4

Quan trọng

use $external
db.createUser(
{
user: "",
roles: [
{ role: "read", db: "records" }
]
}
)

Hoạt động sau đây thêm người dùng myTester vào cơ sở dữ liệu db.foo.insertOne( { x: 1, y: 1 } )6, người có vai trò db.foo.insertOne( { x: 1, y: 1 } )7 trong cơ sở dữ liệu db.foo.insertOne( { x: 1, y: 1 } ) (adsbygoogle = window.adsbygoogle || []).push({}); 6 cũng như vai trò db.foo.insertOne( { x: 1, y: 1 } )9 trong cơ sở dữ liệu use reportingdb.createUser( { user: "reportsUser", pwd: passwordPrompt(), // or cleartext password roles: [ { role: "read", db: "reporting" }, { role: "read", db: "products" }, { role: "read", db: "sales" }, { role: "readWrite", db: "accounts" } ] })0.

Mẹo

Phương thức

use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
1 nhắc bạn nhập mật khẩu. Bạn cũng có thể chỉ định mật khẩu của mình trực tiếp dưới dạng chuỗi. Chúng tôi khuyên bạn nên sử dụng phương thức
use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
1 để tránh hiển thị mật khẩu trên màn hình của bạn và có khả năng rò rỉ mật khẩu vào lịch sử shell của bạn.

Cơ sở dữ liệu nơi bạn tạo người dùng (trong ví dụ này,

db.foo.insertOne( { x: 1, y: 1 } )

6) là cơ sở dữ liệu xác thực của người dùng. Mặc dù người dùng xác thực vào cơ sở dữ liệu này, người dùng có thể có vai trò trong các cơ sở dữ liệu khác. Cơ sở dữ liệu xác thực của người dùng không giới hạn các đặc quyền của người dùng.

Để xác thực LDAP, bạn phải chỉ định tên người dùng. Bạn không cần chỉ định mật khẩu, vì điều đó được xử lý bởi dịch vụ LDAP.

Hoạt động sau đây thêm người dùng

use reporting
db.createUser(
{
user: "reportsUser",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "read", db: "reporting" },
{ role: "read", db: "products" },
{ role: "read", db: "sales" },
{ role: "readWrite", db: "accounts" }
]
}
)
0 có quyền truy cập chỉ đọc vào cơ sở dữ liệu
use $external
db.createUser(
{
user: "reporting",
roles: [
{ role: "read", db: "records" }
]
}
)
4:

use $external
db.createUser(
{
user: "reporting",
roles: [
{ role: "read", db: "records" }
]
}
)

Mẹo

Xem thêm:

Người dùng xác thực với MongoDB bằng cơ chế xác thực bên ngoài, chẳng hạn như xác thực chứng chỉ máy khách X.509, phải được tạo trong cơ sở dữ liệu

use $external
db.createUser(
{
user: "",
roles: [
{ role: "read", db: "records" }
]
}
)
9, cho phép
use $external
db.createUser(
{
user: "reporting",
roles: [
{ role: "read", db: "records" }
]
}
)
0 hoặc
use $external
db.createUser(
{
user: "reporting",
roles: [
{ role: "read", db: "records" }
]
}
)
1 tham khảo nguồn bên ngoài để xác thực.

Để sử dụng các phiên khách hàng và đảm bảo tính nhất quán nhân quả với người dùng xác thực

use $external
db.createUser(
{
user: "",
roles: [
{ role: "read", db: "records" }
]
}
)
9 (người dùng Kerberos, LDAP hoặc X.509), tên người dùng không thể lớn hơn 10k byte.

Đối với xác thực chứng chỉ máy khách X.509, bạn phải thêm giá trị của

use $external
db.createUser(
{
user: "CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry",
roles: [
{ role: "read", db: "records" }
]
}
)
5 từ chứng chỉ máy khách làm người dùng MongoDB. Mỗi chứng chỉ máy khách X.509 duy nhất tương ứng với một người dùng MongoDB duy nhất. Bạn không cần chỉ định mật khẩu.

Hoạt động sau đây bổ sung người dùng chứng chỉ máy khách

use $external
db.createUser(
{
user: "CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry",
roles: [
{ role: "read", db: "records" }
]
}
)
6 có quyền truy cập chỉ đọc vào cơ sở dữ liệu
use $external
db.createUser(
{
user: "reporting",
roles: [
{ role: "read", db: "records" }
]
}
)
4.

use $external
db.createUser(
{
user: "CN=myName,OU=myOrgUnit,O=myOrg,L=myLocality,ST=myState,C=myCountry",
roles: [
{ role: "read", db: "records" }
]
}
)

Mẹo

Xem thêm:

Người dùng xác thực với MongoDB bằng cơ chế xác thực bên ngoài, chẳng hạn như xác thực chứng chỉ máy khách X.509, phải được tạo trong cơ sở dữ liệu

use $external
db.createUser(
{
user: "",
roles: [
{ role: "read", db: "records" }
]
}
)
9, cho phép
use $external
db.createUser(
{
user: "reporting",
roles: [
{ role: "read", db: "records" }
]
}
)
0 hoặc
use $external
db.createUser(
{
user: "reporting",
roles: [
{ role: "read", db: "records" }
]
}
)
1 tham khảo nguồn bên ngoài để xác thực.

Làm thế nào để bạn tạo một người dùng MongoDB mới?

Trong MongoDB, người dùng được tạo bằng phương thức createUser (). Phương thức này tạo ra một người dùng mới cho cơ sở dữ liệu, nếu người dùng được chỉ định đã có trong cơ sở dữ liệu thì phương thức này sẽ trả về lỗi.createUser() method. This method creates a new user for the database, if the specified user is already present in the database then this method will return an error.

Lệnh nào có thể được sử dụng để tạo người dùng trong MongoDB?

createdUser () trên cơ sở dữ liệu bên ngoài $ để tạo người dùng có thông tin đăng nhập được lưu trữ bên ngoài cho MongoDB. Giá trị có thể là: Mật khẩu của người dùng trong chuỗi ClearText hoặc. PasswordPrompt () để nhắc mật khẩu của người dùng. on the $external database to create users who have credentials stored externally to MongoDB. The value can be either: the user's password in cleartext string, or. passwordPrompt() to prompt for the user's password.

Làm cách nào để tạo một quản trị viên trong MongoDB?

MongoDB Tạo người dùng quản trị viên..
Bước đầu tiên là chỉ định tên người dùng trên mạng và mật khẩu trực tuyến cần được tạo ..
Bước thứ hai là gán một vai trò cho người dùng.....
Tham số DB chỉ định cơ sở dữ liệu quản trị viên là cơ sở dữ liệu meta đặc biệt trong MongoDB chứa thông tin cho người dùng này ..

Làm cách nào để cung cấp cho cơ sở dữ liệu quyền truy cập cho người dùng trong MongoDB?

MongoDB: db.grantrolestouser () phương thức được sử dụng để cung cấp một vai trò bổ sung và đặc quyền của nó cho người dùng.Tên của người dùng để cấp vai trò.Một mảng các vai trò bổ sung để cấp cho người dùng.Mức độ viết mối quan tâm cho việc sửa đổi.db. grantRolesToUser() method is used to grants an additional role and its privileges to a user. The name of the user to whom to grant roles. An array of additional roles to grant to the user. The level of write concern for the modification.