【ManggoDB】安装配置(伪分布式集群搭建)Replia Set

2020-12-07 10:30:36 浏览数 (1)

ManggoDB

参考资料

介于 关系型数据库 非关系型数据库之间 菜鸟教程 https://www.runoob.com/mongodb https://www.mongodb.org.cn/

安装配置

MongoDB 源码下载地址:https://www.mongodb.com/download-center#community

centos下载 wget下载url文件

代码语言:javascript复制
// 安装wget命令
yum install wget
// 直接下载文件url
wget 文件url
代码语言:javascript复制
// 获取路径
pwd
/opt/install/mongodb-linux-x86_64-rhel70-4.4.1
// 修改配置
vi /etc/profile
source /etc/profile
// 

配置

tgz没找到conf rpm安装,不建议使用直接配置conf添加配置吧

代码语言:javascript复制
// rpm安装
rpm -ivh rpm文件
// 查看带mongo的文件
find / -name mongo
// 查看是否启了进程
ps -aux | grep mongo
// 查看mongod配置信息
more /usr/lib/systemd/system/mongod.service
[root@hadoop01 etc]# more /usr/lib/systemd/system/mongod.service
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target

[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod.conf"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod $OPTIONS
ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb
ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb
ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb
PermissionsStartOnly=true
PIDFile=/var/run/mongodb/mongod.pid

more /etc/mongod.conf 

vi mongodb.conf

代码语言:javascript复制
// 参考补充

#开放所有的ip可访问
bind_ip=0.0.0.0  
port=27017
#如果没有目录需要创建
dbpath=/opt /module/mongodb/data
#如果没有目录需要创建
logpath=/opt/module/mongodb/log/out.log  
logappend=true

启动 到达.conf的目录

代码语言:javascript复制
mongod -f mongodb.conf &

验证(访问url输出字符)

代码语言:javascript复制
// 法1看url 端口
http://192.168.137.121:27017/
It looks like you are trying to access MongoDB over HTTP on the native driver port.

// 法2 看进程
[root@hadoop01 kafka_2.13-2.6.0]# ps -ef | grep mongo
root      20603      1  1 10月30 ?      00:00:11 mongod -f mongod.conf

连接客户端

代码语言:javascript复制
// mongo有自带的shell
etc]# mongo
>1 1
>2
> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB

MongoDB 复制集(Replica Set)搭建

通常,为了防止单点故障应用程序需要做集群。然而在数据库中除了防止单点故障,还需要做到数据库备份,读写分离,故障转移等。而 MongoDB 的 Replica Set 恰恰都能满足这些要求。

搭建伪节点

代码语言:javascript复制
// 准备数据输出目录
[root@hadoop01 mongo]# pwd
/opt/install/mongo
[root@hadoop01 mongo]# ll
总用量 0
drwxr-xr-x. 2 root root 6 10月 31 00:49 data1
drwxr-xr-x. 2 root root 6 10月 31 00:49 data2
drwxr-xr-x. 2 root root 6 10月 31 00:49 data3

// 到/etc目录下,有mongo 进行三个伪进程启动
27017
27027
27037

mongod --port 27017 --dbpath /opt/install/mongo/data1 --replSet myrs
mongod --port 27027 --dbpath /opt/install/mongo/data2 --replSet myrs
mongod --port 27037 --dbpath /opt/install/mongo/data3 --replSet myrs

// 链接到启动的进程服务
mongo -port 27017

在Mongo客户端使用命令rs.initiate()来启动一个新的副本集。
我们可以使用rs.conf()来查看副本集的配置
查看副本集状态使用 rs.status() 命令

只能通过主节点,添加到副节点中,判断当前运行的Mongo服务是否为主节点可以使用命令db.isMaster() 

// 启动一个新的副本集
rs.initiate()
myrs:PRIMARY> rs.conf()
{
	"_id" : "myrs",
	"version" : 1,
	"term" : 1,
	"protocolVersion" : NumberLong(1),
	"writeConcernMajorityJournalDefault" : true,
	"members" : [
		{
			"_id" : 0,
			"host" : "localhost:27017",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {
				
			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		}
	],
	"settings" : {
		"chainingAllowed" : true,
		"heartbeatIntervalMillis" : 2000,
		"heartbeatTimeoutSecs" : 10,
		"electionTimeoutMillis" : 10000,
		"catchUpTimeoutMillis" : -1,
		"catchUpTakeoverDelayMillis" : 30000,
		"getLastErrorModes" : {
			
		},
		"getLastErrorDefaults" : {
			"w" : 1,
			"wtimeout" : 0
		},
		"replicaSetId" : ObjectId("5f9fc57450e3bf89a3a1016c")
	}
}

// 添加除此节点的另外两个节点
myrs:PRIMARY> rs.add("127.0.0.1:27027")
{
	"ok" : 1,
	"$clusterTime" : {
		"clusterTime" : Timestamp(1604306642, 2),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	},
	"operationTime" : Timestamp(1604306642, 2)
}
// 添加另外一个节点
myrs:PRIMARY> rs.add("127.0.0.1:27037")
{
	"ok" : 1,
	"$clusterTime" : {
		"clusterTime" : Timestamp(1604306692, 2),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	},
	"operationTime" : Timestamp(1604306692, 2)
}

// 检测master
myrs:PRIMARY> db.isMaster()
{
	"topologyVersion" : {
		"processId" : ObjectId("5f9fc36d50e3bf89a3a10155"),
		"counter" : NumberLong(8)
	},
	"hosts" : [
		"localhost:27017",
		"127.0.0.1:27027",
		"127.0.0.1:27037"
	],
	"setName" : "myrs",
	"setVersion" : 3,
	"ismaster" : true,
	"secondary" : false,
	"primary" : "localhost:27017",
	"me" : "localhost:27017",
	"electionId" : ObjectId("7fffffff0000000000000001"),
	"lastWrite" : {
		"opTime" : {
			"ts" : Timestamp(1604306752, 1),
			"t" : NumberLong(1)
		},
		"lastWriteDate" : ISODate("2020-11-02T08:45:52Z"),
		"majorityOpTime" : {
			"ts" : Timestamp(1604306752, 1),
			"t" : NumberLong(1)
		},
		"majorityWriteDate" : ISODate("2020-11-02T08:45:52Z")
	},
	"maxBsonObjectSize" : 16777216,
	"maxMessageSizeBytes" : 48000000,
	"maxWriteBatchSize" : 100000,
	"localTime" : ISODate("2020-11-02T08:46:00.379Z"),
	"logicalSessionTimeoutMinutes" : 30,
	"connectionId" : 1,
	"minWireVersion" : 0,
	"maxWireVersion" : 9,
	"readOnly" : false,
	"ok" : 1,
	"$clusterTime" : {
		"clusterTime" : Timestamp(1604306752, 1),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	},
	"operationTime" : Timestamp(1604306752, 1)
}

// status
myrs:PRIMARY> rs.status()
{
	"set" : "myrs",
	"date" : ISODate("2020-11-02T08:46:59.662Z"),
	"myState" : 1,
	"term" : NumberLong(1),
	"syncSourceHost" : "",
	"syncSourceId" : -1,
	"heartbeatIntervalMillis" : NumberLong(2000),
	"majorityVoteCount" : 2,
	"writeMajorityCount" : 2,
	"votingMembersCount" : 3,
	"writableVotingMembersCount" : 3,
	"optimes" : {
		"lastCommittedOpTime" : {
			"ts" : Timestamp(1604306812, 1),
			"t" : NumberLong(1)
		},
		"lastCommittedWallTime" : ISODate("2020-11-02T08:46:52.212Z"),
		"readConcernMajorityOpTime" : {
			"ts" : Timestamp(1604306812, 1),
			"t" : NumberLong(1)
		},
		"readConcernMajorityWallTime" : ISODate("2020-11-02T08:46:52.212Z"),
		"appliedOpTime" : {
			"ts" : Timestamp(1604306812, 1),
			"t" : NumberLong(1)
		},
		"durableOpTime" : {
			"ts" : Timestamp(1604306812, 1),
			"t" : NumberLong(1)
		},
		"lastAppliedWallTime" : ISODate("2020-11-02T08:46:52.212Z"),
		"lastDurableWallTime" : ISODate("2020-11-02T08:46:52.212Z")
	},
	"lastStableRecoveryTimestamp" : Timestamp(1604306772, 1),
	"electionCandidateMetrics" : {
		"lastElectionReason" : "electionTimeout",
		"lastElectionDate" : ISODate("2020-11-02T08:38:12.097Z"),
		"electionTerm" : NumberLong(1),
		"lastCommittedOpTimeAtElection" : {
			"ts" : Timestamp(0, 0),
			"t" : NumberLong(-1)
		},
		"lastSeenOpTimeAtElection" : {
			"ts" : Timestamp(1604306292, 1),
			"t" : NumberLong(-1)
		},
		"numVotesNeeded" : 1,
		"priorityAtElection" : 1,
		"electionTimeoutMillis" : NumberLong(10000),
		"newTermStartDate" : ISODate("2020-11-02T08:38:12.118Z"),
		"wMajorityWriteAvailabilityDate" : ISODate("2020-11-02T08:38:12.145Z")
	},
	"members" : [
		{
			"_id" : 0,
			"name" : "localhost:27017",
			"health" : 1,
			"state" : 1,
			"stateStr" : "PRIMARY",
			"uptime" : 1046,
			"optime" : {
				"ts" : Timestamp(1604306812, 1),
				"t" : NumberLong(1)
			},
			"optimeDate" : ISODate("2020-11-02T08:46:52Z"),
			"syncSourceHost" : "",
			"syncSourceId" : -1,
			"infoMessage" : "",
			"electionTime" : Timestamp(1604306292, 2),
			"electionDate" : ISODate("2020-11-02T08:38:12Z"),
			"configVersion" : 3,
			"configTerm" : 1,
			"self" : true,
			"lastHeartbeatMessage" : ""
		},
		{
			"_id" : 1,
			"name" : "127.0.0.1:27027",
			"health" : 1,
			"state" : 2,
			"stateStr" : "SECONDARY",
			"uptime" : 176,
			"optime" : {
				"ts" : Timestamp(1604306812, 1),
				"t" : NumberLong(1)
			},
			"optimeDurable" : {
				"ts" : Timestamp(1604306812, 1),
				"t" : NumberLong(1)
			},
			"optimeDate" : ISODate("2020-11-02T08:46:52Z"),
			"optimeDurableDate" : ISODate("2020-11-02T08:46:52Z"),
			"lastHeartbeat" : ISODate("2020-11-02T08:46:58.918Z"),
			"lastHeartbeatRecv" : ISODate("2020-11-02T08:46:58.959Z"),
			"pingMs" : NumberLong(0),
			"lastHeartbeatMessage" : "",
			"syncSourceHost" : "localhost:27017",
			"syncSourceId" : 0,
			"infoMessage" : "",
			"configVersion" : 3,
			"configTerm" : 1
		},
		{
			"_id" : 2,
			"name" : "127.0.0.1:27037",
			"health" : 1,
			"state" : 2,
			"stateStr" : "SECONDARY",
			"uptime" : 126,
			"optime" : {
				"ts" : Timestamp(1604306812, 1),
				"t" : NumberLong(1)
			},
			"optimeDurable" : {
				"ts" : Timestamp(1604306812, 1),
				"t" : NumberLong(1)
			},
			"optimeDate" : ISODate("2020-11-02T08:46:52Z"),
			"optimeDurableDate" : ISODate("2020-11-02T08:46:52Z"),
			"lastHeartbeat" : ISODate("2020-11-02T08:46:58.940Z"),
			"lastHeartbeatRecv" : ISODate("2020-11-02T08:46:59.287Z"),
			"pingMs" : NumberLong(0),
			"lastHeartbeatMessage" : "",
			"syncSourceHost" : "127.0.0.1:27027",
			"syncSourceId" : 1,
			"infoMessage" : "",
			"configVersion" : 3,
			"configTerm" : 1
		}
	],
	"ok" : 1,
	"$clusterTime" : {
		"clusterTime" : Timestamp(1604306812, 1),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	},
	"operationTime" : Timestamp(1604306812, 1)
}

集群测试

在主节点(40000)插入、查询数据。是否成功? 在从节点(40001)插入、查询数据。是否成功? 主节点(40000)关闭 查看从节点,看从节点是否成为主节点 重新启动原来的主节点(40000),查看节点状态

代码语言:javascript复制
myapp:PRIMARY> db.stu.find()
myapp:PRIMARY> db.stu.insert({name:'zhangsan'})
WriteResult({ "nInserted" : 1 })
myapp:PRIMARY> db.stu.find()
{ "_id" : ObjectId("5f58d9aaafeaa3a829c63d4b"), "name" : "zhangsan" }
myapp:PRIMARY>




//主节点关机(40000)


myapp:PRIMARY> use admin
switched to db admin
myapp:PRIMARY> db.shutdownServer()
server should be down...
2020-09-09T21:38:20.925 0800 I NETWORK  [thread1] trying reconnect to 127.0.0.1:40000 (127.0.0.1) failed
2020-09-09T21:38:21.635 0800 I NETWORK  [thread1] Socket recv() Connection reset by peer 127.0.0.1:40000
2020-09-09T21:38:21.635 0800 I NETWORK  [thread1] SocketException: remote: (NONE):0 error: SocketException socket exception [RECV_ERROR] server [127.0.0.1:40000] 
2020-09-09T21:38:21.636 0800 I NETWORK  [thread1] reconnect 127.0.0.1:40000 (127.0.0.1) failed failed 
>

//观察从节点,40002成为master
[hadoop@hadoop1 bin]$ mongo -port 40002

myapp:PRIMARY> db.isMaster()
{
	"hosts" : [
		"localhost:40000",
		"127.0.0.1:40001",
		"127.0.0.1:40002"
	],
	"setName" : "myapp",
	"setVersion" : 3,
	"ismaster" : true,
	"secondary" : false,
	"primary" : "127.0.0.1:40002",
	"me" : "127.0.0.1:40002",
	"electionId" : ObjectId("7fffffff0000000000000002"),
	"lastWrite" : {
		"opTime" : {
			"ts" : Timestamp(1599658861, 1),
			"t" : NumberLong(2)
		},
		"lastWriteDate" : ISODate("2020-09-09T13:41:01Z"),
		"majorityOpTime" : {
			"ts" : Timestamp(1599658861, 1),
			"t" : NumberLong(2)
		},
		"majorityWriteDate" : ISODate("2020-09-09T13:41:01Z")
	},
	"maxBsonObjectSize" : 16777216,
	"maxMessageSizeBytes" : 48000000,
	"maxWriteBatchSize" : 100000,
	"localTime" : ISODate("2020-09-09T13:41:04.249Z"),
	"logicalSessionTimeoutMinutes" : 30,
	"minWireVersion" : 0,
	"maxWireVersion" : 6,
	"readOnly" : false,
	"ok" : 1,
	"operationTime" : Timestamp(1599658861, 1),
	"$clusterTime" : {
		"clusterTime" : Timestamp(1599658861, 1),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	}
}
myapp:PRIMARY>

// 40002 可以查询数据
myapp:PRIMARY> db.stu.find()
{ "_id" : ObjectId("5f58d9aaafeaa3a829c63d4b"), "name" : "zhangsan" }
myapp:PRIMARY>

// 40001 不允许查询数据
myapp:SECONDARY> db.stu.find()
Error: error: {
	"operationTime" : Timestamp(1599658961, 1),
	"ok" : 0,
	"errmsg" : "not master and slaveOk=false",
	"code" : 13435,
	"codeName" : "NotMasterNoSlaveOk",
	"$clusterTime" : {
		"clusterTime" : Timestamp(1599658961, 1),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	}
}
myapp:SECONDARY>


重新启动40000


[hadoop@hadoop1 bin]$ mongod --replSet myapp --dbpath /opt/module/mongodb/data1 --port 40000

[hadoop@hadoop1 bin]$ mongo -port 40000


myapp:SECONDARY> rs.isMaster()
{
	"hosts" : [
		"localhost:40000",
		"127.0.0.1:40001",
		"127.0.0.1:40002"
	],
	"setName" : "myapp",
	"setVersion" : 3,
	"ismaster" : false,
	"secondary" : true,
	"primary" : "127.0.0.1:40002",
	"me" : "localhost:40000",
	"lastWrite" : {
		"opTime" : {
			"ts" : Timestamp(1599659401, 1),
			"t" : NumberLong(2)
		},
		"lastWriteDate" : ISODate("2020-09-09T13:50:01Z"),
		"majorityOpTime" : {
			"ts" : Timestamp(1599659401, 1),
			"t" : NumberLong(2)
		},
		"majorityWriteDate" : ISODate("2020-09-09T13:50:01Z")
	},
	"maxBsonObjectSize" : 16777216,
	"maxMessageSizeBytes" : 48000000,
	"maxWriteBatchSize" : 100000,
	"localTime" : ISODate("2020-09-09T13:50:10.511Z"),
	"logicalSessionTimeoutMinutes" : 30,
	"minWireVersion" : 0,
	"maxWireVersion" : 6,
	"readOnly" : false,
	"ok" : 1,
	"operationTime" : Timestamp(1599659401, 1),
	"$clusterTime" : {
		"clusterTime" : Timestamp(1599659401, 1),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	}
}
myapp:SECONDARY>

注意

只能通过主节点,添加到副节点中,判断当前运行的Mongo服务是否为主节点可以使用命令db.isMaster() 只能通过,主节点来查

配置Debezium的connect

参考博客 local下的读权限,获取日志 zookeeper和kafka的启动 连接的debezium启动

代码语言:javascript复制
./bin/connect-distributed.sh -daemon config/connect-distributed.properties
# 分布式启动,单例模式需要指定下一个代码段的配置信息

kafka的conf文件夹中找到connect-distributed.properties文件(同mysql的伪分布式配置一样)

连接器

代码语言:javascript复制
'{
"name": "mongodb-connector",   # 名字自己取
    "config": {
        "connector.class": "io.debezium.connector.mongodb.MongoDbConnector",  # connector连接器class名称
        "task.max": "1",        
        "mongodb.hosts": "rs77/172.168.31.77:27001, rs77/172.168.31.77:27002, rs77/172.168.31.77:27003",  # 这里注意要副本集 地址端口形式,不然可能无法连接
        "mongodb.user": "mongo", 
        "mongodb.password": "123", 
        "mongodb.authsource": "kafkatest",  # 认证库, 即你shell登录要先use到所在的库才可以进行改库的账户登录 
        "mongodb.name": "rs77",     # 副本集名称
        "database.history.kafka.bootstrap.servers": "172.168.31.77:9092, 172.168.31.78:9092, 172.168.31.79:9092",  # kafka地址
        "snapshot.delay.ms": "3000", 
        "database.whitelist": "kafkatest"   # 监测的库名,可以正则匹配
        }
}'

