tomcat7,jdk7,mongoDB最新版(搭建replacia set模式),maven 服務器nexus,,svn, php

環境需求:tomcat7,jdk7,mongoDB最新版(搭建replacia set模式),maven 服務器nexus,svn, php

linux 版本centos



jdk7+tomcat7+centos 安裝

http://blog.sina.com.cn/s/blog_704836f40100yyc9.html

安裝jdk7的時候要先卸載之前的 OpenJDK

[root@localhost ~]# java -version

java version "1.6.0_24"

OpenJDK Runtime Environment (IcedTea6 1.11.13) (rhel-1.65.1.11.13.el6_4-x86_64)

OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

[root@localhost ~]# rpm -qa | grep java

java-1.6.0-openjdk-1.6.0.0-1.65.1.11.13.el6_4.x86_64

tzdata-java-2013g-1.el6.noarch

[root@localhost ~]# rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.65.1.11.13.el6_4.x86_64

[root@localhost ~]# rpm -e --nodeps tzdata-java-2013g-1.el6.noarch

[root@localhost ~]# rpm -qa | grep java





[root@localhost bin]# cd commons-daemon-1.0.15-native-src/unix/

[root@localhost unix]# ./configure

*** Current host ***

checking build system type... x86_64-unknown-linux-gnu

checking host system type... x86_64-unknown-linux-gnu

checking cached host system type... ok

*** C-Language compilation tools ***

checking for gcc... no

checking for cc... no

checking for cc... no

checking for cl... no

configure: error: no acceptable C compiler found in $PATH

