CentOS下MongoDB的升级
生活随笔
收集整理的這篇文章主要介紹了
CentOS下MongoDB的升级
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
8月29號,MongoDB發行了最新的數據庫版本2.2.0.今天我來把它升級一下.下面記錄下我的相關操作. 首先,我查看一下mongod服務有沒有在運行.可以用下面兩個命令查看:
[root@mysql-master ~]# ps -ef | grep mongo
root????? 3244???? 1? 0 Aug15 ???????? 00:00:37 /usr/bin/mongod -f /etc/mongod.conf
root???? 11480 11451? 0 10:18 pts/0??? 00:00:00 grep mongo
[root@mysql-master ~]# netstat -tpln | grep mongo
tcp??????? 0????? 0 0.0.0.0:27017?????????????? 0.0.0.0:*?????????????????? LISTEN????? 3244/mongod???
tcp??????? 0????? 0 0.0.0.0:28017?????????????? 0.0.0.0:*?????????????????? LISTEN????? 3244/mongod?
上面顯示我系統上的mongod服務是正常運行的,下面連上服務查看一下當前版本號及一些數據庫信息:
[root@mysql-master ~]# mongo
MongoDB shell version: 2.0.7
connecting to: test
> show dbs
admin?0.203125GB
jzf?0.203125GB
local?0.203125GB
test?0.203125GB
> exit
升級前一定要關掉服務,停服務我們可以直接在shell里面調用db.shutdownServer()函數.或者用下面這條命令:
/etc/init.d/mongod stop
Stopping mongod:?????????????????????????????????????????? [? OK? ]
服務器停掉后,我們可以將數據做一下備份.因為我這不是生產環境,這里就不做備份了.下面來升級MongoDB數據庫軟件
[root@mysql-master ~]# yum update -y mongo-10gen mongo-10gen-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
?* base: centos.ustc.edu.cn
?* extras: centos.ustc.edu.cn
?* updates: centos.ustc.edu.cn
Setting up Update Process
Resolving Dependencies
--> Running transaction check
---> Package mongo-10gen.x86_64 0:2.2.0-mongodb_1 set to be updated
---> Package mongo-10gen-server.x86_64 0:2.2.0-mongodb_1 set to be updated
--> Finished Dependency Resolution
......
Updated:
? mongo-10gen.x86_64 0:2.2.0-mongodb_1?????????? mongo-10gen-server.x86_64 0:2.2.0-mongodb_1????????? Complete!
升級完成后,我們來試著啟動下服務:
[root@mysql-master mongo]# /etc/init.d/mongod start
Starting mongod: all output going to: /var/log/mongo/mongod.log
forked process: 11577
?????????????????????????????????????????????????????????? [FAILED]
糟糕,服務啟不來,我們換下別的啟動方法.
[root@mysql-master mongo]# which mongod
/usr/bin/mongod
[root@mysql-master mongo]# /usr/bin/mongod -f /etc/mongod.conf
forked process: 11590
all output going to: /var/log/mongo/mongod.log
child process started successfully, parent exiting
我們來看一下,唉,這樣是能正常啟動的.
[root@mysql-master mongo]# ps -ef | grep mongo
root???? 11590???? 1? 2 10:58 ???????? 00:00:00 /usr/bin/mongod -f /etc/mongod.conf
root???? 11601 11451? 0 10:58 pts/0??? 00:00:00 grep mongo
既然服務啟動了,我們來看一下能不能連接:
[root@mysql-master mongo]# mongo
MongoDB shell version: 2.2.0
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
?http://docs.mongodb.org/
Questions? Try the support group
?http://groups.google.com/group/mongodb-user
> use admin
switched to db admin
> db.auth("root","redhat")
1
> show dbs
admin?0.203125GB
jzf?0.203125GB
local?0.203125GB
test?0.203125GB
> use jzf
switched to db jzf
> show collections
blog
food
myself
system.indexes
system.users
test
test.test
user
> db.food.find()
{ "_id" : 1, "fruit" : [ "apple", "banana", "peach", "strawberry" ] }
{ "_id" : 2, "fruit" : [ "apple", "orange", "peach", "strawberry" ] }
{ "_id" : 3, "fruit" : [ "cherry", "orange", "peach", "strawberry" ] }
{ "_id" : 4, "fruit" : [ "cherry", "orange", "kumquat", "strawberry" ] }
> exit
bye
由上面可以看出,服務器版本上升了(原來的2.0.7升到了2.2.0).而且原來的數據都在!突然感覺備不備份都沒差,當然生產環境中最好別偷懶.
可是為什么我們之前的第一種方式服務啟不來呢,下面的操作是我試圖再次用那種方式啟動:
[root@mysql-master mongo]# ps -ef | grep mongo
root???? 11590???? 1? 0 10:58 ???????? 00:00:01 /usr/bin/mongod -f /etc/mongod.conf
root???? 11618 11451? 0 11:26 pts/0??? 00:00:00 grep mongo
[root@mysql-master mongo]# kill -2 11590
[root@mysql-master mongo]# ps -ef | grep mongo
root???? 11621 11451? 0 11:26 pts/0??? 00:00:00 grep mongo
[root@mysql-master mongo]# /etc/init.d/mongod restart
Stopping mongod:?????????????????????????????????????????? [FAILED]
Starting mongod: all output going to: /var/log/mongo/mongod.log
forked process: 11639
?????????????????????????????????????????????????????????? [FAILED]
還是啟不來,我們來看看日志,看到底是什么原因
[root@mysql-master mongo]# vim /var/log/mongo/mongod.log
Thu Aug 16 11:27:10 [initandlisten] opening db:? test
Thu Aug 16 11:27:10 [initandlisten] couldn't open /var/lib/mongo/test.ns errno:13 Permission denied
Thu Aug 16 11:27:10 [initandlisten] error couldn't open file /var/lib/mongo/test.ns terminating
Thu Aug 16 11:27:10 dbexit:
Thu Aug 16 11:27:10 [initandlisten] shutdown: going to close listening sockets...
Thu Aug 16 11:27:10 [initandlisten] shutdown: going to flush diaglog...
Thu Aug 16 11:27:10 [initandlisten] shutdown: going to close sockets...
Thu Aug 16 11:27:10 [initandlisten] shutdown: waiting for fs preallocator...
Thu Aug 16 11:27:10 [initandlisten] shutdown: lock for final commit...
Thu Aug 16 11:27:10 [initandlisten] shutdown: final commit...
Thu Aug 16 11:27:10 [initandlisten] shutdown: closing all files...
Thu Aug 16 11:27:10 [initandlisten] closeAllFiles() finished
Thu Aug 16 11:27:10 [initandlisten] journalCleanup...
Thu Aug 16 11:27:10 [initandlisten] removeJournalFiles
Thu Aug 16 11:27:10 [initandlisten] flushing directory /var/lib/mongo/journal
Thu Aug 16 11:27:10 [initandlisten] removeJournalFiles end
Thu Aug 16 11:27:10 [initandlisten] shutdown: removing fs lock...
Thu Aug 16 11:27:10 dbexit: really exiting now
打開日志一看,很明顯的字眼映入眼簾:errno:13 Permission denied,這種錯誤信息太常見了!第一感覺當然是看數據庫的目錄權限咯:
[root@mysql-master mongo]# ls -l /var/lib/mongo/
total 852856
-rw------- 1 root?? root??? 67108864 Aug 14 23:21 admin.0
-rw------- 1 root?? root?? 134217728 Aug 14 23:28 admin.1
-rw------- 1 root?? root??? 16777216 Aug 14 23:21 admin.ns
drwxr-xr-x 2 mongod mongod????? 4096 Aug 16 11:34 journal
-rw------- 1 root?? root??? 67108864 Aug 15 00:36 jzf.0
-rw------- 1 root?? root?? 134217728 Aug 15 02:45 jzf.1
-rw------- 1 root?? root??? 16777216 Aug 15 00:36 jzf.ns
-rw------- 1 mongod mongod? 67108864 Aug 14 12:50 local.0
-rw------- 1 mongod mongod 134217728 Aug 14 18:50 local.1
-rw------- 1 mongod mongod? 16777216 Aug 14 12:50 local.ns
-rwxr-xr-x 1 mongod mongod???????? 0 Aug 16 11:34 mongod.lock
drwxr-xr-x 2 root?? root??????? 4096 Aug 15 02:35 test
-rw------- 1 root?? root??? 67108864 Aug 15 02:35 test.0
-rw------- 1 root?? root?? 134217728 Aug 15 02:45 test.1
-rw------- 1 root?? root??? 16777216 Aug 15 02:35 test.ns
看到這里,我想大家應該明白,為什么后面那種方法能正常啟動了.那么我們來改一下目錄權限,看看前面那種啟動方式能不能正常啟動服務:
[root@mysql-master mongo]# chown -R mongod. /var/lib/mongo/
[root@mysql-master mongo]# ls -l /var/lib/mongo/
total 852856
-rw------- 1 mongod mongod? 67108864 Aug 14 23:21 admin.0
-rw------- 1 mongod mongod 134217728 Aug 14 23:28 admin.1
-rw------- 1 mongod mongod? 16777216 Aug 14 23:21 admin.ns
drwxr-xr-x 2 mongod mongod????? 4096 Aug 16 11:34 journal
-rw------- 1 mongod mongod? 67108864 Aug 15 00:36 jzf.0
-rw------- 1 mongod mongod 134217728 Aug 15 02:45 jzf.1
-rw------- 1 mongod mongod? 16777216 Aug 15 00:36 jzf.ns
-rw------- 1 mongod mongod? 67108864 Aug 14 12:50 local.0
-rw------- 1 mongod mongod 134217728 Aug 14 18:50 local.1
-rw------- 1 mongod mongod? 16777216 Aug 14 12:50 local.ns
-rwxr-xr-x 1 mongod mongod???????? 0 Aug 16 11:34 mongod.lock
drwxr-xr-x 2 mongod mongod????? 4096 Aug 15 02:35 test
-rw------- 1 mongod mongod? 67108864 Aug 15 02:35 test.0
-rw------- 1 mongod mongod 134217728 Aug 15 02:45 test.1
-rw------- 1 mongod mongod? 16777216 Aug 15 02:35 test.ns
[root@mysql-master mongo]# /etc/init.d/mongod start
Starting mongod: forked process: 11703
all output going to: /var/log/mongo/mongod.log
child process started successfully, parent exiting
?????????????????????????????????????????????????????????? [? OK? ]
正常啟動了.那么這兩種方法倒底有什么不同的地方呢?我們來看一下mongod的啟動腳本
[root@mysql-master ~]# vim /etc/init.d/mongod
......
MONGO_USER=mongod
MONGO_GROUP=mongod
......
start()
{
? echo -n $"Starting mongod: "
? daemon --user "$MONGO_USER" $NUMACTL $mongod $OPTIONS
? RETVAL=$?
? echo
? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod
}
原來,mongod啟動腳本中服務啟動的用戶是mongod,而用后一種方法啟動用戶是root.那么服務啟不了,報權限被拒絕也是很正常的事啦.下面我們來分別看下: [root@mysql-master ~]# /etc/init.d/mongod start
[root@mysql-master ~]# ps -ef | grep mongo
mongod?? 11703???? 1? 0 11:49 ???????? 00:00:12 /usr/bin/mongod -f /etc/mongod.conf
root???? 11736 11451? 0 13:57 pts/0??? 00:00:00 mongo [root@mysql-master ~]# /usr/bin/mongod -f /etc/mongod.conf
[root@mysql-master ~]# ps -ef | grep mongo
root???? 11590???? 1? 0 10:58 ???????? 00:00:01 /usr/bin/mongod -f /etc/mongod.conf
[root@mysql-master ~]# ps -ef | grep mongo
root????? 3244???? 1? 0 Aug15 ???????? 00:00:37 /usr/bin/mongod -f /etc/mongod.conf
root???? 11480 11451? 0 10:18 pts/0??? 00:00:00 grep mongo
[root@mysql-master ~]# netstat -tpln | grep mongo
tcp??????? 0????? 0 0.0.0.0:27017?????????????? 0.0.0.0:*?????????????????? LISTEN????? 3244/mongod???
tcp??????? 0????? 0 0.0.0.0:28017?????????????? 0.0.0.0:*?????????????????? LISTEN????? 3244/mongod?
上面顯示我系統上的mongod服務是正常運行的,下面連上服務查看一下當前版本號及一些數據庫信息:
[root@mysql-master ~]# mongo
MongoDB shell version: 2.0.7
connecting to: test
> show dbs
admin?0.203125GB
jzf?0.203125GB
local?0.203125GB
test?0.203125GB
> exit
升級前一定要關掉服務,停服務我們可以直接在shell里面調用db.shutdownServer()函數.或者用下面這條命令:
/etc/init.d/mongod stop
Stopping mongod:?????????????????????????????????????????? [? OK? ]
服務器停掉后,我們可以將數據做一下備份.因為我這不是生產環境,這里就不做備份了.下面來升級MongoDB數據庫軟件
[root@mysql-master ~]# yum update -y mongo-10gen mongo-10gen-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
?* base: centos.ustc.edu.cn
?* extras: centos.ustc.edu.cn
?* updates: centos.ustc.edu.cn
Setting up Update Process
Resolving Dependencies
--> Running transaction check
---> Package mongo-10gen.x86_64 0:2.2.0-mongodb_1 set to be updated
---> Package mongo-10gen-server.x86_64 0:2.2.0-mongodb_1 set to be updated
--> Finished Dependency Resolution
......
Updated:
? mongo-10gen.x86_64 0:2.2.0-mongodb_1?????????? mongo-10gen-server.x86_64 0:2.2.0-mongodb_1????????? Complete!
升級完成后,我們來試著啟動下服務:
[root@mysql-master mongo]# /etc/init.d/mongod start
Starting mongod: all output going to: /var/log/mongo/mongod.log
forked process: 11577
?????????????????????????????????????????????????????????? [FAILED]
糟糕,服務啟不來,我們換下別的啟動方法.
[root@mysql-master mongo]# which mongod
/usr/bin/mongod
[root@mysql-master mongo]# /usr/bin/mongod -f /etc/mongod.conf
forked process: 11590
all output going to: /var/log/mongo/mongod.log
child process started successfully, parent exiting
我們來看一下,唉,這樣是能正常啟動的.
[root@mysql-master mongo]# ps -ef | grep mongo
root???? 11590???? 1? 2 10:58 ???????? 00:00:00 /usr/bin/mongod -f /etc/mongod.conf
root???? 11601 11451? 0 10:58 pts/0??? 00:00:00 grep mongo
既然服務啟動了,我們來看一下能不能連接:
[root@mysql-master mongo]# mongo
MongoDB shell version: 2.2.0
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
?http://docs.mongodb.org/
Questions? Try the support group
?http://groups.google.com/group/mongodb-user
> use admin
switched to db admin
> db.auth("root","redhat")
1
> show dbs
admin?0.203125GB
jzf?0.203125GB
local?0.203125GB
test?0.203125GB
> use jzf
switched to db jzf
> show collections
blog
food
myself
system.indexes
system.users
test
test.test
user
> db.food.find()
{ "_id" : 1, "fruit" : [ "apple", "banana", "peach", "strawberry" ] }
{ "_id" : 2, "fruit" : [ "apple", "orange", "peach", "strawberry" ] }
{ "_id" : 3, "fruit" : [ "cherry", "orange", "peach", "strawberry" ] }
{ "_id" : 4, "fruit" : [ "cherry", "orange", "kumquat", "strawberry" ] }
> exit
bye
由上面可以看出,服務器版本上升了(原來的2.0.7升到了2.2.0).而且原來的數據都在!突然感覺備不備份都沒差,當然生產環境中最好別偷懶.
可是為什么我們之前的第一種方式服務啟不來呢,下面的操作是我試圖再次用那種方式啟動:
[root@mysql-master mongo]# ps -ef | grep mongo
root???? 11590???? 1? 0 10:58 ???????? 00:00:01 /usr/bin/mongod -f /etc/mongod.conf
root???? 11618 11451? 0 11:26 pts/0??? 00:00:00 grep mongo
[root@mysql-master mongo]# kill -2 11590
[root@mysql-master mongo]# ps -ef | grep mongo
root???? 11621 11451? 0 11:26 pts/0??? 00:00:00 grep mongo
[root@mysql-master mongo]# /etc/init.d/mongod restart
Stopping mongod:?????????????????????????????????????????? [FAILED]
Starting mongod: all output going to: /var/log/mongo/mongod.log
forked process: 11639
?????????????????????????????????????????????????????????? [FAILED]
還是啟不來,我們來看看日志,看到底是什么原因
[root@mysql-master mongo]# vim /var/log/mongo/mongod.log
Thu Aug 16 11:27:10 [initandlisten] opening db:? test
Thu Aug 16 11:27:10 [initandlisten] couldn't open /var/lib/mongo/test.ns errno:13 Permission denied
Thu Aug 16 11:27:10 [initandlisten] error couldn't open file /var/lib/mongo/test.ns terminating
Thu Aug 16 11:27:10 dbexit:
Thu Aug 16 11:27:10 [initandlisten] shutdown: going to close listening sockets...
Thu Aug 16 11:27:10 [initandlisten] shutdown: going to flush diaglog...
Thu Aug 16 11:27:10 [initandlisten] shutdown: going to close sockets...
Thu Aug 16 11:27:10 [initandlisten] shutdown: waiting for fs preallocator...
Thu Aug 16 11:27:10 [initandlisten] shutdown: lock for final commit...
Thu Aug 16 11:27:10 [initandlisten] shutdown: final commit...
Thu Aug 16 11:27:10 [initandlisten] shutdown: closing all files...
Thu Aug 16 11:27:10 [initandlisten] closeAllFiles() finished
Thu Aug 16 11:27:10 [initandlisten] journalCleanup...
Thu Aug 16 11:27:10 [initandlisten] removeJournalFiles
Thu Aug 16 11:27:10 [initandlisten] flushing directory /var/lib/mongo/journal
Thu Aug 16 11:27:10 [initandlisten] removeJournalFiles end
Thu Aug 16 11:27:10 [initandlisten] shutdown: removing fs lock...
Thu Aug 16 11:27:10 dbexit: really exiting now
打開日志一看,很明顯的字眼映入眼簾:errno:13 Permission denied,這種錯誤信息太常見了!第一感覺當然是看數據庫的目錄權限咯:
[root@mysql-master mongo]# ls -l /var/lib/mongo/
total 852856
-rw------- 1 root?? root??? 67108864 Aug 14 23:21 admin.0
-rw------- 1 root?? root?? 134217728 Aug 14 23:28 admin.1
-rw------- 1 root?? root??? 16777216 Aug 14 23:21 admin.ns
drwxr-xr-x 2 mongod mongod????? 4096 Aug 16 11:34 journal
-rw------- 1 root?? root??? 67108864 Aug 15 00:36 jzf.0
-rw------- 1 root?? root?? 134217728 Aug 15 02:45 jzf.1
-rw------- 1 root?? root??? 16777216 Aug 15 00:36 jzf.ns
-rw------- 1 mongod mongod? 67108864 Aug 14 12:50 local.0
-rw------- 1 mongod mongod 134217728 Aug 14 18:50 local.1
-rw------- 1 mongod mongod? 16777216 Aug 14 12:50 local.ns
-rwxr-xr-x 1 mongod mongod???????? 0 Aug 16 11:34 mongod.lock
drwxr-xr-x 2 root?? root??????? 4096 Aug 15 02:35 test
-rw------- 1 root?? root??? 67108864 Aug 15 02:35 test.0
-rw------- 1 root?? root?? 134217728 Aug 15 02:45 test.1
-rw------- 1 root?? root??? 16777216 Aug 15 02:35 test.ns
看到這里,我想大家應該明白,為什么后面那種方法能正常啟動了.那么我們來改一下目錄權限,看看前面那種啟動方式能不能正常啟動服務:
[root@mysql-master mongo]# chown -R mongod. /var/lib/mongo/
[root@mysql-master mongo]# ls -l /var/lib/mongo/
total 852856
-rw------- 1 mongod mongod? 67108864 Aug 14 23:21 admin.0
-rw------- 1 mongod mongod 134217728 Aug 14 23:28 admin.1
-rw------- 1 mongod mongod? 16777216 Aug 14 23:21 admin.ns
drwxr-xr-x 2 mongod mongod????? 4096 Aug 16 11:34 journal
-rw------- 1 mongod mongod? 67108864 Aug 15 00:36 jzf.0
-rw------- 1 mongod mongod 134217728 Aug 15 02:45 jzf.1
-rw------- 1 mongod mongod? 16777216 Aug 15 00:36 jzf.ns
-rw------- 1 mongod mongod? 67108864 Aug 14 12:50 local.0
-rw------- 1 mongod mongod 134217728 Aug 14 18:50 local.1
-rw------- 1 mongod mongod? 16777216 Aug 14 12:50 local.ns
-rwxr-xr-x 1 mongod mongod???????? 0 Aug 16 11:34 mongod.lock
drwxr-xr-x 2 mongod mongod????? 4096 Aug 15 02:35 test
-rw------- 1 mongod mongod? 67108864 Aug 15 02:35 test.0
-rw------- 1 mongod mongod 134217728 Aug 15 02:45 test.1
-rw------- 1 mongod mongod? 16777216 Aug 15 02:35 test.ns
[root@mysql-master mongo]# /etc/init.d/mongod start
Starting mongod: forked process: 11703
all output going to: /var/log/mongo/mongod.log
child process started successfully, parent exiting
?????????????????????????????????????????????????????????? [? OK? ]
正常啟動了.那么這兩種方法倒底有什么不同的地方呢?我們來看一下mongod的啟動腳本
[root@mysql-master ~]# vim /etc/init.d/mongod
......
MONGO_USER=mongod
MONGO_GROUP=mongod
......
start()
{
? echo -n $"Starting mongod: "
? daemon --user "$MONGO_USER" $NUMACTL $mongod $OPTIONS
? RETVAL=$?
? echo
? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod
}
原來,mongod啟動腳本中服務啟動的用戶是mongod,而用后一種方法啟動用戶是root.那么服務啟不了,報權限被拒絕也是很正常的事啦.下面我們來分別看下: [root@mysql-master ~]# /etc/init.d/mongod start
[root@mysql-master ~]# ps -ef | grep mongo
mongod?? 11703???? 1? 0 11:49 ???????? 00:00:12 /usr/bin/mongod -f /etc/mongod.conf
root???? 11736 11451? 0 13:57 pts/0??? 00:00:00 mongo [root@mysql-master ~]# /usr/bin/mongod -f /etc/mongod.conf
[root@mysql-master ~]# ps -ef | grep mongo
root???? 11590???? 1? 0 10:58 ???????? 00:00:01 /usr/bin/mongod -f /etc/mongod.conf
轉載于:https://blog.51cto.com/jzfjeff/987291
總結
以上是生活随笔為你收集整理的CentOS下MongoDB的升级的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 不同分词器的结果
- 下一篇: ubuntu12.04中sublime输