实际使用

代码语言:javascript复制
{
  "name": "mongodb-connector",  
  "config": {
    "connector.class": "io.debezium.connector.mongodb.MongoDbConnector", 
    "mongodb.hosts": "myrs/192.168.137.121:27017, myrs/192.168.137.121:27027, myrs/192.168.137.121:27037", 
    "mongodb.name": "myrs", 
    "database.history.kafka.bootstrap.servers": "192.168.137.121:9092", 
    "collection.whitelist": "kafkatest"
  }
}

昌杰修正版

代码语言:javascript复制
{
        "connector.class": "io.debezium.connector.mongodb.MongoDbConnector",
        "name": "mongodb-connector1",
        "mongodb.name": "myrs",
        "mongodb.hosts": "myrs/192.168.137.121:27017",
        "collection.whitelist": "kafkatest.rxguo"
    }

创建数据库

代码语言:javascript复制
myrs:PRIMARY> use kafkatest
switched to db kafkatest
myrs:PRIMARY> db
kafkatest
myrs:PRIMARY> show dbs
admin   0.000GB
config  0.000GB
local   0.001GB
test    0.000GB
myrs:PRIMARY> db.kafkatest.insert({"name", "菜鸟教程"})
uncaught exception: SyntaxError: missing : after property id :
@(shell):1:27
myrs:PRIMARY> db
kafkatest
myrs:PRIMARY> db.kafkatest.insert({"name", "测试"})
uncaught exception: SyntaxError: missing : after property id :
@(shell):1:27
myrs:PRIMARY> db.kafkatest.insert({"name":"测试"})
WriteResult({ "nInserted" : 1 })
myrs:PRIMARY> db.kafkatest.insert({"name":"菜鸟教程"})
WriteResult({ "nInserted" : 1 })
myrs:PRIMARY> show dbs
admin      0.000GB
config     0.000GB
kafkatest  0.000GB
local      0.001GB
test       0.000GB

