摘要: 开发环境:System:WindowsIDE:eclipse、MyEclipse 8Database:mongoDB开发依赖库:JavaEE5、mongo-2.5.3.jar、junit-4.8.2.jarEmail:hoojo_@126.comBlog:http://blog.csdn.net/IBM_hoojohttp://hoojo.cnblogs.com/ 一、准备工作1、 首先...  阅读全文
posted @ 2012-08-06 13:34 小马歌 阅读(2462) | 评论 (1)编辑 收藏
 

版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
原文地址:http://helenfj.blogbus.com/logs/60894038.html

时间以及时区设置
首先确认使用utc还是local time. 
UTC(Universal Time Coordinated)=GMT(Greenwich Mean Time) 
Local time 是你手表上的时间

传统的POSIX计算机(Solaris,bsd,unix)使用UTC格式 
linux可以处理UTC时间和蹩脚的Windows所使用的local time

到底是使用UTC还是local time可以这样来确定: 
如果机器上同时安装有Linux和Windows,建议使用local time 
如果机器上只安装有Linux,建议使用utc 
确定后编辑/etc/sysconfig/clock, UTC=0 是local time; UTC=1 是UTC(GMT)

1) 使用cat /etc/sysconfig/clock查看当前时区 
linux5:~ # cat /etc/sysconfig/clock
## Path:                System/Environment/Clock
## Description:         Information about your timezone and time
## Type:                string
## ServiceRestart:      boot.clock
#
# Set to "-u" if your system clock is set to UTC, and to "--localtime"
# if your clock runs that way.
#
HWCLOCK="-u"

## Type:                string(Europe/Berlin,Europe/London,Europe/Paris)
## ServiceRestart:      boot.clock
#
# Timezone (e.g. CET)
# (this will set /usr/lib/zoneinfo/localtime)
#
TIMEZONE="US/Pacific"
DEFAULT_TIMEZONE="US/Pacific"
linux5:~ #

2) 使用tzselect设置时区,最后结果如下

You can make this change permanent for yourself by appending the line
        TZ='Asia/Shanghai'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Asia/Shanghai
linux5:~ #

3) 复制相应的时区文件,替换系统默认时区 
linux5:~ # cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
linux5:~ #

4) 将当前时间写入BIOS永久生效(避免重启后失效) 
linux5:~ # hwclock
Tue Jan 29 18:22:59 2008  -0.565688 seconds
linux5:~ #

10. 配置ntp客户端
编辑/etc/ntp.conf,增加一行server 10.30.1.10,其中10.30.1.105就是时钟服务器,如下
linux:/var/log # grep -v \# /etc/ntp.conf

server 10.30.1.105

查看ntp服务的状态
linux:/var/log # /etc/init.d/xntpd  status
Checking for network time protocol daemon (NTPD):                    unused

设置时区以及时间
/usr/sbin/zic -l PRC
/bin/date "+%H:%M:%S - %d-%m-%Y"

写回硬件时钟
/sbin/hwclock --hctosys --localtime
或者写回硬件时钟: hwclock --systohc

在/etc/rc.d/rc5.d创建xntp服务的启动脚本
linux:/etc/rc.d/rc5.d # ln -s ../xntpd S14xntpd
查看ntp时间调整纪录
linux:/var/log # grep ntp messages
Aug 14 07:19:51 linux ntpdate[2837]: step time server 10.30.1.105 offset 2.010174 sec
Aug 14 07:19:51 linux ntpd[2884]: ntpd 4.2.0a@1.1213-r Wed Jun 30 18:37:03 UTC 2004 (1)
Aug 14 07:19:51 linux ntpd[2884]: precision = 1.000 usec
Aug 14 07:19:51 linux ntpd[2884]: Listening on interface wildcard, 0.0.0.0#123
Aug 14 07:19:51 linux ntpd[2884]: Listening on interface wildcard, ::#123
Aug 14 07:19:51 linux ntpd[2884]: Listening on interface lo, 127.0.0.1#123
Aug 14 07:19:51 linux ntpd[2884]: Listening on interface eth0, 10.40.157.66#123
Aug 14 07:19:51 linux ntpd[2884]: kernel time sync status 0040

