mongodb服务脚本编写
1.新建配置文件 mongodb安装时缺少配置文件 在 /etc 目录下新建 mongod.conf 配置文件 内容如下 # mongo.conf#where to loglogpath=/data/logs/db.loglogappend=true# fork and run in backgroundfork = true#port = 27017dbpath=/data/db# Enables periodic
1.新建配置文件
mongodb安装时缺少配置文件
在 /etc 目录下新建 mongod.conf 配置文件
内容如下
# mongo.conf #where to log logpath=/data/logs/db.log logappend=true # fork and run in background fork = true #port = 27017 dbpath=/data/db # Enables periodic logging of CPU utilization and I/O wait #cpu = true # Turn on/off security. Off is currently the default #noauth = true #auth = true # Verbose logging output. #verbose = true # Inspect all client data for validity on receipt (useful for # developing drivers) #objcheck = true # Enable db quota management #quota = true "/etc/mongod.conf" 82L, 1628C # mongo.conf #where to log logpath=/data/logs/db.log logappend=true # fork and run in background fork = true #port = 27017 dbpath=/data/db # Enables periodic logging of CPU utilization and I/O wait #cpu = true # Turn on/off security. Off is currently the default #noauth = true #auth = true # Verbose logging output. #verbose = true # Inspect all client data for validity on receipt (useful for # developing drivers) #objcheck = true # Enable db quota management #quota = true # Set oplogging level where n is # 0=off (default) # 1=W # 2=R # 3=both # 7=W+some reads #oplog = 0 # Diagnostic/debugging option #nocursors = true # Ignore query hints #nohints = true # Disable the HTTP interface (Defaults to localhost:27018). #nohttpinterface = true # Turns off server-side scripting. This will result in greatly limited # functionality #noscripting = true # Turns off table scans. Any query that would do a table scan fails. #notablescan = true # Disable data file preallocation. #noprealloc = true # Specify .ns file size for new databases. # nssize = <size> # Accout token for Mongo monitoring server. #mms-token = <token> # Server name for Mongo monitoring server. #mms-name = <server-name> # Ping interval for Mongo monitoring server. #mms-interval = <seconds> # Replication Options # in replicated mongo databases, specify here whether this is a slave or master #slave = true #source = master.example.com # Slave only: specify a single database to replicate #only = master.example.com # or #master = true #source = slave.example.com 2.启动
mongodb/bin/mongod -f /etc/mongod.conf
这种启动我感到很不爽,那我就做成service
3.service(服务)脚本
在 /etc/init.d 目录下新建 mongod文件
内容如下
#!/bin/sh # #mongod - Startup script for mongod # # chkconfig: - 85 15 # description: Mongodb database. # processname: mongod # Source function library . /etc/rc.d/init.d/functions # things from mongod.conf get there by mongod reading it # OPTIONS OPTIONS=" -f /etc/mongod.conf" #mongod mongod="/root/mongodb/bin/mongod" lockfile=/var/lock/subsys/mongod start() { echo -n $"Starting mongod: " daemon $mongod $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch $lockfile } "/etc/init.d/mongod" 70L, 1036C #!/bin/sh # #mongod - Startup script for mongod # # chkconfig: - 85 15 # description: Mongodb database. # processname: mongod # Source function library . /etc/rc.d/init.d/functions # things from mongod.conf get there by mongod reading it # OPTIONS OPTIONS=" -f /etc/mongod.conf" #mongod mongod="/root/mongodb/bin/mongod" lockfile=/var/lock/subsys/mongod start() { echo -n $"Starting mongod: " daemon $mongod $OPTIONS RETVAL=$? echo [ $RETVAL -eq 0 ] && touch $lockfile } stop() { echo -n $"Stopping mongod: " killproc $mongod -QUIT RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f $lockfile } restart () { stop start } ulimit -n 12000 RETVAL=0 case "$1" in start) start ;; stop) stop ;; restart|reload|force-reload) restart ;; condrestart) [ -f $lockfile ] && restart || : ;; status) status $mongod RETVAL=$? ;; *) echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}" RETVAL=1 esac exit $RETVAL
4.添加文件执行权限
# chmod +x /etc/init.d/mongod
5.service命令
service mongod start
service mongod stop
service mongod restart
6.查看mongod服务的端口
netstat -npt | grep mongod
7.我操,哥哥也会写脚本了
8.这里我想把开机启动也写进去,奈何能力有限,开机启动还是只能放在 /etc/rc.local 下
# mongodb start
/root/mongodb/bin/mongod --repair
/root/mongodb/bin/mongod -f /etc/mongod.conf
9.linux果然博大精深

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











