通常系統(tǒng)出于安全考慮,需要進(jìn)行權(quán)限(賬號(hào)、密碼)和IP白名單控制。如何獲取訪問來源真實(shí)的IP,如果公司網(wǎng)絡(luò)入口設(shè)置負(fù)載,自己系統(tǒng)設(shè)置nginx代理等操作,會(huì)使你達(dá)到目的不那么簡單直接。
通常情況下我們使用request.getRemoteAddr()就可以獲取到客戶端ip,但是當(dāng)我們使用了nginx作為反向代理后,由于在客戶端和web服務(wù)器之間增加了中間層,因此web服務(wù)器無法直接拿到客戶端的ip,通過$remote_addr變量拿到的將是反向代理服務(wù)器的ip地址。如果我們想要在web端獲得用戶的真實(shí)ip,就必須在nginx這里作一個(gè)賦值操作,如下:
proxy_set_header X-real-ip $remote_addr;
其中這個(gè)X-real-ip是一個(gè)自定義的變量名,這樣用戶的真實(shí)ip就被放在X-real-ip這個(gè)變量里了,然后,在web端可以這樣獲取:request.getAttribute("X-real-ip")。但是如果中間經(jīng)過N次代理過來的請(qǐng)求,X-real-ip就只能獲得到前一層代理的IP(10.6.61.14)了,下面是我的解決方案:


紅色部分IP是使用X-Forwarded-For(簡稱XFF頭)獲取的:,它代表客戶端,也就是HTTP的請(qǐng)求端真實(shí)的IP,只有在通過了HTTP 代理或者負(fù)載均衡服務(wù)器時(shí)才會(huì)添加該項(xiàng)(沒有經(jīng)過的獲取為空)標(biāo)準(zhǔn)格式如下:
X-Forwarded-For: client1, proxy1, proxy2
從標(biāo)準(zhǔn)格式可以看出,X-Forwarded-For頭信息可以有多個(gè),中間用逗號(hào)分隔,第一項(xiàng)為真實(shí)的客戶端ip,剩下的就是曾經(jīng)經(jīng)過的代理或負(fù)載均衡的ip地址,經(jīng)過幾個(gè)就會(huì)出現(xiàn)幾個(gè)。
我的Nginx具體配置如下:

關(guān)于參數(shù)含義:
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
意思是增加(不是覆蓋)一個(gè)$proxy_add_x_forwarded_for到X-Forwarded-For里去。
舉個(gè)例子,有一個(gè)web應(yīng)用,在它之前通過了兩個(gè)nginx轉(zhuǎn)發(fā)。在第一臺(tái)nginx中,使用
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
現(xiàn)在的$proxy_add_x_forwarded_for變量的"X-Forwarded-For"部分是空的,所以只有$remote_addr,而$remote_addr的值是用戶的ip,于是賦值以后,X-Forwarded-For變量的值就是用戶的真實(shí)的ip地址了。
到了第二臺(tái)nginx,使用
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
現(xiàn)在的$proxy_add_x_forwarded_for變量,X-Forwarded-For部分包含的是用戶的真實(shí)ip,$remote_addr部分的值是上一臺(tái)nginx的ip地址,于是通過這個(gè)賦值以后現(xiàn)在的X-Forwarded-For的值就變成了“用戶的真實(shí)ip,第一臺(tái)nginx的ip”。
所以我在程序中使用request.getHeader("x-forwarded-for").toString().split(",")[0]就能獲取到訪問客戶的真實(shí)IP,不用擔(dān)心前面有幾層轉(zhuǎn)發(fā)啦。
exp qq/1qqq BUFFER=640000 FILE=/oracleq/appq/oracleq/newq.DMP OWNER=qq
upstream tomcat_server { server IP地址:端口; }
upstream authority_server { server IP地址:端口; }
if ( $request_uri ~ "^\/itoo-basic" )
{
proxy_pass http://tomcat_server;
}
if ( $request_uri ~ "^\/itoo-authority" )
{
proxy_pass http://authority_server;
}
在Tomcat的bin目錄中執(zhí)行
chmod u+x *.sh
摘要: 二、安裝Nginx1、上傳nginx-0.7.63.tar.gz至/usr/local 2、執(zhí)行如下命令解壓nginx:1.#cd /usr/local2.#tar zxvf nginx-0.7.63.tar.gz3、編譯安裝nginx1.#cd nginx-0.7.632.#./configure --with-http_stub_status_module --with-...
閱讀全文
//連接
connect /as sysdba
1.創(chuàng)建表空間和用戶并為用戶指定表空間
//創(chuàng)建臨時(shí)表空間
create temporary tablespace user_temp tempfile 'D:oracleoradatauser_temp.dbf' size 50m autoextend on next 50m maxsize 20480m extent management local;
(注:user_temp是臨時(shí)表空間的名稱。)
//創(chuàng)建數(shù)據(jù)表空間lportal
create tablespace lportal logging datafile 'D:oracleoradatalportal.dbf' size 100m autoextend on next 50m extent management local;
(注:lportal是數(shù)據(jù)表空間的名稱。)
//創(chuàng)建用戶lportal并指定表空間
create user lportal identified by lportal default tablespace lportal_db temporary tablespace user_temp;
(注:第一個(gè)lportal是用戶名,第二個(gè)lportal是密碼;lportal_db是數(shù)據(jù)表空間名稱,user_temp是臨時(shí)表空間名稱。)
//為lportal用戶授權(quán)
grant connect,resource,dba to lportal;
2.數(shù)據(jù)備份(導(dǎo)入導(dǎo)出數(shù)據(jù))
//導(dǎo)入數(shù)據(jù)
imp lportal/lportal@orcl file=d:lportal20121109.dmp full=Y
//導(dǎo)出數(shù)據(jù)
exp lportal/lportal@orcl file=D:lportal20121109.dmp
(數(shù)據(jù)的導(dǎo)入與導(dǎo)出,在進(jìn)入到黑窗口后直接輸入上列語句,不需要進(jìn)入sqlplus)
3.刪除用戶及表空間
//刪除用戶以及用戶所有的對(duì)象
drop user lportal cascade;
//刪除表空間與表空間文件(注意:如果在創(chuàng)建表空間的時(shí)候帶有雙引號(hào),則刪除的時(shí)候也要帶上)
DROP TABLESPACE "stu_new" INCLUDING CONTENTS AND DATAFILES;
前提:刪除表空間之前要確認(rèn)該表空間沒有被其他用戶使用之后再做刪除
drop tablespace zfmi including contents and datafiles cascade onstraints;
//including contents 刪除表空間中的內(nèi)容,如果刪除表空間之前表空間中有內(nèi)容,而未加此參數(shù),表空間刪不掉,所以習(xí)慣性的加此參數(shù)
//including datafiles 刪除表空間中的數(shù)據(jù)文件
//cascade constraints 同時(shí)刪除tablespace中表的外鍵參照
4.查詢表空間和查詢用戶
//查詢所有表空間名稱
select tablespace_name from dba_tablespaces;
//查看表空間的名稱和狀態(tài)
select tablespace_name,status from dba_tablespaces;
//查詢當(dāng)前表空間屬性
select * from dba_tablespaces where tablespace_name='mtgyd';
//查詢所有用戶
select username from dba_users;
1、在某一目錄下面創(chuàng)建存放表空間的目錄,并賦予權(quán)限 chmod 777 文件 或者
sudo chmod -R 777 文件2、創(chuàng)建臨時(shí)表空間 create temporary tablespace USER_TEMP tempfile '/app1/orac1lenamespase/newn1amespase/USER_TEMP1.bdf' size 5120m reuse autoextend on next 20m maxsize unlimited;
3.創(chuàng)建表空間 create tablespace ZHFXBEMS1 datafile '/app1/ora1clenamespase/newnames1pase/ZHFXBEMS1.dbf' size 20480M reuse autoextend on next 40M maxsize unlimited default storage(initial 128k next 128k minextents 2 maxextents unlimited);
4、創(chuàng)建用戶和指定使用的表空間 create user qqidentified by 1 default tablespace ZHFXBEMSq temporary tablespace USER_TEMPq;
5.賦予權(quán)限
grant dba to qq;
grant connect,resource to qq;
grant select any table to qq;
grant delete any table to qq;
grant update any table to qq;
grant insert any table to qq;
當(dāng)多線程訪問資源時(shí),每條線程的數(shù)據(jù)變量都是不一樣的,線程間的數(shù)據(jù)需要做到獨(dú)立,不能相互共享,例如,數(shù)據(jù)庫中常見的轉(zhuǎn)賬業(yè)務(wù),兩次轉(zhuǎn)出和轉(zhuǎn)入操作,不能共享數(shù)據(jù),還要注意線程安全。
package com.yjw.thread;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
public class ThreadScopeShareData {
static class A{
public void get(){
System.out.println(" A="+Thread.currentThread().getName()+",data="+map.get(Thread.currentThread()));
}
}
static class B{
public void get(){
System.out.println(" B="+Thread.currentThread().getName()+",data="+map.get(Thread.currentThread()));
}
}
static Map<Thread, Integer> map = new HashMap<Thread, Integer>();
public static void main(String[] args) {
for (int i = 0; i < 2; i++) {
new Thread(new Runnable() {
public void run() {
int data=new Random().nextInt();
System.out.println(Thread.currentThread().getName()+",data="+data);
map.put(Thread.currentThread(), data);
new A().get();new B().get();
}
}).start();
}
}
}
當(dāng)使用了mvc:resources標(biāo)簽后,必須使用 <mvc:annotation-driven/>標(biāo)簽,就不會(huì)請(qǐng)求controller失敗了。