Tag: centos
CentOS 5.3 OpenVZ安装指南
by Elton on 十.27, 2009, under Linux
1. 安装宿主系统CentOS 5.3,分区的时候,要分一个/vz的ext3分区用来存放OpenVZ的template和Virtual Private Servers。 官方的建议是:
/ 2-4G
/swap 2倍物理内存
/vz 剩余的磁盘空间
2. 关掉FIrewall和SELinux
3. 安装OpenVZ
a) 从http://wiki.openvz.org/Download/kernel下载你操作系统对应的内核版本。 我这里用的是ovzkernel-2.6.18-128.2.1.el5.028stab064.7.i686.rpm
1 | rpm -ihv ovzkernel-2.6.18-128.2.1.el5.028stab064.7.i686.rpm |
b) 编辑GRUB Loader
/boot/grub/grub.conf
确保grub.conf文件的内容为:
1 2 3 4 | title OpenVZ (2.6.18-128.2.1.el5.028stab064.7)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-128.2.1.el5.028stab064.7 ro root=LABEL=/
initrd /boot/initrd-2.6.18-128.2.1.el5.028stab064.7.img |
c) 设置sysctl参数
/etc/sysctl.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 | # On Hardware Node we generally need # packet forwarding enabled and proxy arp disabled net.ipv4.ip_forward = 1 net.ipv4.conf.default.proxy_arp = 0 # Enables source route verification net.ipv4.conf.all.rp_filter = 1 # Enables the magic-sysrq key kernel.sysrq = 1 # TCP Explict Congestion Notification #net.ipv4.tcp_ecn = 0 # we do not want all our interfaces to send redirects net.ipv4.conf.default.send_redirects = 1 net.ipv4.conf.all.send_redirects = 0 |
使用下面的命令,使设置生效,之后重启系统。
1 | # sysctl -p |
c) 安装客户端工具
- vzctl: 这个工具是用来操作VPS的,如创建,销毁,开始,关闭和设置参数
- vzquota: 用于设定VPS的 quota
- vzpkg:这个工具用来管理 OpenVZ的 templates.
1 2 3 4 | rpm -Uhv vzyum-2.4.0-11.noarch.rpm rpm -Uhv vzquota-3.0.12-1.i386.rpm rpm -Uhv vzctl-3.0.23-1.i386.rpm rpm -Uhv vzpkg-2.7.0-18.noarch.rpm |
然后你就可以启动OpenVZ了
1 | /etc/init.d/vz start |
3.安装OpenVZ template
在这里下载你所需要的模板http://openvz.org/download/template/
先安装模板metadata,再使用vzpkgcache生成cache
或者直接在http://openvz.org/download/template/cache/下载已经cache过的模板,比如centos-5-x86_64.tar.gz ,不用解压,直接把它放到/vz/template/cache中。 然后使用下面的命令来生成虚机
1 | vzctl create 101 --ostemplate centos-5-x86 --config vps.basic |
create后面的数字是这个VPS的ID,每个VPS都要有一个唯一的ID来做标示。 可以使用ip的最后一位来做标示, 这样方便记忆。
VPS创建后,会在/vz/root/vpsid/生成一个目录作为它的私有空间.
为了便于设置,不必每个VPS都指定参数,创建的时候跟上了一个–config参数用于指定VPS的设置参数。 这些配置文件在/etc/sysconfig/vz-script中。 上面使用的就是/etc/sysconfig/vz-scripts/ve-vps.basic.conf-sample这个文件
你可以通过编辑/etc/sysconfig/vz文件的内容,来预先指定模板和配置文件,如:
1 2 | DEF_OSTEMPLATE="centos-5-x86" CONFIGFILE="vps.basic" |
这样就可以通过下面的命令快速建立VPS
1 2 3 4 5 6 | # vzctl create 101 Creating VPS private area: /vz/private/101 VPS is mounted Postcreate action done VPS is unmounted VPS private area was created |
4. 设置VPS
创建虚机后,使用下面命令来设置虚机的参数
1 2 3 4 | vzctl set 101 --hostname test101.my.org --save #设置主机名 vzctl set 101 --nameserver 202.96.209.5 --save #设置DNS vzctl set 101 --ipadd 172.1.1.101 --save #设置IP vzctl set 101 --userpasswd username:password #设置帐号 |
5. 启动和终止
a) 启动
1 | vzctl start 101 |
b)终止
1 | vzctl stop 101 |
c)查看状态
1 | vzctl status 101 |
d)查看所有虚机的资源占用情况
1 | cat /proc/vz/veinfo |
e) 查看所有虚机的状态
1 | vzlist -a |
6. 删除VPS
1 | vzctl destroy 101 |
CentOS环境中lighttpd+php+fastcgi+eAccelerator安装配置
by Elton on 六.21, 2009, under Linux, PHP
Lighttpd 作为新一代的web server,以小巧(不到1M的大小)、快速而著称,因为服务器上安装了rails、java,并以lighttpd为前端代理服务器,不想再部署apache了,所以直接使用lighttpd来部署,顺便看一下性能如何。
本文主要介绍在CentOS下,配置一套用lighttp作为web server的php环境
· 安装Lighttpd
从http://www.lighttpd.net/download/下载源码
安装前先检查pcre是否安装,需要pcre和pcre-devel两个包。 用yum search pcre*检查,如果都是installed就是都安装了。否则安装缺少的包。
1 2 3 4 5 | yum install pcre-devel tar xzvf lighttpd-1.4.23.tar.gz cd lighttpd-1.4.23 ./configure --prefix=/usr/local/lighttpd |
configure完毕以后,会给出一个激活的模块和没有激活模块的清单,可以检查一下,是否自己需要的模块都已经激活,在enable的模块中一定要有“mod_rewrite”这一项,否则重新检查pcre是否安装。然后编译安装:
1 | make && make install |
编译后配置:
1 2 3 | cp doc/sysconfig.lighttpd /etc/sysconfig/lighttpd mkdir /etc/lighttpd cp doc/lighttpd.conf /etc/lighttpd/lighttpd.conf |
如果你的Linux是RedHat/CentOS,那么:
1 | cp doc/rc.lighttpd.redhat /etc/init.d/lighttpd |
如果你的Linux是SuSE,那么:
1 | cp doc/rc.lighttpd /etc/init.d/lighttpd |
其他Linux发行版本可以自行参考该文件内容进行修改。然后修改/etc/init.d/lighttpd,把
1 | lighttpd="/usr/sbin/lighttpd" |
改为
1 | lighttpd="/usr/local/lighttpd/sbin/lighttpd" |
此脚本用来控制lighttpd的启动关闭和重起:
1 2 3 | /etc/init.d/lighttpd start /etc/init.d/lighttpd stop /etc/init.d/lighttpd restart |
如果你希望服务器启动的时候就启动lighttpd,那么:
1 | chkconfig lighttpd on |
这样lighttpd就安装好了,接下来需要配置lighttpd。
配置Lighttpd
修改/etc/lighttpd/lighttpd.conf
1)server.modules
取消需要用到模块的注释,mod_rewrite,mod_access,mod_fastcgi,mod_simple_vhost,mod_cgi,mod_compress,mod_accesslog是一般需要用到的。
2)server.document-root, server.error-log,accesslog.filename需要指定相应的目录
3)用什么权限来运行lighttpd
server.username = “nobody”
server.groupname = “nobody”
从安全角度来说,不建议用root权限运行web server,可以自行指定普通用户权限。
4)静态文件压缩
compress.cache-dir = “/tmp/lighttpd/cache/compress”
compress.filetype = (“text/plain”, “text/html”,”text/javascript”,”text/css”)
可以指定某些静态资源类型使用压缩方式传输,节省带宽,对于大量AJAX应用来说,可以极大提高页面加载速度。
5)配置ruby on rails
最简单的配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | $HTTP["host"] == "www.xxx.com" { server.document-root = "/yourrails/public" server.error-handler-404 = "/dispatch.fcgi" fastcgi.server = (".fcgi" => ("localhost" => ("min-procs" => 10, "max-procs" => 10, "socket" => "/tmp/lighttpd/socket/rails.socket", "bin-path" => "/yourrails/public/dispatch.fcgi", "bin-environment" => ("RAILS_ENV" => "production") ) ) ) } |
即由lighttpd启动10个FCGI进程,lighttpd和FCGI之间使用本机Unix Socket通信。
如果想指定www.abc.com以及所有二级域名,则需要把第一行改为
$HTTP[”host”] =~ “(^|.)abc.com” {
…
}
如果要设置代理,比如lighttpd和tomcat整合,tomcat放在lighttpd后面,则需要通过代理访问tomcat
$HTTP["host"] =~ “www.domain.cn” {
proxy.server = ( “” => ( “localhost” => ( “host”=> “127.0.0.1″, “port”=> 8080 ) ) )
}
则www.domain.cn为主机的网址都交给tomcat处理,tomcat的端口号为8080. 在tomcat的虚拟主机中,需要捕获www.domain.cn这个主机名,设置这个虚拟主机。这里的host都是跟tomcat里面的虚拟主机对应的。
· 安装支持fastcgi的PHP
安装PHP所需的相关类库
curl
1 2 3 4 5 6 7 | wget http://curl.cs.pu.edu.tw/download/curl-7.19.5.tar.bz2 tar xvjf curl-7.19.5.tar.bz2 cd curl-7.19.5 ./configure --prefix=/usr/local/curl make make install |
gettext
1 2 3 4 5 6 | wget ftp://ftp.ntu.edu.tw/pub/gnu/gnu/gettext/gettext-0.17.tar.gz tar xvzf gettext-0.17.tar.gz cd gettext-0.17 ./configure --prefix=/usr/local/gettext make make install |
zlib
1 2 3 4 5 | wget http://kent.dl.sourceforge.net/sourceforge/libpng/zlib-1.2.3.tar.gz tar xvzf zlib-1.2.3.tar.gz cd zlib-1.2.3 ./configure --prefix=/usr/local/zlib make && make install |
libpng
1 2 3 4 5 | wget http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/l/li/libpng/libpng-1.2.9.tar.gz tar xvzf libpng-1.2.9.tar.gz cd libpng-1.2.9 ./configure --prefix=/usr/local/libpng make && make install |
jpeg
1 2 3 4 5 6 7 8 9 10 11 12 13 | wget http://www.ijg.org/files/jpegsrc.v6b.tar.gz tar xvzf jpegsrc.v6b.tar.gz cd jpeg-6b/ ./configure --prefix=/usr/local/jpeg6 make mkdir /usr/local/jpeg6/bin mkdir -p /usr/local/jpeg6/bin mkdir -p /usr/local/jpeg6/man/man1 mkdir -p /usr/local/jpeg6/lib mkdir -p /usr/local/jpeg6/include make install-lib make install |
freetype
1 2 3 4 5 6 | wget http://download.savannah.gnu.org/releases/freetype/freetype-2.3.9.tar.gz tar xvzf freetype-2.3.9.tar.gz cd freetype-2.3.9 ./configure --prefix=/usr/local/freetype2 make make install |
gd
1 2 3 4 5 6 7 | wget http://www.libgd.org/releases/gd-2.0.35.tar.gz tar xvzf gd-2.0.35.tar.gz cd gd-2.0.35 ./configure --prefix=/usr/local/gd2 --with-zlib=/usr/local/zlib/ --with-png=/usr/local/libpng/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype2/ make 如果第一次make出错,试着再make一次,我就是这样,第二次就对了。 make install |
PHP
1 2 3 4 5 6 7 8 | tar xvzf php-5.2.10.tar.gz cd php-5.2.10 ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-jpeg-dir=/usr/local/jpeg6/ --with-png-dir=/usr/local/libpng/ --with-gd=/usr/local/gd2/ --with-freetype-dir=/usr/local/freetype2/ --with-zlib-dir=/usr/local/zlib --with-curl=/usr/local/curl --with-gettext=/usr/local/gettext --enable-fastcgi --enable-zend-multibyte --with-config-file-path=/etc --enable-discard-path --enable-force-cgi-redirect make make install cp php.ini-dist /etc/php.ini 可以使用php -m查看你安装的模块 |
eAccelerator
eAccelerator是一个开源的PHP加速器
1 2 3 4 5 6 7 8 | wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2 tar xjvf eaccelerator-0.9.5.3.tar.bz2 cd eaccelerator-0.9.5.3 export PHP_PREFIX="/usr/local/php" $PHP_PREFIX/bin/phpize ./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config make make install |
执行好后,会提示安装到的路径,下面会用到,如我的被安装到这里
/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613
编辑php.ini中的内容
vim /etc/php.ini
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | cgi.fix_pathinfo = 1 zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so" eaccelerator.shm_size="16" eaccelerator.cache_dir="/tmp/eaccelerator" eaccelerator.enable="1" eaccelerator.optimizer="1" eaccelerator.check_mtime="1" eaccelerator.debug="0" eaccelerator.filter="" eaccelerator.shm_max="0" eaccelerator.shm_ttl="0" eaccelerator.shm_prune_period="0" eaccelerator.shm_only="0" eaccelerator.compress="1" eaccelerator.compress_level="9" |
如果一切顺利,你可以通过下面命令来验证是否安装成功
1 2 3 4 5 | $ php -v PHP 5.2.10 (cli) (built: Jun 20 2009 23:32:09) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies with eAccelerator v0.9.5.3, Copyright (c) 2004-2006 eAccelerator, by eAccelerator |
修改/etc/lighttpd/lighttpd.conf文件,添加下面的配置
vim /etc/lighttpd/lighttpd.conf
1 2 3 4 5 6 7 8 | fastcgi.server = ( ".php" => ( "localhost" => ( "socket" => "/tmp/php-fastcgi.socket", "bin-path" => "/usr/local/php/bin/php-cgi" ) ) ) |
重启lighttpd
1 | /etc/init.d/lighttpd restart |
写一个php测试文件在lighttpd的网站目录里,测试php是否安装成功
CentOS 5.3安装Nagios
by Elton on 六.02, 2009, under Linux
***********************************************
安装软件
***********************************************
确保以下包都被安装
yum install gcc
yum install glibc glibc-common
yum install gd gd-devel
成为root用户
su -l
创建Nagios用户
/usr/sbin/useradd -m nagios
passwd nagios
创建Nagios用户组并把nagios用户和apache用户加入到这个组里
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd apache
创建下载目录
mkdir ~/downloads
cd ~/downloads
下载文件
wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nagios-3.0.6.tar.gz
wget http://osdn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.11.tar.gz
解压源文件
cd ~/downloads
tar xzf nagios-3.0.6.tar.gz
cd nagios-3.0.6
运行配置脚本,指定用户组
./configure –with-command-group=nagcmd –with-httpd-conf=/usr/local/apache/conf
编译
make all
安装
make install
make install-init
make install-config
make install-commandmode
一些配置可以在这里修改
vi /usr/local/nagios/etc/objects/contacts.cfg
安装Apache的web配置文件到Apache的配置目录.
make install-webconf
创建web界面管理员
/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
重启apache使配置生效
/usr/local/apache/bin/apachectl restart
***********************************************
安装插件
***********************************************
cd ~/downloads
tar xzf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
配置编译
./configure –with-nagios-user=nagios –with-nagios-group=nagios
make
make install
如果make的时候出现openssl的错误,需要在make的时候加上
make LDFLAGS+=-ldl(http://yahoon.blog.51cto.com/13184/43020)
将Nagios加到系统启动列表中
chkconfig –add nagios
chkconfig nagios on
验证配置文件正确性
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果没有问题,就启动
service nagios start
然后通过
http://localhost/nagios就可以访问了
***********************************************
安装NRPE
***********************************************
监控主机需要安装check_nrpe,被监控机器需要安装nrpe。他们需要通SSH连接,使用5666端口通信
被监控机器安装
创建帐号
/usr/sbin/useradd nagios
passwd nagios
安装Nagios插件
wget http://osdn.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.13.tar.gz
tar xzf nagios-plugins-1.4.13.tar.gz
cd nagios-plugins-1.4.13
./configure
make
make install
yum install xinetd
wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
tar xzf nrpe-2.8.tar.gz
cd nrpe-2.8
./configure
make all
安装插件(为了测试),守候进程和示例配置文件
make install-plugin
make install-daemon
make install-daemon-config
安装xinetd的NRPE服务
make install-xinetd
编辑 /etc/xinetd.d/nrpe 文件在 only_from 后加入监控主机的ip.
only_from = 127.0.0.1 <nagios_ip_address>
在/etc/services加入下面的条目
nrpe 5666/tcp # NRPE
重启Xinetd
service xinetd restart
本地测试
netstat -at | grep nrpe
会显示
tcp 0 0 *:nrpe *:* LISTEN
/usr/local/nagios/libexec/check_nrpe -H localhost
会显示nrpe的版本信息
打开防火墙
iptables -I RH-Firewall-1-INPUT -p tcp -m tcp –dport 5666 -j ACCEPT
service iptables save
监控主机安装
安装 check_nrpe 插件
wget http://osdn.dl.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
tar xzf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
测试NRPE守候进程
/usr/local/nagios/libexec/check_nrpe -H 192.168.0.1(被监控端的ip)
将会返回被监控端的nrpe版本信息


