1. 程式人生 > 實用技巧 >AOP-MyBatis 多資料來源

AOP-MyBatis 多資料來源

一、開啟--with-http_stub_status_module模組可以看到訪問狀態 

[root@proxy ~]# tar  -zxvf   nginx-1.12.2.tar.gz
[root@proxy ~]# cd  nginx-1.12.2
[root@proxy nginx-1.12.2]# ./configure   \
> --with-http_ssl_module						#開啟SSL加密功能
> --with-stream								#開啟TCP/UDP代理模組
> --with-http_stub_status_module				        #開啟status狀態頁面
[root@proxy nginx-1.12.2]# make && make install	                  #編譯並安裝    

編輯配置檔案再server新增下面配置

[root@proxy ~]# cat /usr/local/nginx/conf/nginx.conf
… …
location /status {
                stub_status on;
				 #allow IP地址;
				 #deny IP地址;
        }
… …

訪問網頁 http://ip/status 可看到下面的資訊

Active connections: 1 
server accepts handled requests
 10 10 3 
Reading: 0 Writing: 1 Waiting: 0

Active connections:當前活動的連線數量。

Accepts:已經接受客戶端的連線總數量。

Handled:已經處理客戶端的連線總數量。

(一般與accepts一致,除非伺服器限制了連線數量)。

Requests:客戶端傳送的請求數量。

Reading:當前伺服器正在讀取客戶端請求頭的數量。

Writing:當前伺服器正在寫響應資訊的數量。

Waiting:當前多少客戶端在等待伺服器的響應。

二、優化併發

  (一)修改配置檔案

root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
.. ..
worker_processes  2;					//與CPU核心數量一致
events {
worker_connections 65535;		//每個worker最大併發連線數
}

  (二)修改核心引數ulimit

[root@proxy ~]# ulimit -a						//檢視所有屬性值
[root@proxy ~]# ulimit -Hn 100000				//設定硬限制(臨時規則)
[root@proxy ~]# ulimit -Sn 100000				//設定軟限制(臨時規則)
[root@proxy ~]# vim /etc/security/limits.conf
	.. ..
*               soft    nofile            100000
*               hard    nofile            100000

#該配置檔案分4列,分別如下:
#使用者或組    硬限制或軟限制    需要限制的專案   限制的值

三、瀏覽器本地快取靜態資料

root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
expires		30d;			//定義客戶端快取時間為30天
}
}

四、日誌切割

[root@proxy ~]# vim /usr/local/nginx/logbak.sh
#!/bin/bash
date=`date +%Y%m%d`
logpath=/usr/local/nginx/logs
mv $logpath/access.log $logpath/access-$date.log
mv $logpath/error.log $logpath/error-$date.log
kill -USR1 $(cat $logpath/nginx.pid)

[root@proxy ~]# crontab -e
03 03 * * 5  /usr/local/nginx/logbak.sh

五、對頁面進行壓縮處理

[root@proxy ~]# cat /usr/local/nginx/conf/nginx.conf
http {
.. ..
gzip on;							//開啟壓縮
gzip_min_length 1000;				//小檔案不壓縮
gzip_comp_level 4;				//壓縮比率
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
									//對特定檔案壓縮,型別參考mime.types
.. ..
}

六、伺服器記憶體快取(如果需要處理大量靜態檔案,可以將檔案快取在記憶體,下次訪問會更快。

http { 
open_file_cache          max=2000  inactive=20s;
        open_file_cache_valid    60s;
        open_file_cache_min_uses 5;
        open_file_cache_errors   off;
//設定伺服器最大快取2000個檔案控制代碼,關閉20秒內無請求的檔案控制代碼
//檔案控制代碼的有效時間是60秒,60秒後過期
//只有訪問次數超過5次會被快取
}