解决运行Mongodb报错 Attempted to create a lock file on a read-only directory: /data/db

汪志业
2023-12-01

完整报错:

{"t":
	{"$date":"2022-07-15T09:36:09.517+08:00"},
	"s":"E",  
	"c":"CONTROL", 
	 "id":20557,   
	 "ctx":"initandlisten",
	 "msg":"DBException in initAndListen, terminating",
	 "attr":
	 	{"error":"IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db"}
}

解决方法

如果没有/data/db文件夹,则创建并赋予权限即可:

sudo mkdir -m 777 -p /data/db

如果已经创建了data/db文件夹,直接赋予权限即可:

sudo chmod 777 /data/*
 类似资料: