网站快速建设,制作网站用什么软件,国内建网站知名企业,评估网站建设方案安装手册英文版在这里
https://www.mongodb.com/docs/v7.0/tutorial/install-mongodb-on-red-hat/
我的安装过程
1#xff09;基础安装 1、创建 /etc/yum.repos.d/mongodb-org-7.0.repo文件 下面的代码复制到这个文件中#xff0c;保存
[mongodb-org-7.0]
nameMongoDB Re…安装手册英文版在这里
https://www.mongodb.com/docs/v7.0/tutorial/install-mongodb-on-red-hat/
我的安装过程
1基础安装 1、创建 /etc/yum.repos.d/mongodb-org-7.0.repo文件 下面的代码复制到这个文件中保存
[mongodb-org-7.0]
nameMongoDB Repository
baseurlhttps://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/7.0/x86_64/
gpgcheck1
enabled1
gpgkeyhttps://www.mongodb.org/static/pgp/server-7.0.asc2、yum安装
yum install -y mongodb-org会看到安装一大堆的内容 注意两个事情 第一MongoDB默认用的mongod的账号去启动资源如果有permission deny的报错找到目录执行chown -R mongod:mongod 目录 第二配置文件默认放在/etc/mongod.conf这里可以设置日志和数据文件地址如果你改了记得按照第一条把新的目录改属主为mongod
3、关闭SELinux设置SELinux状态
setenforce 0不执行上述命令改了属主也没有用 要想重启后生效需要改文件vim /etc/selinux/configSELINUXenforcing改成SELINUXpermissive 4、启动
systemctl start mongod5、用客户端连接试试
mongosh看到一大堆输出就进去了
Current Mongosh Log ID: 6516b6
Connecting to: mongodb://127.0.0.1:27017/?directConnectiontrueserverSelectionTimeoutMS2000appNamemongosh2.0.1
Using MongoDB: 7.0.1
Using Mongosh: 2.0.1For mongosh info see: https://docs.mongodb.com/mongodb-shell/
To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.The server generated these startup warnings when booting2023-09-29T19:27:11.18308:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem2023-09-29T19:27:11.49508:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted2023-09-29T19:27:11.49608:00: You are running on a NUMA machine. We suggest launching mongod like this to avoid performance problems: numactl --interleaveall mongod [other options]2023-09-29T19:27:11.49708:00: /sys/kernel/mm/transparent_hugepage/enabled is always. We suggest setting it to never2023-09-29T19:27:11.49708:00: /sys/kernel/mm/transparent_hugepage/defrag is always. We suggest setting it to never2023-09-29T19:27:11.49708:00: vm.max_map_count is too low
------test6、重启试试 reboot然后看看服务起来没有systemctl status mongod 正常
2集群安装 上面是单机也没有密码下面部署集群记得先把主、从、仲裁都按照上面步骤装好
7、改配置文件 先把三个机器的MongoDB服务停了找到/etc/mongod.conf修改
replication:replSetName: hep22然后启动服务
8、给防火墙开端口
firewall-cmd --permanent --add-port27017/tcp
firewall-cmd --reload不开端口连不上
9、初始化主 在主上进入MongoDB执行mongosh然后执行
rs.initiate({_id: hepee,members:[ {_id:0,host:10.15.32.130:27017,priority:5}]})priority:5越高等级越高你希望谁是主就把谁设高 设置完可以看一下情况
rs.conf()10、增加从 还是在主服务器上操作哈
rs.add({
_id: 1,host:10.15.32.131:27017,priority:4
})11、增加仲裁
rs.add({
_id: 2,host:10.15.32.132:27017,arbiterOnly:true
})增加的时候报错Reconfig attempted to install a config that would change the implicit default write concern执行下面语句
db.adminCommand({setDefaultRWConcern : 1,defaultWriteConcern : {w : 2}
})再增加仲裁机就好了
12、复查
rs.conf()
rs.status()
show dbs增加一条记录试试
use test
db.test.insert({name:mongo})
show dbs注意一定要切换数据库 这时能看到多了个test数据库说明成功了 到从上看看看到secondary了这是从看到了test数据库已经同步过来了
3安全认证 为了安全要配置一下安全认证不然对所有人都是敞开的 mongodb4.0以上不支持TLS1.0改支持1.1
请注意版本mongodb不同版本参数命令会有细微不同所以得试看哪个命令好使
keyfile白话说就是一个记事本存放这一串字符就可以当做秘钥。 keyfile是用于mongodb集群内部成员认证用的。
先建个最高级别账号否则后面怕进不来
db.createUser({user:root,pwd:XXX0,roles: [ { role: root, db: admin } ]})创建keyfile
openssl rand -base64 756 /data/mongoDB/internal.keychmod 400 /data/mongoDB/internal.keychown mongod.mongod /data/mongoDB/internal.key
将此keyfile拷贝到其他两台主机相同目录下。
配置Keyfile
修改/etc/mongod.conf文件增加副本集与安全配置主要是security:里面这两句
net:port: 27017bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.security:keyFile: /data/mongoDB/internal.keyauthorization: enabled#operationProfiling:把三台机器都设置好然后重启服务重启记得顺序先起从节点仲裁最后起主节点
连接
此时用mongosh连接不会报错能进但是进去干不了啥会出错得用用户名、密码进去才正常
mongosh -u root -p用前面创建的账号进入 插入个数据吧
远程连接
此时从远程连接没密码进入执行啥命令就提示要授权只有用账号密码进去了执行才能成功
use
db.cicatDb.insertOne({name:mongo})
show dbs