Centos 5.5(Dell R610)安装Nginx 0.8、MySQL、php 5.3.4、Nagios监控
远程链接工具Puttp,下载地址http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe
第一步,修改SSH配置
vi /etc/ssh/sshd_config
将PermitRootLogin yes修改为PermitRootLogin no禁止root用户远程登录,提高系统安全性。
重新启动sshd
/sbin/service sshd restart 或者 /etc/init.d/sshd restart
第二步:安装基础软件
这些软件是系统所需要的基础软件,执行前请确保已经联网。
sudo -s LANG=C yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
顺手更新下系统
yum update
喝杯水,看着屏幕,一路yes。需要配置成国内的dns,使用163的centos源,安装速度比较快。
第三步:安装附加软件,下载地址请自己Google。
内部同事请修改host,
vi /etc/hosts
添加 192.168.1.3 svn.xxx.cn。
然后
cd /app svn co svn://svn.xxx.cn/xxx/server/trunk software cd software
1、安装iconv库,干嘛用的请google
tar zxvf libiconv-1.13.tar.gz cd libiconv-1.13/ ./configure --prefix=/usr/local make make install cd ../
2、安装mcrypt库
tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8/ ./configure make make install /sbin/ldconfig cd libltdl/ ./configure --enable-ltdl-install make make install cd ../../
3、安装mhash
tar zxvf mhash-0.9.9.9.tar.gz cd mhash-0.9.9.9/ ./configure make make install cd ../
4、建立软链接
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4 ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8 ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2 ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1 ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
5、安装mcrypt
tar zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8/ /sbin/ldconfig ./configure make make install cd ../
6、安装ImageMagick
tar zxf ImageMagick.tar.gz cd ImageMagick-6.5.1-2/ ./configure make make install cd ../
7、安装libevent
tar xf libevent-1.4.14b-stable.tar.gz cd libevent-1.4.14b-stable ./configure --prefix=/usr make make install cd ..
8、安装memcached
tar xf memcached-1.4.5.tar.gz cd memcached-1.4.5 ./configure --with-libevent=/usr make make install cd ..
以11211端口启动Memcached
/usr/local/bin/memcached -d -p 11211 -u nobody -m 2048 -c 10240 -P /var/run/memcached/memcached.pid
第四步:安装MySQL
1、添加MYSQL用户
/usr/sbin/groupadd mysql /usr/sbin/useradd -g mysql mysql
2、安装MySQL
tar xf mysql-5.1.50.tar.gz cd mysql-5.1.50/ ./configure --prefix=/app/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrg make && make install
3、更改文件权限
chmod +w /app/mysql chown -R mysql:root /app/mysql
4、创建配置文件和启动服务
cp support-files/my-huge.cnf /etc/my.cnf cp support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld
5、初始化数据库
/app/mysql/bin/mysql_install_db --user=mysql
6、启动数据库
cd ../ /sbin/service mysqld start
第五步:安装PHP 5.3.4
1、安装php主程序
tar xf php-5.3.4.tar.gz cd php-5.3.4 ./configure --prefix=/app/php --with-config-file-path=/app/php/etc --with-mysql=/app/mysql --with-pdo-mysql=/app/mysql/ --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --enable-ftp make ZEND_EXTRA_LIBS='-liconv' make install cp php.ini-production /app/php/etc/php.ini cd ../
2、安装memcache扩展
tar zxvf memcache-2.2.6.tgz cd memcache-2.2.6/ /app/php/bin/phpize ./configure --with-php-config=/app/php/bin/php-config make make install cd ../
3、安装imagick扩展
tar zxvf imagick-3.0.1.tgz cd imagick-3.0.1/ /app/php/bin/phpize ./configure --with-php-config=/app/php/bin/php-config make make install cd ../
4、安装xcache扩展
tar xf xcache-1.3.1.tar.gz cd xcache-1.3.1 /app/php/bin/phpize ./configure --enable-xcache --with-php-config=/app/php/bin/php-config make make install cd ../
5、修改php.ini文件 /app/etc/php.ini
extension_dir = "/app/php/lib/php/extensions/no-debug-non-zts-20090626/" extension = "memcache.so" extension = "imagick.so" short_open_tag = On memory_limit = 512M expose_php = Off
6、启动PHP FPM
ulimit -SHn 65535 /app/php/sbin/php-fpm
可以用 ps aux|grep php来验证下是否已经启动php-fpm
第六步:安装Nginx
1、安装PCRE
tar zxvf pcre-8.01.tar.gz cd pcre-8.01/ ./configure make && make install cd ../
2、安装openssl
tar zxvf ./openssl-0.9.8l.tar.gz cd ./openssl-0.9.8l ./config enable-tlsext make make install cd ..
3、安装Nginx
tar zxvf nginx-0.8.50.tar.gz cd nginx-0.8.50/ ./configure --user=nobody --group=nobody --prefix=/app/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-openssl=../openssl-0.9.8l/ --with-openssl-opt="enable-tlsext" make && make install cd ../
4、启动Nginx
ulimit -SHn 65535 /app/nginx/sbin/nginx
5、创建日志切割脚本
vi /app/nginx/sbin/cut_nginx_log.sh
添加内容如下
#!/bin/bash
# This script run at 00:00
# The Nginx logs path
logs_path="/app/nginx/logs/"
mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat /app/nginx/logs/nginx.pid`用Crontab使其每日凌晨自动运行
crontab -e
添加内容
00 00 * * * /bin/bash /app/nginx/sbin/cut_nginx_log.sh
第七步:优化系统
1、修改/etc/sysctl.conf文件,添加下列内容到文件末尾
# Add net.ipv4.tcp_max_syn_backlog = 65536 net.core.netdev_max_backlog = 32768 net.core.somaxconn = 32768 net.core.wmem_default = 8388608 net.core.rmem_default = 8388608 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_synack_retries = 2 net.ipv4.tcp_syn_retries = 2 net.ipv4.tcp_tw_recycle = 1 #net.ipv4.tcp_tw_len = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_mem = 94500000 915000000 927000000 net.ipv4.tcp_max_orphans = 3276800 #net.ipv4.tcp_fin_timeout = 30 #net.ipv4.tcp_keepalive_time = 120 net.ipv4.ip_local_port_range = 1024 65535
使之立即生效
/sbin/sysctl -p
第八步:安装ntp进行时间同步
yum install ntp /usr/sbin/ntpdate 0.pool.ntp.org
下面进行ntp内网服务器的配置,注意非服务器不用执行下面的步骤
1、修改ntp配置文件
vi /etc/ntp.conf
# Hosts on local network are less restricted. restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap #去掉前面的注释,允许内网其他机器访问服务器。
2、vi /etc/ntp/step-tickers
#添加国际标准时间服务器 0.pool.ntp.org 1.pool.ntp.org 2.pool.ntp.org
3、启动NTPD时间服务器
/sbin/service ntpd start /sbin/chkconfig ntpd on
第九步,安装Nagios监控
被监控机(即被监测服务器,非监测服务器,一般web服务器都是被监测的对象。)
1、添加用户
/usr/sbin/groupadd nagios /usr/sbin/useradd -g nagios -d /app/nagios -s /sbin/nologin nagios
2、安装plugin
tar zxf nagios-plugins-1.4.15.tar.gz cd nagios-plugins-1.4.15 ./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/app/nagios --with-ping-command="/bin/ping" --with-mysql=/app/mysql --enable-perl-modules make make install cd ..
3、安装Nrpe
tar zxvf nrpe-2.12.tar.gz cd nrpe-2.12 ./configure --prefix=/app/nagios make all make install-plugin make install-daemon make install-daemon-config chown -R nagios:nagios /app/nagios
4、配置Nagios,即允许哪个服务器访问
vi /app/nagios/etc/nrpe.cfg allowed_hosts=127.0.0.1,192.168.11.110
修改/etc/hosts.allow增加监控机ip
echo 'nrpe:192.168.1.110' >> /etc/hosts.allow
5、启动 NRPE 守护进程:
/app/nagios/bin/nrpe -c /app/nagios/etc/nrpe.cfg -d
可以将此命令加入 /etc/rc.local ,以便开机自动启动。
echo "/app/nagios/bin/nrpe -c /app/nagios/etc/nrpe.cfg -d" >> /etc/rc.local
检查 NRPE 是否正常: 在被监控机上
/app/nagios/libexec/check_nrpe -H 127.0.0.1
查看相应的端口:netstat -an |grep 5666
防火墙开启5666 允许局域网IP或固定IP连接
在监控主机上
/app/nagios/libexec/check_nrpe -H $目标主机地址
都应该可以输出 NRPE 的版本: NRPE v2.12
检查可监控的服务
在被监控端的 nrpe.cfg 文件中,可以看到这样的配置:
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
这是用来检查 CPU 负载的。
如果需要自定参数则使用下面命令
command[check_load]=/usr/local/nagios/libexec/check_load -w $ARG1$ -c $ARG2$
并开启dont_blame_nrpe =1
开启参数将会带来一定的安全风险
附:
创建用户
/usr/sbin/useradd somebody passwd somebody
修改DNS
vi /etc/resolv.conf
去除所有内容
添加
nameserver 202.96.209.5
关闭防火墙命令
/sbin/service iptables stop 或者 /etc/init.d/iptables stop
重启网络‘
/sbin/service network restart
重新安装Dell R610网卡驱动,系统自带的驱动和网卡硬件不兼容,在高负载下网卡会停止运行
tar xf Bcom_LAN_14.1.5_Linux_Source_A00.tar.gz cd Bcom_LAN_14.1.5_Linux_Source_A00/NetXtremeII/ rpm -ivh netxtreme2-5.0a.10-1.src.rpm cd /usr/src/redhat/ rpmbuild -bb SPECS/netxtreme2.spec rpm -ivh RPMS/x86_64/netxtreme2-5.0a.10-1.x86_64.rpm cd /app/software/Bcom_LAN_14.1.5_Linux_Source_A00 echo "/sbin/rmmod bnx2;/sbin/modprobe bnx2;" > lan_dr_up.sh chmod +x lan_dr_up.sh ./lan_dr_up.sh &
安装并启动Rsync
为磁盘同步做准备
/usr/bin/rsync --daemon echo "/usr/bin/rsync --daemon" >> /etc/rc.local