When developing an e-commerce website, I encountered a difficult problem: how to provide users with personalized product recommendations. Initially, I tried some simple recommendation algorithms, but the results were not ideal, and user satisfaction was also affected. In order to improve the accuracy and efficiency of the recommendation system, I decided to adopt a more professional solution. Finally, I installed andres-montanez/recommendations-bundle through Composer, which not only solved my problem, but also greatly improved the performance of the recommendation system. You can learn composer through the following address:

It is impossible to view MongoDB password directly through Navicat because it is stored as hash values. How to retrieve lost passwords: 1. Reset passwords; 2. Check configuration files (may contain hash values); 3. Check codes (may hardcode passwords).

GitLab Database Deployment Guide on CentOS System Selecting the right database is a key step in successfully deploying GitLab. GitLab is compatible with a variety of databases, including MySQL, PostgreSQL, and MongoDB. This article will explain in detail how to select and configure these databases. Database selection recommendation MySQL: a widely used relational database management system (RDBMS), with stable performance and suitable for most GitLab deployment scenarios. PostgreSQL: Powerful open source RDBMS, supports complex queries and advanced features, suitable for handling large data sets. MongoDB: Popular NoSQL database, good at handling sea

Detailed explanation of MongoDB efficient backup strategy under CentOS system This article will introduce in detail the various strategies for implementing MongoDB backup on CentOS system to ensure data security and business continuity. We will cover manual backups, timed backups, automated script backups, and backup methods in Docker container environments, and provide best practices for backup file management. Manual backup: Use the mongodump command to perform manual full backup, for example: mongodump-hlocalhost:27017-u username-p password-d database name-o/backup directory This command will export the data and metadata of the specified database to the specified backup directory.

MongoDB and relational database: In-depth comparison This article will explore in-depth the differences between NoSQL database MongoDB and traditional relational databases (such as MySQL and SQLServer). Relational databases use table structures of rows and columns to organize data, while MongoDB uses flexible document-oriented models to better suit the needs of modern applications. Mainly differentiates data structures: Relational databases use predefined schema tables to store data, and relationships between tables are established through primary keys and foreign keys; MongoDB uses JSON-like BSON documents to store them in a collection, and each document structure can be independently changed to achieve pattern-free design. Architectural design: Relational databases need to pre-defined fixed schema; MongoDB supports

To set up a MongoDB user, follow these steps: 1. Connect to the server and create an administrator user. 2. Create a database to grant users access. 3. Use the createUser command to create a user and specify their role and database access rights. 4. Use the getUsers command to check the created user. 5. Optionally set other permissions or grant users permissions to a specific collection.

Encrypting MongoDB database on a Debian system requires following the following steps: Step 1: Install MongoDB First, make sure your Debian system has MongoDB installed. If not, please refer to the official MongoDB document for installation: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-debian/Step 2: Generate the encryption key file Create a file containing the encryption key and set the correct permissions: ddif=/dev/urandomof=/etc/mongodb-keyfilebs=512

MongoDB is suitable for unstructured data and high scalability requirements, while Oracle is suitable for scenarios that require strict data consistency. 1.MongoDB flexibly stores data in different structures, suitable for social media and the Internet of Things. 2. Oracle structured data model ensures data integrity and is suitable for financial transactions. 3.MongoDB scales horizontally through shards, and Oracle scales vertically through RAC. 4.MongoDB has low maintenance costs, while Oracle has high maintenance costs but is fully supported.