mmscbill:~ # date
Wed May  7 15:53:10 CST 2008
这里时区设置没有错. PRC是时区的名称,它对应/usr/share/lib/zoneinfo下的PRC时区文件.
CST是Chinese Standard Time的缩写,用在date命令的输出中.它是定义在PRC时区文件中.看
一下/usr/share/lib/zoneinfo/src下的asia文件就知道是怎么回事了.

修改系统时间(bjchenxu,laixi781211,hutuworm)
date -s “2003-04-14 cst”,cst指时区,时间设定用date -s 18:10
修改后执行clock -w 写到CMOS
hwclock --systohc
set the hardware clock to the current system time

posted @ 2012-07-23 10:22 小马歌 阅读(737) | 评论 (0)编辑 收藏
 

MongoDB的源代码依赖了一些基础组件,如js引擎Spider Monkey,正则表达式引擎PCRE,安装构建工具Scons,以及C++的boost库等

1、准备

wget http://downloads.mongodb.org/src/mongodb-src-r1.8.2.tar.gz
wget http://sourceforge.net/projects/scons/files/scons/2.1.0.alpha.20101125/scons-2.1.0.alpha.20101125.tar.gz/download
wget http://ftp.mozilla.org/pub/mozilla.org/js/js-1.7.0.tar.gz
wget http://sourceforge.net/projects/pcre/files/pcre/7.4/pcre-7.4.tar.gz/download
wget http://downloads.sourceforge.net/project/boost/boost/1.42.0/boost_1_42_0.tar.gz?use_mirror=cdnetworks-kr-1

2、scons编译安装

tar zxvf scons-2.1.0.alpha.20101125.tar.gz
cd scons-2.1.0.alpha.20101125
python setup.py install

3、pcre编译安装

tar zxvf pcre-7.4.tar.gz
cd pcre-7.4
configure --enable-unicode-properties
make -j 2 && make install

configure中要加入--enable-unicode-properties支持,要不运行mongod会出现下面错误

Fri Dec 30 23:53:45 Assertion: 10342:pcre not compiled with utf8 support
0x53f16a 0x5cfda1 0x8945f3 0x338101d994 0x4c0e49
/usr/local/mongodb/bin/mongod(_ZN5mongo11msgassertedEiPKc+0x12a) [0x53f16a]
/usr/local/mongodb/bin/mongod(_ZN5mongo6RXTest3runEv+0x3b1) [0x5cfda1]
/usr/local/mongodb/bin/mongod(main+0x5c73) [0x8945f3]
/lib64/libc.so.6(__libc_start_main+0xf4) [0x338101d994]
/usr/local/mongodb/bin/mongod(__gxx_personality_v0+0x451) [0x4c0e49]

4、js编译安装

tar zxvf js-1.7.0.tar.gz
cd js/src
export CFLAGS="-DJS_C_STRINGS_ARE_UTF8"
make -f Makefile.ref
JS_DIST=/usr make -f Makefile.ref export

5、boost编译安装

tar -zxvf boost_1_42_0.tar.gz
cd boost_1_42_0/
#使用下面的命令创建boost自己的编译工具bjam(目的是保证Boost在任何平台上都能用bjam编译),类似于GNU Make。
./bootstrap.sh
#会安装头文件和库文件到相应指定目录,头文件安装到/usr/local/include下,库文件安装到/usr/local/lib下
install
#最后执行的创建命令:
./bjam –without-python –layout=tagged variant=debug,release link=static,shared runtime-link=shared threading=multi stage

6、mongodb编译安装

tar -xzvf mongodb-src-r1.8.2.tar.tar
cd mongodb-src-r1.8.2/
scons all
scons --prefix=/usr/local/mongodb --full install

安装成功后 安装到/usr/local/mongodb下

文件结果

bin
GNU-AGPL-3.0
include
lib64
README
THIRD-PARTY-NOTICES

7、加入环境变量

/etc/profile 加入

CLASSPATH=.:/usr/local/lib
export CLASSPATH

然后source /etc/profile

完成后就可以运行mongodb。

