centos7下mongodb安装及开启副本

下载安装包

https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.13.tgz

解压并修改目录名称

mongodb-4.0.13

编写配置文件

dbpath=/data/mongodb/db
bind_ip=0.0.0.0
port=27017
logpath=/data/mongodb/logs/mongodb.log
logappend=true
auth=false
replSet=rs0

保存为mongodb.conf文件

设置mongodb的环境变量

export MONGODB_HOME=/opt/mongodb-4.0.13
export PATH=$PATH:$MONGODB_HOME/bin
source /etc/profile

启动mongodb

mongod -f conf/mongodb.conf

添加用户及权限的脚本

HOSTNAME=`hostname`OPTS=`getopt -o h: --long hostname: -n 'parse-options' -- "$@"`if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fiecho "$OPTS"eval set -- "$OPTS"while true; docase "$1" in-h | --hostname )     HOSTNAME=$2;        shift; shift ;;-- ) shift; break ;;* ) break ;;esacdone
echo "Using HOSTNAME='$HOSTNAME'"mongo localhost:27017/inventory <<-EOFrs.initiate({_id: "rs0",members: [ { _id: 0, host: "${HOSTNAME}:27017" } ]});
EOF
echo "Initiated replica set"sleep 3
mongo localhost:27017/admin <<-EOFdb.createUser({ user: 'admin', pwd: 'admin', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });
EOFmongo -u admin -p admin localhost:27017/admin <<-EOFdb.runCommand({createRole: "listDatabases",privileges: [{ resource: { cluster : true }, actions: ["listDatabases"]}],roles: []});db.createUser({user: 'debezium',pwd: 'dbz',roles: [{ role: "readWrite", db: "inventory" },{ role: "read", db: "local" },{ role: "listDatabases", db: "admin" },{ role: "read", db: "config" },{ role: "read", db: "admin" }]});
EOFecho "Created users"mongo -u debezium -p dbz --authenticationDatabase admin localhost:27017/inventory <<-EOFuse inventory;db.products.insert([{ _id : NumberLong("101"), name : 'scooter', description: 'Small 2-wheel scooter', weight : 3.14, quantity : NumberInt("3") },{ _id : NumberLong("102"), name : 'car battery', description: '12V car battery', weight : 8.1, quantity : NumberInt("8") },{ _id : NumberLong("103"), name : '12-pack drill bits', description: '12-pack of drill bits with sizes ranging from #40 to #3', weight : 0.8, quantity : NumberInt("18") },{ _id : NumberLong("104"), name : 'hammer', description: "12oz carpenter's hammer", weight : 0.75, quantity : NumberInt("4") },{ _id : NumberLong("105"), name : 'hammer', description: "14oz carpenter's hammer", weight : 0.875, quantity : NumberInt("5") },{ _id : NumberLong("106"), name : 'hammer', description: "16oz carpenter's hammer", weight : 1.0, quantity : NumberInt("0") },{ _id : NumberLong("107"), name : 'rocks', description: 'box of assorted rocks', weight : 5.3, quantity : NumberInt("44") },{ _id : NumberLong("108"), name : 'jacket', description: 'water resistent black wind breaker', weight : 0.1, quantity : NumberInt("2") },{ _id : NumberLong("109"), name : 'spare tire', description: '24 inch spare tire', weight : 22.2, quantity : NumberInt("5") }]);db.customers.insert([{ _id : NumberLong("1001"), first_name : 'Sally', last_name : 'Thomas', email : 'sally.thomas@acme.com' },{ _id : NumberLong("1002"), first_name : 'George', last_name : 'Bailey', email : 'gbailey@foobar.com' },{ _id : NumberLong("1003"), first_name : 'Edward', last_name : 'Walker', email : 'ed@walker.com' },{ _id : NumberLong("1004"), first_name : 'Anne', last_name : 'Kretchmar', email : 'annek@noanswer.org' }]);db.orders.insert([{ _id : NumberLong("10001"), order_date : new ISODate("2016-01-16T00:00:00Z"), purchaser_id : NumberLong("1001"), quantity : NumberInt("1"), product_id : NumberLong("102") },{ _id : NumberLong("10002"), order_date : new ISODate("2016-01-17T00:00:00Z"), purchaser_id : NumberLong("1002"), quantity : NumberInt("2"), product_id : NumberLong("105") },{ _id : NumberLong("10003"), order_date : new ISODate("2016-02-19T00:00:00Z"), purchaser_id : NumberLong("1002"), quantity : NumberInt("2"), product_id : NumberLong("106") },{ _id : NumberLong("10004"), order_date : new ISODate("2016-02-21T00:00:00Z"), purchaser_id : NumberLong("1003"), quantity : NumberInt("1"), product_id : NumberLong("107") }]);
EOFecho "Inserted example data"

