最初安装Mongodb是从官网下载最新的tar.gz包,但老是报./bin/mongod: /usr/lib64/libstdc++.so.6: version `CXXABI_1.3.5' notfound (required by ./bin/mongod)错误!网上搜索了很多方法,但是都不顶用,感觉是版本问题,所以决定换个思路安装。参考官方文档。
[root@WH bin]# uname -a
Linux WH 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
1、配置包管理系统(yum)
For versions of MongoDB earlier than 3.0
To install the packages from an earlier release series, such as 2.4 or 2.6, you can specify the release series in the repository configuration. For example, to restrict your system to the 2.6 release series, create a /etc/yum.repos.d/mongodb-org-2.6.repofile to hold the following configuration information for the MongoDB 2.6repository:
[mongodb-org-2.6]
name=MongoDB 2.6Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
You can find .repo files for each release in the repository itself. Remember that odd-numbered minor release versions(e.g. 2.5) are development versions and are unsuitable for production use.
2、安装Mongodb包及其相关工具
Install the MongoDB packages and associated tools.
When you install the packages, you choose whether to install the current release or a previous one. This step provides the commands for both.
To install the latest stable version of MongoDB, issue the following command:
sudo yum install -y mongodb-org
To install a specific release of MongoDB, specify each component package individually and append the version number to the packagename, as in the following example:
sudo yum install -y mongodb-org-3.2.4 mongodb-org-server-3.2.4 mongodb-org-shell-3.2.4 mongodb-org-mongos-3.2.4 mongodb-org-tools-3.2.4
You can specify any available version of MongoDB. However yum will upgrade the packages when a newer version becomes available. To prevent unintended upgrades, pin the package. To pin a package,add the following exclude directive to your /etc/yum.conf file:
exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools
3、运行Mongodb
You can start the mongod process by issuing the following command:
sudo service mongod start
4、验证Mongodb是否启动成功
You can verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.logfor a line reading
[initandlisten] waiting for connections on port <port>
where <port> is the portconfigured in /etc/mongod.conf, 27017 bydefault.
You can optionally ensure that MongoDB will start followinga system reboot by issuing the following command:
sudo chkconfig mongod on
5、停止Mongodb
As needed, you can stop the mongod process by issuing the following command:
sudo service mongod stop
6、重启Mongodb
You can restart the mongod process by issuing the following command:
sudo service mongod restart
You can follow the state of the process for errors or important messages by watching the output in the /var/log/mongodb/mongod.log file.
7、卸载Mongodb
(1)停止Mongodb
Stop the mongod process by issuing the following command:
sudo service mongod stop
(2)删除包
Remove any MongoDB packages that you had previously installed.
sudo yum erase $(rpm -qa | grep mongodb-org)
(3)删除数据目录
Remove MongoDB databases and log files.
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongo