2017-12-19

防火牆 內網 連不上 虛擬ip 的問題要用 nat loopback 來解決

FortiGate 為例 先建立 ip rang 如 192.168.1.0/24 在政策 中加入 來源 wan1 192.168.1.0/24 目的 internal 虛擬ip

2017-12-06

php curl ssl https 錯誤的 排除

curl 抓 https 時會出現以下的錯誤
Failed: Error Number: 60. Reason: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
原因是 ssl 無法驗証成功
解決方法一:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
解決方法二:
先用火狐或ie開啟連結,下載其 crt 檔,放到自已站中
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/path/download.crt");
缺點要自行注意到期日,重下新的 crt檔


參考連結:http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/

2017-11-03

php 自行編譯後,如何新增 extension,以sybase_ct 為例,並安裝freetds以連線mssql,系統為ubuntu

自行編譯時會下載 完整安裝包 , 裡面有 ext 的 資料夾,底下全是可以 新增的 Extension
安裝前要裝 freetds
sudo apt-get install freetds-dev tds-odbc libsybdb5 libct4libdbd-freetds freetds-common freetds-bin
再裝 freetds-dev (開發包)才不會出現 ctpublic.h 找不到的的錯誤
sudo apt-get install freetds-dev
完成後切換到 sybase_ct 資料夾中
cd sybase_ct
phpize
sudo ./configure --with-php-config=/www/server/php/56/bin/php-config --with-sybase-ct=shared,/usr
sudo make
sudo make install
指令說明
phpize :建立php extension 用的configure
--with-php-config= :之前編譯php時的php-config 位置,我的是在/www/server/php/56/bin/php-config
--with-sybase-ct=shared,/usr :官方bug有說明,因為 ctpublic.h 是在 /usr/include 底下,所以要這樣設才找得到 https://bugs.php.net/bug.php?id=13782

最後再到php.ini中,新增一行 
extension=完成路徑/sybase_ct.so
完整路徑會在 make install 列出

重開 apache 或重開 php-fpm

2017-06-30

apache 最大連接數

以 ubuntu 為例
sudo vim /etc/apache/apache.conf
<ifmodule mpm_prefork_module="">
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</ifmodule>

如 伺服器記憶體有16G,保守基本服務需要6g,還剩10G可用,假如每個進程用5m(很大用量) 那麼理論上可以支援10000/5 = 2000
更新為
<ifmodule mpm_prefork_module="">
StartServers 5
MinSpareServers 5
MaxSpareServers 10
ServerLimit 2500
MaxClients 2000
MaxRequestsPerChild 0
</ifmodule>

查看當前的連接數可以用:
ps aux | grep apache2 | wc -l
或:
pgrep apache2|wc -l

即時檢測HTTPD連接數:
watch -n 1 -d "ps aux | grep apache2 | wc -l"
或:
watch -n 1 -d "pgrep apache2|wc -l"

2017-06-16

vm,esx,esxi要連外部的 iscsi 或 nfs ,網卡須新增 VMkernel ,

vm,esx,esxi要連外部的 iscsi 或 nfs ,網卡須新增 VMkernel ,並且要vmkping 的 ping 外部的ip


2017-04-07

ajax 跨網域授權問題

//a.com.tw 用 ajax 抓 b.com.tw 的php 時, 
//b 站的php 要用 header("Access-Control-Allow-Origin: http://a.com.tw");
//授權給 http://a.com.tw 連入的ajax使用

//底下為 b.com.tw 的php 開頭語法
$http_origin = $_SERVER['HTTP_ORIGIN'];
$allow_origins = array();
//連入的站名
$allow_origins[] = "a.com.tw";
//有沒有 www 為不同來源
$allow_origins[] = "www.a.com.tw";
//要授權給多個須一一輸入
$allow_origins[] = "server1.com";
$allow_origins[] = "server2.com";
$allow_origins[] = "server3.com";
$allow_origins[] = "server4.com";
$allow_origins[] = "www.server1.com";
$allow_origins[] = "www.server2.com";
$allow_origins[] = "www.server3.com";
$allow_origins[] = "www.server4.com";
//如是用區域ip或實體ip 連入時
$allow_origins[] = "192.168.0.2";
$allow_origins[] = "10.0.0.3";
$allow_origins[] = "168.95.1.1";
foreach($allow_origins as $allow_origin){
if( $http_origin == "http://".$allow_origin || $http_origin == "https://".$allow_origin ){
header("Access-Control-Allow-Origin: ".$http_origin);
break;
}
}

?>