See `config.log' for more details.

需要安裝gcc組件

yum -y install gcc




nexusMave私服

http://my.oschina.net/shootercn/blog/12269

http://blog.csdn.net/cuker919/article/details/6338039

Maven.pdf 2.2基於unix的系統上安裝

Maven.pdf 9Nexus 創建私服



出現這個狀況是因爲 nexus目錄權限的問題修改權限即可。

chown -R apaduser:apaduser nexus-2.6.4-02

chown -R apaduser:apaduser nexus


install MongoDB on Red Hat Enterprise,CentOS,or Fedora Linux

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux/

mongodb replica set configuration

http://docs.mongodb.org/manual/reference/replica-configuration/

centos svn server 安裝配置

http://www.ha97.com/4467.html



相關下載:

jdk7_linux_64

http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-x64.rpm

apche-tomcat7.0.42

http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.42/bin/apache-tomcat-7.0.42.tar.gz



————————————————————————————————————————————————————————

mongodb安裝(centos or redhat

vim /etc/yum.repos.d/mongodb.repo

[mongodb]

name=MongoDB Repository

baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/

gpgcheck=0

enabled=1


yum install mongo-10gen mongo-10gen-server


yum install mongo-10gen-2.4.6 mongo-10gen-server-2.4.6

防止意外的升級mongodb /etc/yum.conf 增加如下內容

exclude=mongo-10gen,mongo-10gen-server


配置文件位置/etc/mogod.conf ,初始化腳本位置/etc/rc.d/init.d/mongod

這個MongoDB實例,的數據文件在/var/lib/mongo 日誌文件位置 /var/log/mongo

#如果切換用戶運行MongoDB進程,需要修改/var/lib/mongo /var/log/mongo 的文件夾權限。


啓動MongoDB

service mongod start

停止MongoDB

service mongod stop

重啓MongoDB

service mongod restart


————————————————————————————————————————————————————————


第五部分架構篇第二十一章 Replica Sets 複製集

MongoDB 支持在多個機器中通過異步複製達到故障轉移和實現冗餘。多機器中同一時刻只有一臺是用於寫操作。正是由於這個情況, MongoDB 提供了數據一致性的保障。擔當 Primary 角色的機器能把讀操作分發給 slave

MongoDB 高可用可用分兩種:

Master-Slave 主從複製:

只需要在某一個服務啓動時加上–master 參數,而另一個服務加上–slave –source 參數, 即可實現同步。MongoDB 的最新版本已不再推薦此方案。
ReplicaSets複製集:

MongoDB 1.6 版本對開發了新功能 replica set,這比之前的 replication 功能要強大一,增加了故障自動切換和自動修復成員節點,各個 DB 之間數據完全一致,大大降低了維護成功。auto shard 已經明確說明不支持 replication paris,建議使用 replica set,replica set 故障切換完全自動。


如果上圖所示,Replica Sets 的結構非常類似一個集羣。是的,你完全可以把它當成集羣,爲它確實跟集羣實現的作用是一樣的,其中一個節點如果出現故障,其它節點馬上會將業務接過來而無須停機操作。

21.1 部署 Replica Sets 接下來將一步一步的給大家分享一下實施步驟:

1創建數據文件存儲路徑

2創建日誌文件路徑

[root@localhost ~]# mkdir -p /data/log

3、創建主從 key 文件,用於標識集羣的私鑰的完整路徑,如果各個實例的 key file 內容不一,程序將不能正常用。

4、啓動 3 個實例

[root@localhost ~]# mkdir -p /data/data/r0

[root@localhost ~]# mkdir -p /data/data/r1

[root@localhost ~]# mkdir -p /data/data/r2

[root@localhost ~]# mkdir -p /data/key
[root@localhost ~]#
echo "this is rs1 super secret key" > /data/key/r0

[root@localhost ~]# echo "this is rs1 super secret key" > /data/key/r1

[root@localhost ~]# echo "this is rs1 super secret key" > /data/key/r2

[root@localhost ~]# chmod 600 /data/key/r*


[root@localhost ~]# /Apps/mongo/bin/mongod --replSet rs1 --keyFile /data/key/r0 --fork --port 28010 --dbpath /data/data/r0 --logpath=/data/log/r0.log --logappend
all output going to: /data/log/r0.log
forked process: 6573

[root@localhost ~]# /Apps/mongo/bin/mongod --replSet rs1 --keyFile /data/key/r1 --fork --port 28011 --dbpath /data/data/r1 --logpath=/data/log/r1.log --logappend
all output going to: /data/log/r1.log
forked process: 6580

[root@localhost ~]# /Apps/mongo/bin/mongod --replSet rs1 --keyFile /data/key/r2 --fork --port 28012 --dbpath /data/data/r2 --logpath=/data/log/r2.log --logappend
all output going to: /data/log/r2.log
forked process: 6585

[root@localhost ~]#


5、配置及初始化 Replica Sets


配置 replca set

[root@localhost data]# mongo -port 28010

MongoDB shell version: 2.4.6

connecting to: 127.0.0.1:28010/test

> config_rs1 = {_id:'rs1',members:[

... {_id: 0,host:'localhost:28010',priority:1},

... {_id: 1,host:'localhost:28011'},

... {_id: 2,host:'localhost:28012'}]

... }

{

"_id" : "rs1",

"members" : [

{

"_id" : 0,

"host" : "localhost:28010",

"priority" : 1

},

{

"_id" : 1,

"host" : "localhost:28011"

},

{

"_id" : 2,

"host" : "localhost:28012"

}

]

}


初始化配置

> rs.initiate(config_rs1);

{

"info" : "Config now saved locally. Should come online in about a minute.",

"ok" : 1

}


查看複製集的狀態



rs1:SECONDARY> rs.status()

{

"set" : "rs1",

"date" : ISODate("2013-10-25T11:14:53Z"),

"myState" : 1,

"members" : [

{

"_id" : 0,

"name" : "localhost:28010",

"health" : 1, 1表示正常;0表示異常

"state" : 1, 1表明是 Primary;2表示是 Secondary;

"stateStr" : "PRIMARY", 表明此機器是主庫

"uptime" : 1168,

"optime" : Timestamp(1382699470, 1),

"optimeDate" : ISODate("2013-10-25T11:11:10Z"),

"self" : true

},

{

"_id" : 1,

"name" : "localhost:28011",

"health" : 1,

"state" : 2,

"stateStr" : "SECONDARY",

"uptime" : 218,

"optime" : Timestamp(1382699470, 1),

"optimeDate" : ISODate("2013-10-25T11:11:10Z"),

"lastHeartbeat" : ISODate("2013-10-25T11:14:53Z"),

"lastHeartbeatRecv" : ISODate("2013-10-25T11:14:53Z"),

"pingMs" : 0,

"syncingTo" : "localhost:28010"

},

{

"_id" : 2,

"name" : "localhost:28012",

"health" : 1,

"state" : 2,

"stateStr" : "SECONDARY",

"uptime" : 218,

"optime" : Timestamp(1382699470, 1),

"optimeDate" : ISODate("2013-10-25T11:11:10Z"),

"lastHeartbeat" : ISODate("2013-10-25T11:14:53Z"),

"lastHeartbeatRecv" : ISODate("2013-10-25T11:14:52Z"),

"pingMs" : 0,

"syncingTo" : "localhost:28010"

}

],

"ok" : 1

}



還可以用 isMaster 查看 Replica Sets 狀態。

rs1:PRIMARY> rs.isMaster()

{

"setName" : "rs1",

"ismaster" : true,

"secondary" : false,

"hosts" : [

"localhost:28010",

"localhost:28012",

"localhost:28011"

],

"primary" : "localhost:28010",

"me" : "localhost:28010",

"maxBsonObjectSize" : 16777216,

"maxMessageSizeBytes" : 48000000,

"localTime" : ISODate("2013-10-25T11:18:38.231Z"),

"ok" : 1

}

讀寫分類

1,主庫中插入一條測試數據

[root@localhost data]# mongo --port 28010

MongoDB shell version: 2.4.6

connecting to: 127.0.0.1:28010/test

rs1:PRIMARY> db.c1.insert({age:30})

rs1:PRIMARY> db.c1.find()

{ "_id" : ObjectId("526a5841f38d5f1304bcff8c"), "age" : 30 }

2,在從庫中進行查詢等操作

rs1:SECONDARY> show collections

Fri Oct 25 19:40:29.837 error: { "$err" : "not master and slaveOk=false", "code" : 13435 } at src/mongo/shell/query.js:128

rs1:SECONDARY> db.getMongo().setSlaveOk()

rs1:SECONDARY> db.c1.find()

{ "_id" : ObjectId("526a5841f38d5f1304bcff8c"), "age" : 30 }

rs1:SECONDARY> show collections

c1

system.indexes





————————————————————————————————————————————————————————



軟件下載

apache-maven

http://apache.fayea.com/apache-mirror/maven/binaries/apache-maven-3.0.5-bin.tar.gz

nexus

http://www.sonatype.org/downloads/nexus-latest-bundle.tar.gz


maven安裝配置

1,創建用戶和用戶組

groupadd apaduser

useradd -g apaduser apaduser

passwd apaduser //設置密碼

2,創建解壓目錄

mkdir -p /opt/maven

mv apache-maven-3.0.5-bin.tar.gz /opt/maven

cd !$

tar -zvxf apache-maven-3.0.5-bin.tar.gz

ln -s apache-maven-3.0.5 apache-maven

chown -R apaduser:apaduser /opt/maven

3,配置環境變量

cd

vim .bash_profile


# .bash_profile


# Get the aliases and functions

if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi


# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

M2_HOME=/opt/maven/apache-maven

export M2_HOME

PATH=$PATH:$M2_HOME/bin

export PATH


source .bash_profile

4,查看版本

/opt/maven/apache-maven/bin -version

5,查看.m2目錄

cd /home/apaduser/.m2

如果沒有這個目錄則創建一個

mkdir .m2

6、如果需要把mavenrepository目錄指定到其他目錄,則修改maven安裝目錄下conf中的配置文件settings.xml文件

1. #vi /opt/maven/apache-maven/conf/settings.xml

2. 將文件中<localRepository>….</localRepository>的註釋打開

3. 或者在文件中增加在這個註釋下增加

4. <localRepository>your repository path</localRepository>


二、搭建nexus私服
1、解壓nexus-oss-webapp-1.8.0-bundle.tar.gz文件到指定目錄

使用root用戶進行操作

1.#cp nexus-oss-webapp-1.8.0-bundle.tar.gz /usr/local

2.#tar -zvxf nexus-oss-webapp-1.8.0-bundle.tar.gz

3.#ln –s nexus-oss-webapp-1.8.0 nexus

4.chown -R apaduser:apaduser /usr/local/sonatype-work/ /usr/local/nexus /usr/local/nexus-2.6.4-02/


2、啓動nexus

1.#cd /usr/local/nexus/bin/jsw

2.

3.選擇自己機器的版本:

4.

5.#cd linux-x86-64/

6.#./nexus start

7.

8.重啓:

9.#./nexus restart

10.停止:

11.#./nexus stop

3、運行nexus
在瀏覽器中輸入:http://changethislocalhost:8081/nexus
就可以看到nexus 的主頁,點擊右上角Log in
默認用戶名和密碼是:admin/admin123
運行後會自動生成一個nexus工作目錄sonatype-worknexus下載的jar包會存放在
sonatype-work/nexus/storage

4、配置
1) 點擊左側菜單Repositories
分別將右側列表中

1. Apache Snapshots 2. Codehaus Snapshots 3. Maven Central

三個repository 的configuration配置選項中的Download Remote Index 配置改爲True,並保存設置,
然後在列表中分別右鍵點擊三個Repository,點擊ReIndex



true是開啓,false是關閉由於中央倉庫內容比較多,因此其索引文件比較大,需要查看下載是否完成了,我們可以單擊界面左邊導航欄中的 Scheduled Tasks 鏈接後,就可以看到系統調度的任務其狀態爲 runing,在說哦因下載完畢之後,該任務就會消失。

Scheduled Tasks 界面:



只有下載了,在search查詢纔會有東西,不然什麼都搜索不到。



2)增加新的Repository,有一些比較常用jar包在nexus提供的repository中可能找不到,
一般比較常用的有

1.JBOSS的兩個:

2.http://repository.jboss.org/maven2/

3.http://repository.jboss.org/nexus/content/repositories/releases/

4.SUN的:

5.http://download.java.net/maven/2/

6.K-INT的:

7.http://developer.k-int.com/maven2/

8.

9.因爲找juel:juel-impl:2.2.1這個jar包,所以我還添加了一個自己找的:

10.http://repository.exoplatform.org/content/groups/public/

添加步驟:

點擊Add->Proxy Repository->填寫Repository ID, Repository Name, 以及Remote Storage Location 其他的默認即可。

3) 將新增的Repository添加到Public Repositories
Public Repositories Configuration中,將多選Select中的項全部添加到左邊,然後保存。

4) 添加自己的jar

1.repository列表中有一個3rd party,也就是第三方jar包,點擊會看到一個Artifact Upload選項卡,點擊後,填寫相應的信息。

2.GAV Definition 一般選擇 GAV Parameters

3.然後添加Group:Artifact:Version:Package

4.示例 juel:juel-impl:2.2.1:jar

然後選擇要上傳的jar包,保存即可

比如我們項目需要如下幾個包:

javax.jms:jms:1.1:jar

proxool:proxool:0.9.1:jar

proxool:proxool-cglib:0.9.1:jar

com.lowagie:itextasian:1.0:jar

com.danga.MemCached:memcached:2.0.1:jar


5) nexus中設置代理服務器
選擇左側administrator菜單中的Server選項,在右側打開的頁面的中下部,有一個選擇項:Default HTTP Proxy Settings(optional) 將前面的複選框選中,填寫相應的代理服務器信息即可。web-proxy.cce.hp.com:8080

6) 編寫自己的settings.xml,文件內容如下:

1.<settings>

2. <proxies>

3. <proxy>

4. <id>normal</id>

5. <active>true</active>

6. <protocol>http</protocol>

7. <username>deployment</username>

8. <password>deploy</password>

9. <host>changethislocalhost:8081/nexus</host>

10. <port>80</port>

11. <nonProxyHosts>changethislocalhost:8081/nexus</nonProxyHosts>

12. </proxy>

13. </proxies>

14.

15. <mirrors>

16. <mirror>

17. <!–This is used to direct the public snapshots repo in the

18. profile below over to a different nexus group –>

19. <id>nexus-public-snapshots</id>

20. <mirrorOf>public-snapshots</mirrorOf>

21. <url>http://changethislocalhost:8081/nexus/content/groups/public-snapshots</url>

22. </mirror>

23. <mirror>

24. <!–This sends everything else to /public –>

25. <id>nexus</id>

26. <mirrorOf>*</mirrorOf>

27. <url>http://changethislocalhost:8081/nexus/content/groups/public</url>

28. </mirror>

29. </mirrors>

30.

31. <profiles>

32. <profile>

33. <id>nexus</id>

34. <repositories>

35. <repository>

36. <id>central</id>

37. <url>http://central</url>

38. <releases><enabled>true</enabled></releases>

39. <snapshots><enabled>true</enabled></snapshots>

40. </repository>

41. </repositories>

42. <pluginRepositories>

43. <pluginRepository>

44. <id>central</id>

45. <url>http://central</url>

46. <releases><enabled>true</enabled></releases>

47. <snapshots><enabled>true</enabled></snapshots>

48. </pluginRepository>

49. </pluginRepositories>

50. </profile>

51. <profile>

52. <!–this profile will allow snapshots to be searched when activated–>

53. <id>public-snapshots</id>

54. <repositories>

55. <repository>

56. <id>public-snapshots</id>

57. <url>http://public-snapshots</url>

58. <releases><enabled>false</enabled></releases>

59. <snapshots><enabled>true</enabled></snapshots>

60. </repository>

61. </repositories>

62. <pluginRepositories>

63. <pluginRepository>

64. <id>public-snapshots</id>

65. <url>http://public-snapshots</url>

66. <releases><enabled>false</enabled></releases>

67. <snapshots><enabled>true</enabled></snapshots>

68. </pluginRepository>

69. </pluginRepositories>

70. </profile>

71. </profiles>

72. <activeProfiles>

73. <activeProfile>nexus</activeProfile>

74. </activeProfiles>

75.</settings>

settings.xml文件複製到${user}/.m2目錄下

7) 測試
創建一個maven項目

#mvn archetype:generate

如果創建一個web項目可以選擇83
填寫相應的信息,maven會從私服上下載相應的jar包,看到的地址應該都是changethislocalhost
項目創建成功後,將自己的pom.xml文件放在項目,執行

#mvn install 或者#mvn package

mvn會下載pom.xml文件定義的jar依賴

下載完成後,你可以在自己指定的repository目錄下, 如果沒有指定則是在 .m2/repository目錄下查看自己的jar

至此,我們的maven安裝以及私服的搭建工作就完成了。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章