sudo /usr/bin# /usr/bin/mysql_install_db
Category Archives: Linux
XMPP4R supports Chinese
*** parsers/baseparser.rb~ 2011-01-12 22:35:06.000000000 +0200
*** parsers/baseparser.rb 2011-01-12 22:35:06.000000000 +0200
*** 216,222 ****
version = version[1] unless version.nil?
encoding = ENCODING.match(results)
encoding = encoding[1] unless encoding.nil?
! @source.encoding = encoding
standalone = STANDALONE.match(results)
standalone = standalone[1] unless standalone.nil?
return [ :xmldecl, version, encoding, standalone ]
— 216,222 —-
version = version[1] unless version.nil?
encoding = ENCODING.match(results)
encoding = encoding[1] unless encoding.nil?
! @source.encoding = encoding unless encoding.nil?
standalone = STANDALONE.match(results)
standalone = standalone[1] unless standalone.nil?
return [ :xmldecl, version, encoding, standalone ]
Reference Link: http://pastie.org/1454110
Apache Enable UserDir
a2enmod userdir
Apache Proxy to Thin (ROR app server)
1. sudo a2enmod proxy
2. sudo a2enmod proxy_balancer
3. sudo a2enmod proxy_http
4. sudo a2enmod rewrite
5. sudo /etc/init.d/apache2 force-reload
6. sudo nano /etc/apache2/sites-available/domain.com
<VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /home/demo/public_html/railsapp/public
RewriteEngine On
<Proxy balancer://thinservers>
BalancerMember http://127.0.0.1:5000
BalancerMember http://127.0.0.1:5001
BalancerMember http://127.0.0.1:5002
</Proxy>
# Redirect all non-static requests to thin
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/http-bind(.*) http://127.0.0.1:5280%{REQUEST_URI} [P,QSA,L]
RewriteRule ^/(.*)$ balancer://thinservers%{REQUEST_URI} [P,QSA,L]
#ProxyPass / balancer://thinservers/
#ProxyPassReverse / balancer://thinservers/
#ProxyPreserveHost on
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# Custom log file locations
ErrorLog /home/demo/public_html/railsapp/log/error.log
CustomLog /home/demo/public_html/railsapp/log/access.log combined
</VirtualHost>
Start ROR
source .bash_profile
rvm use 1.9.2 –default
sudo /etc/init.d/kannel stop
sudo -s
bearerbox -v 0
smsbox -v 0 &
rails runner script/send_sms.rb
rails runner script/xmpp4r_forwarder.rb
rails runner script/notifier.rb
bundle exec thin start –server 3
Translate Domain Name via VPN
Server Side:
1. Install dnsmasq
2. setup tcp tunnel of openvpn
3. iptables -t nat -I POSTROUTING -s 10.x.x.x/24 -j SNAT –to x.x.x.x
Client Side:
1. Add DNSMASQ_OPTS=”–clear-on-reload” to /etc/default/dnsmasq
2. setup tcp tunnel client of openvpn
3. Add 0 5 * * * lynx -source https://smarthosts.googlecode.com/svn/trunk/dnsmasq.conf | grep address | awk -F / {‘print “server=/”$2″/10.9.0.1″‘} > /etc/dnsmasq.d/smart_host_domain;; /etc/init.d/dnsmasq restart to crontab
4. Modify /etc/resolv.conf to use “nameserver 127.0.0.1” only
Route https packets to VPN 2
ip route add default dev tun0 table 200
ip rule add fwmark 0x45 table 200
iptables -A INPUT -i tun0 -j ACCEPT
iptables -t nat -I POSTROUTING -o tun0 -j SNAT –to 10.8.0.6
iptables -t nat -I POSTROUTING -o tun0 -j MASQUERADE
# Add the marked packets
iptables -t mangle -I PREROUTING -p tcp –dport 443 -j MARK –set-mark 0x45
iptables -t mangle -I OUTPUT -s 10.8.0.6 -j MARK –set-mark 0x45
# Delete the marked packets
iptables -t mangle -D OUTPUT -p tcp –dport 443 -j MARK –set-mark 0x45
iptables -t mangle -D OUTPUT -s 10.8.0.6 -j MARK –set-mark 0x45
# re-enable ALL source-address verification filtering
for i in /proc/sys/net/ipv4/conf/*/rp_filter ; do echo 0 > $i; done
Redirect 443 packets to VPN channel
-
#!/sbin/runscript
-
# Distributed under the terms of the GNU General Public License v2
-
IFACE=$(netstat -rn | grep UG | awk ‘NR==1{print($8)}’)
-
ITUN=”tun0″
-
TBL=”VPN1″
-
depend() {
-
use dnsmasq
-
}
-
start() {
-
# starting openVPN
-
/etc/init.d/openvpn.vpn1 start
-
# wait until VPN is fully operationnal [ route is built ]
-
while [ -z “$(route -n | awk ‘/'”$ITUN”‘/&&/255/ {print($1)}’)” ]; do sleep .25; done
-
# getting our VPN IP, range & mask
-
ITUNADDR=$(ifconfig $ITUN | awk ‘/dr:/ { gsub(/.*:/,””,$2); print($2); }’)
-
TUNRANGE=$(route -n | awk ‘/tun0/ && /255/ {print($1)}’)
-
TUNMASK=$(route -n | awk ‘/tun0/ && /255/ {print($3)}’)
-
# adding $TBL table if necessary
-
if [ ! -n “$(grep “200 $TBL” /etc/iproute2/rt_tables)” ]; then
-
echo “200 $TBL” >> /etc/iproute2/rt_tables
-
fi
-
# re-add standard nameserver
-
echo “nameserver 127.0.0.1” > /etc/resolv.conf
-
# making route to VPN
-
ip route add default dev $ITUN table $TBL
-
# marked packets follows VPN route
-
ip rule add fwmark 0x45 table $TBL
-
# accept packets from VPN
-
iptables -A INPUT -i $ITUN -j ACCEPT
-
# some services are marked to follow the route
-
iptables -t mangle -A OUTPUT -p udp –dport 53 -j MARK –set-mark 0x45
-
iptables -t mangle -A OUTPUT -p tcp –dport 443 -j MARK –set-mark 0x45
-
iptables -t mangle -A OUTPUT -p tcp –dport 8080 -j MARK –set-mark 0x45
-
# binding tun’s ip to tun’s interface
-
iptables -t nat -A POSTROUTING -o $ITUN -j SNAT –to $ITUNADDR
-
# force output packets (from VPN) to go out through VPN too
-
iptables -t mangle -A OUTPUT -s $ITUNADDR -j MARK –set-mark 0x45
-
# disable ALL source-address verification filtering
-
for i in /proc/sys/net/ipv4/conf/*/rp_filter ; do echo 0 > $i; done
-
}
-
stop() {
-
# getting our VPN IP, range & mask
-
#ITUNADDR=$(ifconfig $ITUN | awk ‘NR==2{print $2}’ | sed ‘s/adr://g’)
-
ITUNADDR=$(ifconfig $ITUN | awk ‘/dr:/ { gsub(/.*:/,””,$2); print($2); }’)
-
TUNRANGE=$(route -n | awk ‘/tun0/ && /255/ {print($1)}’)
-
TUNMASK=$(route -n | awk ‘/tun0/ && /255/ {print($3)}’)
-
# stoping openVPN
-
/etc/init.d/openvpn.vpn1 stop
-
# removing VPN route if is present
-
if [ ! -z “$(route -n | awk ‘/'”$ITUN”‘/&&/255/ {print($1)}’)” ]; then
-
ip route del default dev $ITUN table $TBL
-
fi
-
# remove route for marked packets
-
ip rule del fwmark 0x45 table $TBL
-
# remove accept packets from VPN
-
iptables -D INPUT -i $ITUN -j ACCEPT
-
# remove iptables packet marking
-
iptables -t mangle -D OUTPUT -p udp –dport 53 -j MARK –set-mark 0x45
-
iptables -t mangle -D OUTPUT -p tcp –dport 443 -j MARK –set-mark 0x45
-
iptables -t mangle -D OUTPUT -p tcp –dport 8080 -j MARK –set-mark 0x45
-
# removing binding
-
iptables -t nat -D POSTROUTING -o $ITUN -j SNAT –to $ITUNADDR
-
# remove output packets to go out throuth VPN
-
iptables -t mangle -D OUTPUT -s $ITUNADDR -j MARK –set-mark 0x45
-
# re-enable ALL source-address verification filtering
-
for i in /proc/sys/net/ipv4/conf/*/rp_filter ; do echo 1 > $i; done
-
#echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
-
}
Redirect traffic from one interface to another
VPS (10.8.0.0/24) <——> (tun0) Server (ppp1) <——> iPhone (172.16.31.0/24)
iptables -A INPUT -p tcp –dport 109 -j ACCEPT
iptables -A INPUT -i ppp1 -j ACCEPT
iptables -A FORWARD -i ppp1 -j ACCEPT
iptables -A FORWARD -o ppp1 -j ACCEPT
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -I POSTROUTING -s 172.16.31.0/24 -o ppp0 -j MASQUERADE
ip route add default dev tun0 table 200
ip rule add priority 100 from 172.16.31.0/24 table 200
iptables -t nat -I POSTROUTING -o tun0 -j SNAT –to 10.8.0.6