[root@test_192.168.4.95 mongodb]# bin/mongo
MongoDB shell version: 1.8.2
connecting to: test

运行可能会出现下面错误

/usr/local/mongodb/bin/mongod: error while loading shared libraries: libboost_system.so.1.42.0: cannot open shared object file: No such file or directory

解决方法

echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig

posted @ 2012-07-18 15:20 小马歌 阅读(2079) | 评论 (0)编辑 收藏
 
     摘要: 我们有项目用到了MongoDB,在正式运营时数据需要做实时备份,而目前资源也有限,只有两台机器用于MongoDB,所以选用MongoDB的Master-Slave Replication来实现实时备份,其实我是比较看好Replica Sets的,因为其可以实现自动切换,但我目前因为机器少只能做罢。两台机器一台为Master(192.168.1.173),一台为Slave(192.168.1.174...  阅读全文
posted @ 2012-07-18 12:52 小马歌 阅读(536) | 评论 (0)编辑 收藏
 

mongodb的Replication是通过一个日志来存储写操作的,这个日志就叫做Oplog。

在默认情况下,对于64位的mongodb,oplogs都相当大-可能是5%的磁盘空间。通常而言,这是一种合理的设置。可以通过mongod --oplogSize来改变Oplog的日志大小。

 

Oplog的collectio为:

local.oplog.$main for master/slave replication;

local.oplog.rs for replica sets

如 master/slave replication:

> use local               
switched to db local
> db.oplog.$main.help()
DBCollection help
        db.oplog.$main.find().help() - show DBCursor help
        db.oplog.$main.count()
        db.oplog.$main.dataSize()
        db.oplog.$main.distinct( key ) - eg. db.oplog.$main.distinct( 'x' )
        db.oplog.$main.drop() drop the collection
        db.oplog.$main.dropIndex(name)
        db.oplog.$main.dropIndexes()
        db.oplog.$main.ensureIndex(keypattern,options) - options should be an object with these possible fields: name, unique, dropDups
        db.oplog.$main.reIndex()
        db.oplog.$main.find( [query] , [fields]) - first parameter is an optional query filter. second parameter is optional set of fields to return.
                                           e.g. db.oplog.$main.find( { x : 77 } , { name : 1 , x : 1 } )
        db.oplog.$main.find(...).count()
        db.oplog.$main.find(...).limit(n)
        db.oplog.$main.find(...).skip(n)
        db.oplog.$main.find(...).sort(...)
        db.oplog.$main.findOne([query])
        db.oplog.$main.findAndModify( { update : ... , remove : bool [, query: {}, sort: {}, 'new': false] } )
        db.oplog.$main.getDB() get DB object associated with collection
        db.oplog.$main.getIndexes()
        db.oplog.$main.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )
        db.oplog.$main.mapReduce( mapFunction , reduceFunction , <optional params> )
        db.oplog.$main.remove(query)
        db.oplog.$main.renameCollection( newName , <dropTarget> ) renames the collection.
        db.oplog.$main.runCommand( name , <options> ) runs a db command with the given name where the first param is the collection name
        db.oplog.$main.save(obj)
        db.oplog.$main.stats()
        db.oplog.$main.storageSize() - includes free space allocated to this collection
        db.oplog.$main.totalIndexSize() - size in bytes of all the indexes
        db.oplog.$main.totalSize() - storage allocated for all data and indexes
        db.oplog.$main.update(query, object[, upsert_bool, multi_bool])
        db.oplog.$main.validate() - SLOW
        db.oplog.$main.getShardVersion() - only for use with sharding
