2014年3月4日 星期二

Apache Reverse Proxy 設定摘要

Reverse Proxy 的設定 /etc/httpd/conf/httpd.conf
<virtualhost *:80>
ProxyPass  /aa http://192.168.1.1      
ProxyPassReverse  /aa http://192.168.1.1
</virtualhost>

Web(192.168.1.1 (apache)) 修改 Log設定  /etc/httpd/conf/httpd.conf 加入
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
CustomLog "logs/access_log" combined env=!forwarded
CustomLog "logs/access_log" proxy env=forwarded
 
限制 
Web 中若有同一層目錄會有無法 PassReverse 情況
上例設定中若 url http://web/b <===> http://reverse-proxy/aa/b <= 失效
 

PROXMOX VE - OpenVZ Console

Centos 5 編輯 /etc/inittab 加入以下內容
1:2345:respawn:/sbin/agetty tty1 38400 linux


Centos 6 編輯 /etc/init/tty.conf 內容如下
# This service maintains a getty on tty1 from the point the system is
# started until it is shut down again.

start on stopped rc RUNLEVEL=[2345]

stop on runlevel [!2345]

respawn
exec /sbin/agetty -8 tty1 38400

更新 Proxmox Virtual Environment 3.x to latest 3.2

檢查 /etc/apt/sources.list  內容如下
deb http://http.at.debian.org/debian wheezy main contrib

# security updates
deb http://security.debian.org/ wheezy/updates main contrib

檢查 /etc/apt/sources.list.d/pve-enterprise.list 內容如下
deb https://enterprise.proxmox.com/debian wheezy pve-enterprise

執行以下指令
apt-get update
apt-get dist-upgrade
reboot

檢查版本指令 pveversion -v 

更改 PROXMOX VE 3.x 主機名稱

修改以下檔案
/etc/hosts
/etc/hostsname
/etc/postfix/main.cf

reboot

移動 openvz 設定檔
mv /etc/pve/nodes/{old-name}/openvz/* /etc/pve/nodes/{new-name}/openvz/

reboot

MySQL流程控制-repeat範例

# 去除字串中重覆空白字元

DROP FUNCTION `mrim`;
CREATE DEFINER=`root`@`localhost` FUNCTION `mrim`(`str` VARCHAR(2048)) RETURNS VARCHAR(2048) NOT DETERMINISTIC NO SQL SQL SECURITY DEFINER begin
DECLARE i INT DEFAULT 1;
DECLARE l INT;
DECLARE _str varchar(1024);
DECLARE _s varchar(1024);

set l = LENGTH(str);
set _str = '';

r1:REPEAT

set _s = substr(str,i,1);

if(_s<> ' ') then set _str = concat(_str,_s);
elseif (_s=' ' and substr(_str, LENGTH(_str), 1)<>' ') THEN set _str = CONCAT(_str,_s);
END IF;
  
set i = i + 1;

UNTIL i>l
END REPEAT r1;

return _str;
end

MySQL流程控制-while範例

# 字串反轉

DROP FUNCTION `while_ex`;
CREATE DEFINER=`root`@`localhost` FUNCTION `while_ex`(`str` VARCHAR(255)) RETURNS VARCHAR(255) NOT DETERMINISTIC NO SQL SQL SECURITY DEFINER begin
declare _ varchar(255) default '';

while not str is null and str<>'' do
  set _ = concat(_, substr(str, -1,1));
  set str = substr(str,1, length(str)-1);
end while;

return _;
end