Archive for the ‘CentOS’ Category

Gentoo下Nginx使用GeoIP模块为Django提供GEO信息

Tuesday, July 27th, 2010

首先要在Gentoo下安装编译Nginx,需要加入GeoIP模块,请参考另一篇文章《Gentoo 安装编译Nginx》。在安装的过程中应该是会自动安装dev-libs/geoip这个包,如果没有的话使用emerge安装:

emerge -avt dev-libs/geoip

下载MaxMind的GEO数据,解压缩放在/etc/nginx目录下:

#Get the free database of geo_city
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoLiteCity.dat.gz
mv GeoLiteCity.dat /etc/nginx
#Get the free database of geo_coundty
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gunzip GeoIP.dat.gz
mv GeoIP.dat /etc/nginx

编辑/etc/nginx/nginx.con文件,加入GeoIP的支持:

http {
    geoip_country  /etc/nginx/GeoIP.dat;
    geoip_city     /etc/nginx/GeoLiteCity.dat;
}

编辑django的fastcgi_param:

fastcgi_param GEOIP_COUNTRY_CODE $geoip_city_country_code;
fastcgi_param GEOIP_COUNTRY_CODE3 $geoip_country_code3;
fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;
fastcgi_param GEOIP_CITY_COUNTRY_CODE $geoip_city_country_code;
fastcgi_param GEOIP_CITY_COUNTRY_CODE3 $geoip_city_country_code3;
fastcgi_param GEOIP_CITY_COUNTRY_NAME $geoip_city_country_name;
fastcgi_param GEOIP_REGION $geoip_region;
fastcgi_param GEOIP_CITY $geoip_city;
fastcgi_param GEOIP_POSTAL_CODE $geoip_postal_code;
fastcgi_param GEOIP_CITY_CONTINENT_CODE $geoip_city_continent_code;
fastcgi_param GEOIP_LAT $geoip_latitude;
fastcgi_param GEOIP_LNG $geoip_longitude;

在Django的使用方法:

def index(request):
    return HttpResponse(request.META['GEOIP_COUNTRY_CODE'])

在CentOS 5.5上安装MongoDB

Thursday, July 1st, 2010

首先编辑/etc/yum.repos.d下的配置文件,我修改的是epel.repo,这个配置文件是我在安装OpenVPN的时候加入的,具体参见《CentOS VPS 安装 OpenVPN》。在配置文件中加入MongoDB的Repository地址:

[10gen]
name=10gen Repository
baseurl=http://downloads.mongodb.org/distros/centos/5.4/os/x86_64/
gpgcheck=0

然后执行:

yum update
yum install mongo-stable-server
/etc/init.d/mongod start

安装Ruby的驱动:

yum install mongo

Rubygem 缺少no such file to load zlib 错误

Tuesday, June 29th, 2010

在CentOS 5上使用源代码安装了ruby和gem,当使用gem更新的时候却提示no such file to load zlib的错误。下意识认为zlib的包没有安装好,重装了zlib和zlib-devel,但是在一台VPS中依然出现问题,搜了一下发现安装ruby源码中的zlib可以解决这个问题。

cd ext/zlib
ruby ./extconf.rb
make
make install

CentOS VPS 安装 OpenVPN

Wednesday, February 3rd, 2010

最近频繁在CentOS的VPS上安装OpenVPN,安装过程中还是颇有周折。首先是要和客服人员沟通开通TUN/TAP、iptables和NAT。有的VPS只开通iptables却没有NAT的支持,iptables设置postrouting的时候还是会失败。不管你在开通的时候怎么要求,VPS开通的时候还是要提交个ticket来处理这些事情。

默认CentOS的源里面只有很少的软件,需要安装EPEL(Extra Packages for Enterprise Linux),这样源里面的就有openvpn了。

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm

然后再执行安装openvpn的命令。

yum install openvpn

剩下的配置文件和别的一样,启动iptables的命令是:

#1.2.3.4改成VPS分配的Main IP
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to-source 1.2.3.4

这次要再评论photonvps.com一下,购买的VPS分配的IP被Google误认为是德国的IP,看Youtube的时候总是有些影片受限制,看hulu.com的时候就没有什么问题。跟他们沟通更换IP,最后到另外一台机器上新安装了一个VPS。觉得photonvps.com的服务还是不错,是值得推荐的一家VPS厂商。

—————————————————————————————–
杯具了,新换的IP被Google认为是法国的IP….