> db.oplog.$main.find()
{ "ts" : { "t" : 1294582140000, "i" : 14 }, "op" : "d", "ns" : "mixi_top_city.building_90", "b" : true, "o" : { "_id" : "6380690_441_30_29" } }
{ "ts" : { "t" : 1294582140000, "i" : 15 }, "op" : "i", "ns" : "mixi_top_city.building_90", "o" : { "_id" : "6380690_441_24_24", "uid" : "6380690", "x" : 24, "y" : 24, "pos" : 1, "btime" : 1294154452, "ntime" : 1294154452, "bid" : 71, "extprop" : 0, "status" : 0, "ucid" : 441 } }
{ "ts" : { "t" : 1294582140000, "i" : 16 }, "op" : "u", "ns" : "mixi_top_city.building_64", "o2" : { "_id" : "16702364_459_14_14" }, "o" : { "$set" : { "status" : 1 } } }
{ "ts" : { "t" : 1294582140000, "i" : 17 }, "op" : "u", "ns" : "mixi_top_city.building_08", "o2" : { "_id" : "6223408_391_30_28" }, "o" : { "$set" : { "ntime" : 1294582321 } } }
{ "ts" : { "t" : 1294582140000, "i" : 18 }, "op" : "u", "ns" : "mixi_top_city.building_03", "o2" : { "_id" : "9882403_353_28_20" }, "o" : { "$set" : { "ntime" : 1294600141 } } }
{ "ts" : { "t" : 1294582140000, "i" : 19 }, "op" : "u", "ns" : "mixi_top_city.building_24", "o2" : { "_id" : "4162924_365_32_28" }, "o" : { "$set" : { "ntime" : 1294582321 } } }
{ "ts" : { "t" : 1294582141000, "i" : 1 }, "op" : "u", "ns" : "mixi_top_city.building_49", "o2" : { "_id" : "32797749_285_28_30" }, "o" : { "$set" : { "ntime" : 1294583341 } } }
{ "ts" : { "t" : 1294582141000, "i" : 2 }, "op" : "u", "ns" : "mixi_top_city.building_50", "o2" : { "_id" : "33768850_425_28_32" }, "o" : { "$set" : { "ntime" : 1294582561 } } }
{ "ts" : { "t" : 1294582141000, "i" : 3 }, "op" : "u", "ns" : "mixi_top_city.building_35", "o2" : { "_id" : "28235635_333_28_36" }, "o" : { "$set" : { "ntime" : 1294582741 } } }
{ "ts" : { "t" : 1294582141000, "i" : 4 }, "op" : "u", "ns" : "mixi_top_city.building_04", "o2" : { "_id" : "25178304_3_32_28" }, "o" : { "$set" : { "ntime" : 1294594141 } } }
{ "ts" : { "t" : 1294582141000, "i" : 5 }, "op" : "u", "ns" : "mixi_top_city.building_18", "o2" : { "_id" : "7304918_445_32_26" }, "o" : { "$set" : { "ntime" : 1294582321 } } }
{ "ts" : { "t" : 1294582141000, "i" : 6 }, "op" : "u", "ns" : "mixi_top_city.building_93", "o2" : { "_id" : "5003293_453_20_24" }, "o" : { "$set" : { "status" : 1 } } }
{ "ts" : { "t" : 1294582141000, "i" : 7 }, "op" : "u", "ns" : "mixi_top_city.building_59", "o2" : { "_id" : "19601459_485_28_30" }, "o" : { "$set" : { "ntime" : 1294582741 } } }
{ "ts" : { "t" : 1294582141000, "i" : 8 }, "op" : "u", "ns" : "mixi_top_city.building_47", "o2" : { "_id" : "23744647_273_22_46" }, "o" : { "$set" : { "ntime" : 1294582741 } } }
{ "ts" : { "t" : 1294582141000, "i" : 9 }, "op" : "u", "ns" : "mixi_top_city.building_50", "o2" : { "_id" : "3549050_451_20_30" }, "o" : { "$set" : { "ntime" : 1294583041 } } }
{ "ts" : { "t" : 1294582141000, "i" : 10 }, "op" : "d", "ns" : "mixi_top_city.building_77", "b" : true, "o" : { "_id" : "8577977_215_44_38" } }
{ "ts" : { "t" : 1294582141000, "i" : 11 }, "op" : "i", "ns" : "mixi_top_city.building_77", "o" : { "_id" : "8577977_215_44_38", "uid" : "8577977", "x" : 44, "y" : 38, "pos" : 1, "btime" : 1293955498, "ntime" : 1294486420, "bid" : 18, "extprop" : 0, "status" : 0, "ucid" : 215 } }
{ "ts" : { "t" : 1294582141000, "i" : 12 }, "op" : "u", "ns" : "mixi_top_city.building_89", "o2" : { "_id" : "21405489_541_20_24" }, "o" : { "$set" : { "status" : 1 } } }
{ "ts" : { "t" : 1294582141000, "i" : 13 }, "op" : "u", "ns" : "mixi_top_city.building_60", "o2" : { "_id" : "6479060_395_16_32" }, "o" : { "$set" : { "ntime" : 1294582321 } } }
{ "ts" : { "t" : 1294582141000, "i" : 14 }, "op" : "u", "ns" : "mixi_top_city.building_38", "o2" : { "_id" : "12696438_1037_28_40" }, "o" : { "$set" : { "ntime" : 1294583042 } } }
has more
>

Oplog日志中:

ts:Timestamp 这个操作的时间戳

op:operation 操作

i – insert
d – delete
u – update
c – command
n – no-op

ns:Namespace也就是操作的collection name

o:Document

 

查看master的Oplog信息:

[root@tc-03 cacti]# mongo
MongoDB shell version: 1.6.4
connecting to: test
> db.printReplicationInfo();
configured oplog size:   7503.049113600001MB
log length start to end: 3566227secs (990.62hrs)
oplog first event time:  Tue Jan 11 2011 12:17:03 GMT+0900 (KST)
oplog last event time:   Mon Feb 21 2011 18:54:10 GMT+0900 (KST)
now:                     Mon Feb 21 2011 18:54:10 GMT+0900 (KST)

 

查看slave的同步状态:

> db.printSlaveReplicationInfo()
source:   192.168.8.173
         syncedTo: Mon Feb 21 2011 18:55:19 GMT+0900 (KST)
                 = 31secs ago (0.01hrs)

posted @ 2012-07-18 12:52 小马歌 阅读(1770) | 评论 (0)编辑 收藏
 

一、安装PCRE库
PCRE(Perl Compatible Regular Expressions),提供高速的正则表达式匹配api。

yum install pcre-devel

或者到ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/下载合适的pcre源码包,然后configure/make/make install

二、安装Spider Monkey库
SpiderMonkey是JavaScript的C实现,可以提供JavaScript的代码解释功能。
到ftp://ftp.mozilla.org/pub/mozilla.org/js/下载js压缩包,解压后进入src目录,并按照如下步骤进行编译安装:

export CFLAGS=”-DJS_C_STRINGS_ARE_UTF8″  make -f Makefile.ref JS_DIST=/usr make -f Makefile.ref export

三、安装SCons
Scons是一个Python写的自动化构建工具,比传统的GNU make更加简便、可靠以及高效。
到http://sourceforge.net/projects/scons/files/scons/下载源码压缩包,解压之后按照如下步骤进行安装:

python setup.py install

四、安装MongoDB
先到http://www.mongodb.org/downloads/下载想要的MongoDB版本。建议下载1.6以上,有很多架构和功能方面的改进。
解压缩之后按照如下步骤进行安装:

scons all scons –prefix=/usr/local/mongodb install

如果想要头文件和lib包,执行

scons –prefix=/usr/local/mongodb –full install

五,让MongoDB跑起来
虽然MongoDB支持在命令行里面添加所有参数,但是为了管理方便,还是应该添加一个配置文件的。然后在命令行里面指定配置文件的位置。
下面是一个简单的配置文件:

vim /usr/local/mongodb/config/mongodb
#Directory and relavent set dbpath = /usr/local/mongodb/data logpath = /usr/local/mongodb/log/mongodb.log repairpath = /usr/local/mongodb/repair pidfilepath = /usr/local/mongodb/mongodb.pid directoryperdb = true #sysinfo = true #verbose = true logappend = true #cpu = true #Network and security set noauth = true port = 8888 maxConns = 1024 fork = true #Management #nohttpinterface = true rest = true quota = true quotaFiles = 1024 nssize = 16 #syncdelay = 5

值得注意的是,类似 nohttpinterface = false 的配置是无效的。因为这些选项默认为false,不需要配置。

运行MongDB:

