mongodb4.x 在 ubuntu 22.04 以上的版本没有提供 deb 安装包。经过测试以下两种方式都能安装成功。
1
2
|
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
|
下载 mongodb4.4 tar
1
2
|
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2004-4.4.29.tgz
tar -zxvf mongodb-linux-x86_64-ubuntu2004-4.4.29.tgz
|
下载 mongo-tools
https://www.mongodb.com/try/download/database-tools
1
2
|
wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-ubuntu2404-x86_64-100.12.2.tgz
tar -zxvf mongodb-database-tools-ubuntu2404-x86_64-100.12.2.tgz
|
docker-compose.yml 文件如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
services:
mongodb-rs0:
network_mode: bridge
container_name: mongodb-rs0
image: mongo:4.4.29
ports:
- "27017:27017"
restart: always
command: mongod --port 27017 --replSet rs0 --logpath=/data/logs/log
volumes:
- ./data-27017:/data/db
- ./logs-27017:/data/logs
- ./configdb-27017:/data/configdb
mongodb-rs1:
network_mode: bridge
container_name: mongodb-rs1
image: mongo:4.4.29
ports:
- "27030:27017"
restart: always
command: mongod --port 27017 --replSet rs1 --logpath=/data/logs/log
volumes:
- ./data-27030:/data/db
- ./logs-27030:/data/logs
- ./configdb-27030:/data/configdb
|
进入 mongo shell
1
|
docker exec -it mongodb-rs0 mongo
|
设置初始化配置
1
2
3
4
5
6
|
conf = {
_id : "rs0",
members: [
{ _id: 0, host: "100.111.111.1:27017" },
]
}
|
将 100.111.111.1 替换为自己的 IP
其他的一个节点也类似。