保存为sh后缀的脚本,执行此文件,此时mongodb的inventory库可做实时的cdc处理了

参考资料

  • https://www.mongodb.com/docs/v4.0/tutorial/install-mongodb-on-red-hat/
  • https://blog.csdn.net/x549971589x/article/details/119147785

centos7下mongodb安装及开启副本相关推荐

  1. centos72安装mysql配置密码_MySQL数据库之170419、Centos7下完美安装并配置mysql5.6

    本文主要向大家介绍了MySQL数据库之170419.Centos7下完美安装并配置mysql5.6 ,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助. linxu环境: centos ...

  2. linux环境下MongoDB安装过程详解

    Linux下MongoDB安装和配置详解 *注:本文是参考了多篇文章后,并通过实践总结来的,按照步骤来,下载好对应的版本,保准你能安装个心仪的mongodb服务器.... 一.创建MongoDB的安装 ...

  3. CentOS-7 下 GitLab 安装部署教程

    CentOS-7 下 GitLab 安装部署教程 前言 主要内容 GitLab 介绍 本篇环境信息 准备工作 配置清华大学镜像仓库 安装基础依赖 安装 Postfix 开放 ssh 以及 http 服 ...

  4. Windows下MongoDB安装及创建用户名和密码

    Windows下MongoDB安装及创建用户名和密码 下载MongoDB的安装文件https://www.mongodb.com/download-center#community,选择合适的版本(注 ...

  5. linux中mongo的导出数据,Linux下mongodb安装及数据导入导出教程(示例代码)

    Linux下mongodb安装及数据导入导出教程 #查看linux发行版本 cat /etc/issue #查看linux内核版本号 uname -r 一.Linux下mongodb安装的一般步骤 1 ...

  6. linux7安装pgsql数据库,CentOS7下PostgreSQL安装

    环境:CentOS 7 版本:postgresql11 安装repo源 yum install https://download.postgresql.org/pub/repos/yum/reporp ...

  7. Linux下mongodb安装及数据导入导出教程

    Linux下mongodb安装及数据导入导出教程 #查看linux发行版本 cat /etc/issue #查看linux内核版本号 uname -r 一.Linux下mongodb安装的一般步骤 1 ...

  8. 二进制安装mysql集群_实战mysql集群搭建(一)--centos7下二进制安装mysql-5.6

    在超哥的帮助下,完成了基于InnoDb数据引擎的mysql数据库集群搭建,实现了主从复制的功能,本篇博文介绍如何使用二进制安装mysql的方法,具体实现步骤如下: 软件使用说明: Liunx系统:ce ...

  9. Hive入门教程<2> | hive在centos7下的安装部署

    hive在centos7下的安装部署 前提 安装hive hadoop集群配置 hive基本操作 演示向hive中导入本地数据文件 前提 1.首先有自己的远程终端登录工具,我这里用的是mobaxter ...

最新文章

  1. 机器学习集成学习与模型融合!
  2. 阿里某新员工感慨:入职阿里三个月生活一团糟,想辞职休息
  3. QT cannot open output file debug\OpencvTest.exe: Permission denied
  4. Linux操作_常用命令操作练习
  5. 高标准,严要求!数据中心发电机组的调试与验收工作
  6. [云炬创业基础笔记]第二章创业者测试24
  7. ECCV 2020 Spotlight | CFBI:前背景整合的协作式视频目标分割
  8. 【Linux系统编程】线程栈大小
  9. 致NLP学习者,该跟大佬学习做项目了,附资料
  10. 前端学习(3281):生成器迭代器
  11. 深入理解空指针(C++)
  12. 在一个centos6上安装多个不同版本python
  13. mysql 5.6 默认密码_mysql5.6配置及修改密码
  14. 面试阿里(P8)竟被MySQL难倒,奋发图强二次面试斩获阿里offer
  15. mysql数据库分页查询,limit语句用法
  16. 抖音上热门的好处有哪些?
  17. 【BZOJ 3653】谈笑风生
  18. 什么是金手指,金手指的设计要求有哪些?
  19. matlab2016agui出错,关于 gui运行出错的问题
  20. string转blob

热门文章

  1. iOS 修改图片的亮度、对比度、饱和度
  2. propagation=NEVER”
  3. Material UI – React (2022) 版的完整教程
  4. 无知造就对阿法狗(AlphaGo)的恐惧与喧闹
  5. 不懂金融,2020年做不好矿工!
  6. 电脑误删u盘文件怎么恢复?u盘资料误删怎么恢复
  7. 微信群互动h5游戏推荐:旅行匹配度大考验
  8. R7 3700x配什么主板
  9. mobaxterm(linux)解压7z.001.001/7z.002.002等分卷文件
  10. 2058(等差求和)