mongod –config /usr/local/mongodb/config/mongodb

启动脚本 mongodb-start.sh

#!/bin/sh /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/config/mongodb ## --upgrade \ ##runs a database upgrade option if needed \

关闭脚本 mongodb-stop.sh

#!/bin/bash pid=`ps -o pid,command ax | grep mongod | awk '!/awk/ && !/grep/ {print $1}'`; if [ "${pid}" != "" ]; then kill -2 ${pid}; fi

六,做服务

启动脚本init-rpm.sh

#! /bin/sh # # mongodb – this script starts and stops the mongodb daemon # # chkconfig: - 85 15 # description: MongoDB is a non-relational database storage system. # processname: mongodb # config: /opt/config/mongodb # pidfile: /opt/mongodb/mongo.pid PATH=/opt/mongodb/bin:/sbin:/bin:/usr/sbin:/usr/bin NAME=mongodb test -x $DAEMON || exit 0 set -e case "$1" in start) echo -n "Starting MongoDB... " su - mongodb -c "/opt/bin/mongodb-start" ;; stop) echo -n "Stopping MongoDB" /opt/bin/mongodb-stop ;; *) N=/etc/init.d/$NAME echo "Usage: $N {start|stop}" >&2 exit 1 ;; esac exit 0

把以上启动脚本做成服务

#mv init-rpm.sh /etc/init.d/mongodb #chmod +x /etc/init.d/mongodb #chkconfig --add mongodb #chkconfig -–level 345 mongodb on

 

MongoDB与sql语句对照表

SQL Statement  Mongo Query Language Statement 
CREATE TABLE USERS (a Number, b Number)
implicit; can be done explicitly
INSERT INTO USERS VALUES(1,1)
db.users.insert({a:1,b:1})
SELECT a,b FROM users
db.users.find({}, {a:1,b:1})
SELECT * FROM users
db.users.find()
SELECT * FROM users WHERE age=33
db.users.find({age:33})
SELECT a,b FROM users WHERE age=33
db.users.find({age:33}, {a:1,b:1})
SELECT * FROM users WHERE age=33 ORDER BY name
db.users.find({age:33}).sort({name:1})
SELECT * FROM users WHERE age>33
db.users.find({'age':{$gt:33}})})
SELECT * FROM users WHERE age<33
db.users.find({'age':{$lt:33}})})
SELECT * FROM users WHERE name LIKE "%Joe%"
db.users.find({name:/Joe/})
SELECT * FROM users WHERE name LIKE "Joe%"
db.users.find({name:/^Joe/})
SELECT * FROM users WHERE age>33 AND age<=40
db.users.find({'age':{$gt:33,$lte:40}})})
SELECT * FROM users ORDER BY name DESC
db.users.find().sort({name:-1})
CREATE INDEX idx_name ON users(name)
db.users.ensureIndex({name:1})
CREATE INDEX idx_name ON users(name,ts DESC)
db.users.ensureIndex({name:1,ts:-1})
SELECT * FROM users WHERE a=1 and b='q'
db.users.find({a:1,b:'q'})
SELECT * FROM users LIMIT 10 SKIP 20
db.users.find().limit(10).skip(20)
SELECT * FROM users WHERE a=1 or b=2
db.users.find( { $or : [ { a : 1 } , { b : 2 } ] } )
SELECT * FROM users LIMIT 1
db.users.findOne()
EXPLAIN SELECT * FROM users WHERE z=3
db.users.find({z:3}).explain()
SELECT DISTINCT last_name FROM users
db.users.distinct('last_name')
SELECT COUNT(*y) FROM users
db.users.count()
SELECT COUNT(*y) FROM users where AGE > 30
db.users.find({age: {'$gt': 30}}).count()
SELECT COUNT(AGE) from users
db.users.find({age: {'$exists': true}}).count()
UPDATE users SET a=1 WHERE b='q'
db.users.update({b:'q'}, {$set:{a:1}}, false, true)
UPDATE users SET a=a+2 WHERE b='q'
db.users.update({b:'q'}, {$inc:{a:2}}, false, true)
DELETE FROM users WHERE z="abc"
db.users.remove({z:'abc'});
posted @ 2012-07-18 11:43 小马歌 阅读(2268) | 评论 (0)编辑 收藏
 

