版權聲明:轉載時請以超鏈接形式標明文章原始出處和作者信息及本聲明
原文地址: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
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
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)
一、安裝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'}); |
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,但是穩定第一,可以確保不會出現上面的問題了。
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了。