系统环境
$ cat /etc/issue
CentOS release 6.6 (Final)
$ uname -rs
Linux 2.6.32-504.23.4.el6.centos.plus.x86_64
下载所需要的源码包
wget -c http://cn2.php.net/get/php-5.6.5.tar.gz/from/this/mirror
wget -c http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz
wget -c http://mirrors.ustc.edu.cn/mariadb/mariadb-10.0.16/bintar-linux-x86/mariadb-10.0.16-linux-i686.tar.gz
http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.4.3/zabbix-2.4.3.tar.gz
解决依赖关系
yum groupinstall "Server Platform Development" ,"Development tools"
yum -y install pcre-devel
部署LNMP
一、安装Nginx:
tar xf nginx-1.6.2.tar.gz
cd nginx-1.6.2
首先添加用户nginx,实现以之运行nginx服务进程:
# groupadd -r nginx
# useradd -r -g nginx nginx
接着开始编译和安装:
# ./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-http_spdy_module \
--with-http_realip_module \
--with-http_auth_request_module \
--with-file-aio \
--with-pcre
# make && make install
为nginx提供SysV init脚本:
新建文件/etc/rc.d/init.d/nginx,内容如下:
#!/bin/sh
## nginx - this script starts and stops the nginx daemon
## chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx# pidfile: /var/run/nginx.pid
# Source function library.. /etc/rc.d/init.d/functions
# Source networking configuration.. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return
$retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2esac
而后为此脚本赋予执行权限:
# chmod +x /etc/rc.d/init.d/nginx
添加至服务管理列表,并让其开机自动启动:
# chkconfig --add nginx# chkconfig nginx on
而后就可以启动服务并测试了:
# service nginx start
二:安装MariaDB
1、准备数据存放目录mkdir /mydata/data
2、建用户以安全方式运行进程:groupadd -r mysqluseradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysqlchown -R mysql:mysql /mydata/data
3、安装并初始化mariadb-10.0.15
tar xf mariadb-10.0.15-linux-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -sv /usr/local/mariadb-10.0.15-linux-x86_64 /usr/local/mysql
cd /usr/local/mysql
chown -R mysql:mysql
.scripts/mysql_install_db --user=mysql --datadir=/mydata/data
4、为mysql提供主配置文件:cp support-files/my-large.cnf /etc/my.cnf
并修改此文件中thread_concurrency的值为你的CPU个数乘以2,
比如这里使用如下行:thread_concurrency = 8
另外还需要添加如下行指定mysql数据文件的存放位置:datadir = /mydata/data
5、为mysql提供sysv服务脚本:
# cd /usr/local/mysql# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
添加至服务列表:# chkconfig --add mysqld# chkconfig mysqld on 而后就可以启动服务测试使用了。
为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:
6、输出mysql的man手册至man命令的查找路径: 编辑/etc/man.config,添加如下行即可:MANPATH /usr/local/mysql/man
7、输出mysql的头文件至系统头文件路径/usr/include: 这可以通过简单的创建链接实现:
# ln -sv /usr/local/mysql/include /usr/include/mysql
8、输出mysql的库文件给系统库查找路径: # echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf 而后让系统重新载入系统库:# ldconfig 9、修改PATH环境变量,让系统可以直接使用mysql的相关命令。
# vim /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
三、安装php-5.6.5解决依赖关系
yum install libjpeg-turbo-devel libmcrypt-devel -y
tar xf php-5.6.5.tar.gzcd php-5.6.5
./configure --prefix=/usr/local/php \
--with-mysql=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-openssl \
--enable-fpm \
--enable-sockets \
--enable-sysvshm \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-libxml-dir=/usr \
--enable-xml \
--with-mhash \
--with-mcrypt \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2 --with-curl \
--enable-bcmath \
--enable-mbstring \
--with-gd
make && make install
为php提供配置文件:
# cp php.ini-production /etc/php.ini
为php-fpm提供Sysv init脚本,并将其添加至服务列表:
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
为php-fpm提供配置文件:
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
编辑php-fpm的配置文件:
# vim /usr/local/php/etc/php-fpm.conf
配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行):
pm.max_children = 150
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pid = /usr/local/php/var/run/php-fpm.pid
接下来就可以启动php-fpm了:
# service php-fpm start
使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
# ps aux | grep php-fpm整合nginx和php51、
编辑/etc/nginx/nginx.conf,
启用如下选项:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
2、编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容:
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
并在所支持的主页面格式中添加php格式的主页,类似如下:
location / {
root html;
index index.php index.html index.htm;
}
而后重新载入nginx的配置文件:
# service nginx reload
3、在/usr/html新建index.php的测试页面,测试php是否能正常工作:
# cat > /usr/local/nginx/html/index.php << EOF
<?php
phpinfo();
?>
接着就可以通过浏览器访问此测试页面了。
安装xcache,为php加速:
1、安装
# tar xf xcache-2.0.0.tar.gz
# cd xcache-2.0.0
# /usr/local/php/bin/phpize
# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
# make && make install
安装结束时,会出现类似如下行:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
2、编辑php.ini,整合php和xcache:
首先将xcache提供的样例配置导入php.ini
# mkdir /etc/php.d
# cp xcache.ini /etc/php.d
说明:xcache.ini文件在xcache的源码目录中。
接下来编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行:
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
或者:cp /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so xcache.so /usr/local/php/include/php/ext/.
注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。
3、重新启动php-fpm
# service php-fpm restart
补充说明
如果要在SSL中使用php,需要在php的location中添加此选项:
fastcgi_param HTTPS on;
部署安装zabbix
# tar xf zabbix-2.4.3.tar.gz
创建用户:
# groupadd zabbix
# useradd -g zabbix zabbix
# cd zabbix-2.4.3
创建数据库:
server和proxy的运行都依赖于数据库,agent则不需要。
以MySQL数据库为例:
# mysql> CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
# mysql> GRANT ALL ON zabbix.* TO zabbix@'10.15.%.%' IDENTIFIED BY 'zabbix';
# 请按需要修改用户名和密码;
# mysql -h10.15.201.104 -uzabbix -pzabbix zabbix < database/mysql/schema.sql
# 如果仅为proxy创建数据库,只导入schema.sql即可;否则,请继续下面的步骤;
# mysql -h10.15.201.104 -uzabbix -pzabbix zabbix < database/mysql/images.sql
# mysql -h10.15.201.104 -uzabbix -pzabbix zabbix < database/mysql/data.sql
编译安装zabbix:
# yum install net-snmp net-snmp-devel libssh2-devel
同时安装server和agent,并支持将数据放入mysql数据中,可使用类似如下配置命令:
./configure\
--prefix=/usr/local/zabbix \
--enable-server --enable-agent \
--with-mysql --enable-ipv6 \
--with-net-snmp --with-libcurl \
--with-ssh2 --with-libxml2
./configure\
--prefix=/usr/local/zabbix \
--enable-agent \
--sysconfdir=/etc/zabbix
# make && make install
配置zabbix:
server的配置文件为zabbix_server.conf,至少应该为其配置数据库等相关的信息;
agent的配置文件为zaabix_agentd.conf,至少应该为其指定server的IP地址;
proxy的配置文件为zabbix_proxy.conf,至少应该为其指定proxy的主机名和server的IP,以及数据库等相关的配置信息;
cd /usr/local/zabbix/etc
vim zabbix_server.conf
DBHost=10.15.201.104
DBName=zabbix
DBUser=zabbix
StartDiscoverers=3
CacheSize=64M
vim zabbix_agentd.conf
Server=10.15.201.104
EnableRemoteCommands=1 #执行远程命令
UnsafeUserParameters=1 #允许在自定义参数中使用所有特殊字符
ServerActive=10.15.201.104 #指定Server端的IP
Hostname=10.15.201.104 #最好使用agent节点的IP
cp misc/init.d/fedora/core/zabbix_* /etc/init.d/
chmod +x /etc/init.d/zabbix_*
chkconfig --add zabbix_agentd
chkconfig --add zabbix_server
vim /etc/init.d/zabbix_server
BASEDIR=/usr/local/zabbix
vim /etc/init.d/zabbix_agentd
BASEDIR=/usr/local/zabbix
cd /opt/zabbix-2.4.3
cp -a frontends/php/* /usr/local/nginx/html/zabbix/
需要修改php.ini 并重启php-fpm
# vim /etc/php.ini
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Asia/Shanghai
always_populate_raw_post_data = 1
cd /opt/php-5.6.5/ext/gettext
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
mkae && make install
vim /etc/php.ini
extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/gettext.so
注意:
zabbix优化
1. CacheSize=64M 增大缓存
2. StartDiscoverers=3 该值默认为1 如不调大该值则会一直报警Zabbix discoverer processes more than 75% busy
3. 将zabbix的 Template App Zabbix Agent 模版中的 Item "Agent ping" 的 Store value 和 Show value 两个值得类型都调整为"As is",否则会报"Zabbix agent on is unreachable for 2 minutes"