mongod每天要产生大量的日志,如果不去管它,我这边一周大约有10~20G的日志出来,可见日志轮询是必须的。

mongodb本身支持日志轮询的信号,所以我的日志轮询脚本如下:

#!/bin/sh

log_dir="/var/log/mongo/"
killall -SIGUSR1 mongod
/usr/bin/find ${log_dir} -name 'mongod.log.*' -mtime +5  -exec rm -f {} \;

然后每天零点零分跑一下。

我有6台mongodb,上面的脚本跑了一两个月一直挺正常。但是最近其中一台在做日志轮询的时候可能是产生了死锁,因为我首先收到了读写锁过多的报警,日志轮询没有成功,客户端也连不进去。收到报警后就连到服务器去看,查查日志,确定问题后重启mongodb就正常了。

这个脚本造成服务中断14分钟,mongodb用的是最新的稳定版本1.8.1,mongodb的稳定性还有待提高。

 

发生这个问题之后,上面的脚本就不敢再用了,对脚本进行了更改:

#!/bin/sh

log_dir="/var/log/mongo/"
date=`date +%Y-%m-%d`


cat ${log_dir}/mongod.log >> ${log_dir}/mongod.log.${date}
cat /dev/null > ${log_dir}/mongod.log


/usr/bin/find ${log_dir} -name 'mongod.log.*' -mtime +5  -exec rm -f {} \;

然后让他一小时跑一次,目前看还行,就是要多占一点磁盘IO,但是稳定第一,可以确保不会出现上面的问题了。

posted @ 2012-07-18 10:58 小马歌 阅读(755) | 评论 (0)编辑 收藏
 

Redmine是一个基于web的项目管理软件,用Ruby开发。它通过“项目(Project)”的形式把成员、任务(问题)、文档、讨论以及各种形式的资源组织在一起,大家参与更新任务、文档等内容来推动项目的进度,同时系统利用时间线索(Timeline)和各种动态的报表(Report)形式来自动给成员汇报项目进度。

       Redmine功能可以说是非常强大了:

  ● 多项目和子项目支持

  ● 里程碑版本跟踪

  ● 可配置的用户角色控制

  ● 可配置的问题追踪系统

  ● 自动日历和甘特图绘制

  ● 支持 Blog 形式的新闻发布、Wiki 形式的文档撰写和文件管理

  ● RSS 输出和邮件通知

  ● 每个项目可以配置独立的 Wiki 和论坛模块

  ● 简单的任务时间跟踪机制

  ● 用户、项目、问题支持自定义属性

  ● 支持多种版本控制系统的绑定(SVN、CVS、Git、Mercurial 和 Darcs)

  ● 支持多 LDAP 用户认证

  ● 支持用户自注册和用户激活

  ● 多语言支持(已经内置了zh简体中文)

  ● 多数据库支持(MySQL、SQLite、PostgreSQL)

  ● 外观模版化定制(可以使用 Basecamp 、Ruby安装)

 

下面介绍一下在Centos 5.5下的安装,以及和nginx结合的问题。

 

1. 先安装一些相关库

yum groupinstall "Development Tools"
yum install zlib-devel wget openssl-devel pcre pcre-devel make gcc gcc-c++ curl-devel

 

2. 既然是ruby写的,ruby总是要安装的了,ruby最新的是1.9.x版了,但是最新的redmine 1.1版也只是支持ruby1.8版,所以要安装ruby 1.8.x
wget ftp://ftp.ruby-lang.org//pub/ruby/ruby-1.8.7-p334.tar.gz
tar -xvzf ruby-1.8.7-p334.tar.gz
cd ruby-1.8.7-p334

./configure
make -j3
make install

 

3. 安装rubygems,这个东东应该类似perl的module了,我是这么理解的。

wget http://production.cf.rubygems.org/rubygems/rubygems-1.5.1.tgz
tar -zxvf rubygems-1.5.1.tgz
cd rubygems-1.5.1/
ruby setup.rb

 