配置文件启动

代码语言:javascript复制
// 注意两个--port
mongo --port 27017
rs.initiate()



rs.add("192.168.137.121:27017")
rs.add("192.168.137.121:27027")
rs.add("192.168.137.121:27037")


myrs:PRIMARY> rs.conf()
{
	"_id" : "myrs",
	"version" : 3,
	"term" : 2,
	"protocolVersion" : NumberLong(1),
	"writeConcernMajorityJournalDefault" : true,
	"members" : [
		{
			"_id" : 0,
			"host" : "hadoop01:27017",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {
				
			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 1,
			"host" : "192.168.137.121:27027",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {
				
			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		},
		{
			"_id" : 2,
			"host" : "192.168.137.121:27037",
			"arbiterOnly" : false,
			"buildIndexes" : true,
			"hidden" : false,
			"priority" : 1,
			"tags" : {
				
			},
			"slaveDelay" : NumberLong(0),
			"votes" : 1
		}
	],
	"settings" : {
		"chainingAllowed" : true,
		"heartbeatIntervalMillis" : 2000,
		"heartbeatTimeoutSecs" : 10,
		"electionTimeoutMillis" : 10000,
		"catchUpTimeoutMillis" : -1,
		"catchUpTakeoverDelayMillis" : 30000,
		"getLastErrorModes" : {
			
		},
		"getLastErrorDefaults" : {
			"w" : 1,
			"wtimeout" : 0
		},
		"replicaSetId" : ObjectId("5fa12b198c2c3960105a9151")
	}
}

Environment=“OPTIONS=-f /etc/mongod27017.conf”

代码语言:javascript复制
正确关闭mongod 的方法:进入mongo shell

    use admin
    db.shutdownServer()

注意关闭顺序

删除掉该文件:

代码语言:javascript复制
rm /data/db/mongo.lock

再执行:

代码语言:javascript复制
./mongod --repair

检验

代码语言:javascript复制
// 查看创建的topic信息
bin/kafka-topics.sh --list --zookeeper 192.168.137.121:2181 rxguo-topic
// 输出kafka对应的连接器内容
bin/kafka-console-consumer.sh --bootstrap-server 192.168.137.121:9092 --topic myrs.kafkatest.rxguo --from-beginning

解决无法远程连接的问题-服务启动失败

常见问题1: 开放端口

问题二 服务未启动 查看状态service mongod status 开启服务sudo service mongod start

代码语言:javascript复制
Redirecting to /bin/systemctl start mongod.service
Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.

mongod[6108]: ERROR: child process failed, exited with 14 错误原因: mongodb非正常关闭 删除mongod.lock文件即可. ERROR: child process failed, exited with error number 100 错误原因: mongodb非正常关闭 删除mongod.lock文件即可. ERROR: child process failed ,exited with error number 1 错误原因: dbpath文件的权限问题,增加写权限即可 mongodb.conf bind 不能写127.0.0.1否则其它主机连接不了 情况不唯一,这边只能当参考,大致就是这么几种解决思路

代码语言:javascript复制
exited with 1,说明第一行就是错的就退出了。应该是一开头的路径配置就有错误。

这里可能的原因有以下几种:

1.排查文件名称,到底是mongodb.conf 还是 mongod.conf;

2.排查当前bin文件中,mongodb.conf这个文件内的内容是否配置路径是正确的?

3.执行sudo nano /etc/systemd/system/mongodb.service,排查其中的路径是否正确,是否是指向配置的mongod.conf文件和mongod文件。尤其要仔细看到底是放在usr/bin还是usr/bin/local还是usr/etc还是……(等等等路径)下的,这个路径要与mongodb.conf中配置的路径吻合。

修改完成后,执行如下代码:

systemctl daemon-reload

sudo systemctl start mongodb

sudo systemctl status mongodb

出现绿色的Active: active(running)时,成功。

配置文件

如果配置文件方式启动 注意三个文件指定不同的path前缀

代码语言:javascript复制
[root@hadoop01 mongo]# pwd
/opt/install/mongo
[root@hadoop01 mongo]# ll
总用量 12
drwxr-xr-x. 4 root root 4096 11月  3 17:22 data1
drwxr-xr-x. 4 root root 4096 11月  3 17:17 data2
drwxr-xr-x. 4 root root 4096 11月  3 17:18 data3

启动指定配置文件mongod -f mongod27017.conf

代码语言:javascript复制
# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /opt/install/mongo/data1/mongod.log

# Where and how to store data.
storage:
  dbPath: /opt/install/mongo/data1
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /opt/install/mongo/data1/mongod.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

# network interfaces
net:
  port: 27017
  bindIp: 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:

#operationProfiling:

replication:
  replSetName: myrs
#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

待解决服务启动问题

Linux

wget下载url文件

代码语言:javascript复制
// 安装wget命令
yum install wget
// 直接下载文件url
wget 文件url

0 人点赞