1.解壓
修改文件名為mongo3.2.5,執(zhí)行命令如下:
mv mongodb-linux-i686-3.2.5 mongo3.2.5
2.創(chuàng)建組mongoDB與用戶mongoDB、文件夾data以及l(fā)og
用于與組是為了便于管理MongoDB
data用于存放mongoDB數(shù)據(jù)。
log用于記錄mongoDB日志。
3.指定組、用戶
4.啟動(dòng)mongo服務(wù)命令
bin/mongod --dbpath=/usr/local/mongo-3.25/data/ --logpath=/usr/local/mongo-3.25/log/mongo.log --journal --storageEngine=mmapv1
注意:因?yàn)槲沂褂玫氖莑inux32位系統(tǒng)的,故默認(rèn)的存儲(chǔ)引擎wiredTiger是不支持的。需要指定存儲(chǔ)引擎。如果不指定可能會(huì)報(bào)以下錯(cuò)誤:
開啟MongoDB服務(wù)成功后,截圖如下:
連接mongo服務(wù)
上面啟動(dòng)MongoDB之后,需要重新打開一個(gè)窗口,進(jìn)行連接。
當(dāng)提示如下信息,代表連接成功。
當(dāng)然,也可以通過瀏覽器訪問以下網(wǎng)址,查看輸出結(jié)果
http://192.168.153.140:27017
初始安裝的時(shí)候沒有admin數(shù)據(jù)庫(kù)
開啟認(rèn)證
修改配置文件/etc/MongoDB.conf
打開auth的注釋,設(shè)置為auth = true
重啟mongodb
sudo service mongodb restart
添加管理員
使用命令mongo進(jìn)入命令行
創(chuàng)建第一個(gè)用戶,該用戶需要有用戶管理權(quán)限
這里設(shè)置其角色為root
use admin
db.createUser({user:"admin",pwd:"password",roles:["root"]})
新增的用戶在system.users中
> db.getCollectionNames()
[ "system.indexes", "system.users", "system.version" ]
第一個(gè)用戶添加完成后,便需要認(rèn)證才能繼續(xù)添加其他用戶
使用db.auth("admin", "password")認(rèn)證
添加數(shù)據(jù)庫(kù)用戶
為其他數(shù)據(jù)庫(kù)添加用戶,添加用戶前需要切換到該數(shù)據(jù)庫(kù)
這里設(shè)置其角色為dbOwner
use testdb1
db.createUser({user: "testdb1u1", pwd: "xyz123", roles: [{ role: "dbOwner", db: "testdb1" }]})
查看用戶
> use admin
switched to db admin
> db.system.users.find()
{ "_id" : "admin.admin", "user" : "admin", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "Fdh2ldIW3Aw8Cxz9Dt+96g==", "storedKey" : "zbkfj6ZQH1xwGoOg8JJ6OjtR3Cs=", "serverKey" : "yqkqHABZ64rEeq1X0htOAtUnwFU=" } }, "roles" : [ { "role" : "root", "db" : "admin" } ] }
{ "_id" : "testdb1.testdb1u1", "user" : "testdb1u1", "db" : "testdb1", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "Xxt2uET3jRtAYVigyLUydw==", "storedKey" : "yinLG61nRFzfC+3NtB5p9RR+avM=", "serverKey" : "OX/Pdft7JWJm/g0jg07q49OC4c8=" } }, "roles" : [ { "role" : "dbOwner", "db" : "testdb1" } ] }
參考地址:
一、spring-context*.xml 合并到 spring-mvc.xml 的方法
spring-servlet.xml 中加入 <import resource="ApplicationContext.xml" />
ApplicationContext.xml 中把其它的xml文件import進(jìn)來
web.xml
SpringMVC核心分發(fā)器 加入?yún)?shù) <param-value>classpath:spring-mvc.xml</param-value>
不加載 <param-value>classpath*:/spring-context*.xml</param-value>
controller/service等都在mvc中加載
<context:component-scan base-package="com.mweb.**.controller" />
<context:component-scan base-package="com.mweb.**.service" />。。。。需要加載的@Component等
加入:
<aop:aspectj-autoproxy proxy-target-class="true" />
二、spring-context*.xml / spring-mvc.xml 分開加載掃描的方法
web.xml 中:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/spring-context*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 必須加入才行
</listener>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
spring-mvc.xml 中:
<context:component-scan base-package="com.mweb.**.controller" /> 掃描 controller
<aop:aspectj-autoproxy /> aop 參考下面的也行
- <aop:aspectj-autoproxy proxy-target-class="true">
- <aop:include name="controllerAspect"/> @Aspect聲明的類
- </aop:aspectj-autoproxy>
<context:component-scan base-package="com.mweb.**.extension,
com.mweb.**.service,
com.mweb.base.aspect,
com.mweb.base.shiro.realm" />
<aop:aspectj-autoproxy proxy-target-class="true" />
這樣就可以了