4. 用gem安装一些redmine运行所需的库
gem install rails
gem update --system
gem install rake rack
gem install i18n
gem install RedCloth
gem install fastthread --no-rdoc --no-ri
gem install mysql --no-rdoc --no-ri -- --with-mysql-dir=/usr/bin --with-mysql-lib=/usr/lib/mysql --with-mysql-include=/usr/include/mysql

 

5. 安装passenger,passenger是apache或nginx的一个模块,可以理解为用于apache或nginx和rails的交互的一个proxy。
gem install passenger
passenger-install-nginx-module

 

6. 下载redmine

svn co http://redmine.rubyforge.org/svn/branches/1.1-stable redmine-1.1
cp -rf redmine-1.1 /home/httpd/redmine

 

7. 建立数据库,我是用的mysql,redmine还支持其它的数据库。
mysql -h192.168.1.24 -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 169105
Server version: 5.0.77 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> create database redmine character set utf8;
Query OK, 1 row affected (0.03 sec)

mysql> quit
Bye

8. 配置redmine
cd /home/httpd/redmine/
cp database.yml.example database.yml

修改配置文件:
vi database.yml

production:
  adapter: mysql
  database: redmine
  host: 192.168.1.24
  username: root
  password: password
  encoding: utf8
 

然后跑下:

cd ..

rake generate_session_store
rake db:migrate RAILS_ENV="production"

如果提示哪些东西的版本不对,就安装哪些:

gem install -v=0.4.2 i18n
gem install -v=2.3.5 rails

然后再跑:
RAILS_ENV=production rake db:migrate


如果提示:
rake aborted!
undefined local variable or method `version_requirements' for #<Rails::GemDependency:0x7f1bdb0f24d8>

就:
vi /home/httpd/redmine/config/environment.rb
在开头加入:
if Gem::VERSION >= "1.3.6"
    module Rails
        class GemDependency
            def requirement
                r = super
                (r == Gem::Requirement.default) ? nil : r
            end
        end
    end
end

启动redmine:
ruby script/server webrick -e production &

然后可以在浏览器内通过http://ip:3000访问redmine,redmine安装就完成了。

 

9. 用nginx运行redmine

虽然上面这种方式可以运行redmine,但是非常慢,经分析主要是慢在http处理这块,从上面的运行命令就可以看出来,redmine相当于是运行在一个用ruby写的web server上。能不慢嘛。。。

 

所以就需要用nginx运行redmine,配置也很简单:

vim nginx.conf

在http这块加入:

  http {
      ...
      passenger_root /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.2;
      passenger_ruby /usr/bin/ruby;
      ...
  }

然后加一虚拟主机:

    server {
      listen 80;
      server_name www.yourhost.com;
      root /home/http/redmine/public;   # 注意这边要配置redmine目录下的public目录
      passenger_enabled on;
   }

重启nginx,就可以通过域名访问redmine了。

posted @ 2012-07-18 10:55 小马歌 阅读(527) | 评论 (0)编辑 收藏
 
     摘要: 原文:http://blog.ftofficer.com/2010/03/translation-rabbitmq-python-rabbits-and-warrens/RabbitMQ作为一个工业级的消息队列服务器,在其客户端手册列表的Python段当中推荐了一篇blog,作为RabbitMQ+Python的入门手册再合适不过了。不过,正如其标题Rabbit and Warrens(兔子和养兔场...  阅读全文
posted @ 2012-07-18 10:53 小马歌 阅读(274) | 评论 (0)编辑 收藏
 
     摘要: 在之前的《MongoDB分布式部署》中已经提到,同一组数据库服务器上的数据是支持复制的。mongodb支持两种方式的数据复制,简单的主从配置和互为主从的配置。MongoDB分布式部署之分片配置可见http://hi.baidu.com/lzpsky/blog/item/644e083d6bbd920cbaa16793.html   一、主从配置(Master Slave)主从数...  阅读全文
posted @ 2012-07-18 10:19 小马歌 阅读(291) | 评论 (0)编辑 收藏
仅列出标题
共95页: First 上一页 33 34 35 36 37 38 39 40 41 下一页 Last