Install MongoDB on Centos 7

#!/bin/bash
#######################
#mongodb简介
#mongodb是个非关系型数据库,但操作跟关系型数据最类似。mysql是关系型数据库
#mongodb是面向文档存储的非关系型数据库,数据以json的格式进行存储
#mongodb可用来永久存储,也可用来缓存数据
#mongodb提供副本集和分片集群功能,操作简单
#############################
if [ `whoami` != root ]
then
echo "Please login as root to continue :)"
exit 1
fi

if [ ! -d /home/tools/ ];then
mkdir -p /home/tools
else
rm -rf /home/tools && mkdir -p /home/tools
fi

#Prohibit memory giant pages
echo ‘never‘ >/sys/kernel/mm/transparent_hugepage/enabled
echo ‘never‘ >/sys/kernel/mm/transparent_hugepage/defrag

#Add commands to /etc/rc.local
chmod +x /etc/rc.d/rc.local
echo "echo ‘never‘ >/sys/kernel/mm/transparent_hugepage/enabled" >>/etc/rc.local
echo "echo ‘never‘ >/sys/kernel/mm/transparent_hugepage/defrag" >>/etc/rc.local

#Disable firewall and selinux
sed -i ‘/SELINUX/s/enforcing/disabled/‘ /etc/selinux/config
systemctl disable firewalld.service

#Setting Handles Number and Process
cat >> /etc/security/limits.conf << EOF
* soft nofile 204800
* hard nofile 204800
* soft nproc 204800
* hard nproc 204800
EOF

sed -i ‘s/4096/204800/g‘ /etc/security/limits.d/20-nproc.conf

#download mongodb on centos 7
cd /home/tools && wget -c https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.6.tgz

#install mongodb
tar zxvf mongodb-linux-x86_64-rhel70-4.0.6.tgz
mv mongodb-linux-x86_64-rhel70-4.0.6 /usr/local/mongodb-linux-x86_64-rhel70-4.0.6
ln -s /usr/local/mongodb-linux-x86_64-rhel70-4.0.6 /usr/local/mongodb

#Create data directory
mkdir -p /data/mongodb/27017/

cat > /data/mongodb/27017/mongodb.conf <<EOF
systemLog:
destination: file
logAppend: true
path: /data/mongodb/27017/mongodb.log
storage:
dbPath: /data/mongodb/27017/
journal:
enabled: true
processManagement:
fork: true
net:
port: 27017
bindIp: 0.0.0.0
EOF

#Add mongodb users and setting permission
useradd mongodb && chown -R mongodb.mongodb /data/mongodb/ /usr/local/mongodb/

#Add autoStart script
cat >/etc/init.d/mongodb <<EOF
#!/bin/bash
# Description:mongodb ORS SERVER
# chkconfig: - 85 15
# Written by jerry
MONGODB_EXEC="/usr/local/mongodb/bin/mongod"
MONGODB_DATA="/data/mongodb/27017/"
MONGODB_CONF="/data/mongodb/27017/mongodb.conf"
PORT=\$(netstat -tunlp|grep 27017|awk ‘{print \$4}‘|cut -d ‘:‘ -f2)
MONGODB_USER=mongodb
case \$1 in
start)
echo -n "Starting mongodb..."
if [[ \$PORT = 27017 ]];then
echo "mongodb is alreday running!"
else
/bin/su - \$MONGODB_USER -s /bin/bash -c "\$MONGODB_EXEC -f \$MONGODB_CONF"
fi
echo " done"
;;
stop)
echo -n "Stoping mongodb..."
/bin/su - \$MONGODB_USER -s /bin/bash -c "\$MONGODB_EXEC --shutdown --dbpath \$MONGODB_DATA"
echo " done"
;;
restart)
\$0 stop
\$0 start
;;
status)
if [[ \$PORT != 27017 ]];then
echo "mongodb is not running!"
else
echo "mongodb is running!"
fi
;;
*)
echo "Usage: \$0"
exit 1
esac
EOF

#Setting environment variables
cat >/etc/profile.d/mongodb.sh<<EOF
export MONGODB_HOME=/usr/local/mongodb
export PATH=\$PATH:\$MONGODB_HOME/bin
EOF

source /etc/profile.d/mongodb.sh

#Add permission to /etc/init.d/mongodb
chmod +x /etc/init.d/mongodb

#Add to chkconfig service
chkconfig --add mongodb

#Setting up MongoDB auto-start
chkconfig mongodb on

#Start MongoDB
service mongodb start

原文地址:https://blog.51cto.com/jinyan2049/2367495

时间: 2024-08-29 20:33:58

Install MongoDB on Centos 7的相关文章

Install MongoDB on Red Hat Enterprise, CentOS, Fedora, or Amazon Linux

Install MongoDB on Red Hat Enterprise, CentOS, Fedora, or Amazon Linux? Overview Use this tutorial to install MongoDB on Red Hat Enterprise Linux, CentOS Linux, Fedora Linux, or a related system. The tutorial uses .rpm packages to install. While some

转: How to Install MongoDB 3.2 on CentOS/RHEL &amp; Fedora (简单易懂)

from:  http://tecadmin.net/install-mongodb-on-centos-rhel-and-fedora/ MongoDB (named from “huMONGOus“) is a full flexible index support and rich queries database. Its is a NoSQL database. MongoDB provides large media storage with GridFS. Clickhere fo

How to Install MySQL on CentOS 7

How to Install MySQL on CentOS 7 Updated Thursday, August 27th, 2015 by Linode Use promo code DOCS10 for $10 credit on a new account. Try this Guide Contribute on GitHub View Project | View File | Edit File MySQL is a popular database management syst

How to install MP4box on CentOS 6

How to install MP4box on CentOS 6 MP4Box is a MP4 multiplexer. It can import MPEG-4 video, DivX, XviD, 3ivx, h264 etc, audio streams and subtitles into the .mp4 container. The end result is a compliant MP4 stream. It can also extract streams from a .

Install MongoDB on Windows

Overview Use this tutorial to install MongoDB on a Windows systems. PLATFORM SUPPORT Starting in version 2.2, MongoDB does not support Windows XP. Please use a more recent version of Windows to use more recent releases of MongoDB. IMPORTANT If you ar

Install Ceph on CentOS 6.5

vi /etc/yum.repos.d/ceph-extras.repo[ceph-extras]name=Ceph Extras Packagesbaseurl=file:///ceph/ceph-extrasenabled=1priority=2gpgcheck=0type=rpm-md [ceph-extras-noarch]name=Ceph Extras noarchbaseurl=file:///ceph/ceph-extras-noarchenabled=1priority=2gp

Install MongoDB driver for PHP on XAMPP for Mac OSX

试了不少方法,最后还是这个最有效. [转自:http://thatsimplecode.com/install-mongodb-driver-for-php-on-xampp-for-mac-osx] You need to have the following installed in your Mac: MongoDB XAMPP for Mac OSX Homebrew Package Manager Type the following in your terminal : brew i

install mongodb on macos

Update Homebrew’s package database. In a system shell, issue the following command: brew update 2 Install MongoDB. You can install MongoDB via brew with several different options. Use one of the following operations: Install the MongoDB Binaries To i

Install MongoDB on Linux Systems 速记

Download the Latest Release >> curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.4.8.tgz Extract MongoDB From Archive >> tar -zxvf mongodb-linux-x86_64-2.4.8.tgz Optional. Copy MongoDB to Target Directory >> mkdir -p mong