mongodb的安装部署-备份
1.安装部署
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.10.tgz tar -zxf mongodb-linux-x86_64-3.4.7.tgz mv mongodb-linux-x86_64-3.4.10 /usr/local/mongodb mkdir /usr/local/mongodb/data mkdir /usr/local/mongodb/logs
mkdir conf
cd conf/
2.cat /etc/profile
export MONGODB_HOME=/usr/local/mongodb export PATH=$PATH:$MONGODB_HOME/bin
source /etc/profile
3.配置文件
[root@k8s ~]# cat /usr/local/mongodb/conf/mongodb.conf
port=27017
dbpath=/usr/local/mongodb/data
logpath=/usr/local/mongodb/logs/mongodb.log
pidfilepath=/usr/local/mongodb/mongo.pid
fork=true
logappend=true
auth=true
4.启动服务
./bin/mongod --config ./conf/mongodb.conf
---------------------------------------------------------------------------
1.主要文件
[root@k8s mongodb]# tree
.
├── back_mongodb.sh
├── db_file.txt
├── load_mongodb.sh
└── vars_config.conf
2.备份脚本
[root@k8s mongodb]# cat back_mongodb.sh #!/bin/bash source ./vars_config.conf if [ ! -d "$OUTPUT_DIR" ]; then mkdir -p "$OUTPUT_DIR" fi for db in `cat $DB_FILE` do $MONGODUMP_CMD -h ${HOST}:${PORT}-d $db -o $DUMP_MONGODB done # 删除天之前的备份数据 find /data/backup/ -mtime +30 -name "mongodb*" -exec rm -rf {} \;
3.变量文件
[root@k8s mongodb]# cat vars_config.conf HOST="" PORT="" OUTPUT_DIR="/data/backup/mongodb$(date +%Y%m%d%H%M%S)" DB_FILE="/opt/mongodb/db_file.txt" MONGODUMP_CMD="/usr/local/mongodb/bin/mongodump" MONGORESTORE_CMD="/usr/local/mongodb/bin/mongorestore"
4.数据库名文件
[root@k8s mongodb]# cat db_file.txt
db3
用一个例子来演示会更加清晰