zabbix nginx php mariadb安装
mariadb编译安装1,现在源码包这里用的 mariadb-10.0.15.tar.gz 解压
下载地址http://mirrors.neusoft.edu.cn/ma ... iadb-10.0.15.tar.gz
1
2
3
4
5
# ls
mariadb-10.0.15.tar.gz
# tar xf mariadb-10.0.15.tar.gz
# ls
mariadb-10.0.15mariadb-10.0.15.tar.gz
2,安装编译工具cmake gcc
1
# yum -y install ncurses-devel gcc camke openssl-devel gcc-c++
查看编译选项和配置编译选项
1
# ccmake .
编译
1
# cmake .
如果编译缺少依赖的开发包,可看提示安装,然后删除CMakeCache.txt重新编译
1
# make && make install
make的界面挺漂亮的
3,添加mysql用户
1
# useradd -r mysql
4,创建数据目录
1
# mkdir -pv /data/mariadb
5,改权限
1
2
3
4
# chown -R root.mysql /usr/local/mysql
# chown -R mysql.mysql /data/mariadb
# chmod -R640 /data/mariadb
#
6,提供配置文件和启动脚本
1
2
3
4
5
6
7
# cp support-files/my-innodb-heavy-4G.cnf /etc/my.cnf
# cp support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
# chkconfig --list mysqld
mysqld 0:off1:off2:on3:on4:on5:on6:off
7,初始化mysql
1
2
3
4
5
6
7
# cd /usr/local/mysql
# scripts/mysql_install_db--user=mysql --datadir=/data/mariadb --skip-name-resolve --basedir=/usr/local/mysql
# service mysqld start
Starting MySQL. SUCCESS!
# cat /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
#
php编译安装
1,下载源码包并解压
http://cn2.php.net/distributions/php-5.6.4.tar.bz2
1
# tar xf php-5.6.4.tar.bz2
安装编译依赖
1
2
3
#yum -y install gcclibcurl-devel bzip2-devellibxml2-devel mhash-devel libmcrypt-devel gd-devel bcmath-devel openssl-devel
# ./configure --prefix=/usr/local/php--with-openssl --enable-fpm --enable-sockets --enable-sysvshm--enable-mbstring --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=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --with-bz2 --with-curl --enable-bcmath--with-gd--with-gettext --with-mysql=mysqlnd --with-mysqli=mysqlnd
# make && make install
2,为php提供配置文件
1
# cp php.ini-production /etc/php.ini
为php-fpm提供Sysv init脚本,并将其添加至服务列表:
1
2
3
4
# 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提供配置文件:
1
# 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文件(如下最后一行):
1
2
3
4
5
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了:
1
# service php-fpm start
使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
1
# ps aux | grep php-fpm
五、安装xcache,为php加速:
1、安装
1
2
3
4
5
# 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
安装结束时,会出现类似如下行:
1
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
2、编辑php.ini,整合php和xcache:
首先将xcache提供的样例配置导入php.ini
1
2
# mkdir /usr/local/php/etc/php.d
# cp xcache.ini /usr/local/php/etc/php.d
说明:xcache.ini文件在xcache的源码目录中。
接下来编辑/usr/local/php/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行:
zend_extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。
3、重新启动php-fpm
1
# service php-fpm restart
nginx编译安装
首先添加用户nginx,实现以之运行nginx服务进程
1
2
# groupadd -r nginx
# useradd -r -g nginx nginx
1,下载源码包并解压
http://nginx.org/download/nginx-1.6.2.tar.gz
1
2
3
4
5
# ls
mariadb-10.0.15mariadb-10.0.15.tar.gznginx-1.6.2nginx-1.6.2.tar.gz
# cd nginx-1.6.2
# ls
autoCHANGESCHANGES.ruconfconfigurecontribhtmlLICENSEmanREADMEsrc
2,可用./configure --help 查看编译选项
1
2
3
4
5
6
7
8
# ./configure --help
--help print this message
--prefix=PATH set installation prefix
--sbin-path=PATH set nginx binary pathname
--conf-path=PATH set nginx.conf pathname
--error-log-path=PATH set error log pathname
--pid-path=PATH set nginx.pid pathname
--lock-path=PATH set nginx.lock pathname
编译,根据提示安装devel包
1
2
3
# yum -y install pcre-devel
# ./configure --prefix=/usr/local/nginx --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-pcre
# make && make install
3、为nginx提供SysV init脚本:
新建文件/etc/rc.d/init.d/nginx,内容如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/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/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=([^ ]*).*//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 2
esac
而后为此脚本赋予执行权限:
1
# chmod +x /etc/rc.d/init.d/nginx
添加至服务管理列表,并让其开机自动启动:
1
2
# chkconfig --add nginx
# chkconfig nginx on
而后就可以启动服务并测试了:
1
# service nginx start
四、整合nginx和php5
1、编辑/etc/nginx/nginx.conf,启用如下选项:
1
2
3
4
5
6
7
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
include fastcgi_params;
}
2、编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fastcgi_paramGATEWAY_INTERFACECGI/1.1;
fastcgi_paramSERVER_SOFTWARE nginx;
fastcgi_paramQUERY_STRING $query_string;
fastcgi_paramREQUEST_METHOD $request_method;
fastcgi_paramCONTENT_TYPE $content_type;
fastcgi_paramCONTENT_LENGTH $content_length;
fastcgi_paramSCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_paramSCRIPT_NAME $fastcgi_script_name;
fastcgi_paramREQUEST_URI $request_uri;
fastcgi_paramDOCUMENT_URI $document_uri;
fastcgi_paramDOCUMENT_ROOT $document_root;
fastcgi_paramSERVER_PROTOCOL $server_protocol;
fastcgi_paramREMOTE_ADDR $remote_addr;
fastcgi_paramREMOTE_PORT $remote_port;
fastcgi_paramSERVER_ADDR $server_addr;
fastcgi_paramSERVER_PORT $server_port;
fastcgi_paramSERVER_NAME $server_name;
并在所支持的主页面格式中添加php格式的主页,类似如下:
1
2
3
4
location / {
root html;
indexindex.php index.html index.htm;
}
而后重新载入nginx的配置文件:
1
# service nginx reload
3、在/usr/html新建index.php的测试页面,测试php是否能正常工作:
1
# echo "" > index.php
编译安装zabbix
下载地址:http://www.zabbix.com/download.php
1
# tar -zxvf zabbix-2.4.3.tar.gz
创建用户:
1
2
# groupadd zabbix
# useradd -g zabbix zabbix
注意:同时安装了server和agent的节点上,建议其运行用户不要相同。
创建数据库:
server和proxy的运行都依赖于数据库,agent则不需要。
以MySQL数据库为例:
1
2
mysql> CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
mysql> GRANT ALL ON zabbix.* TO zbuser@'%' IDENTIFIED BY 'zbpass';
# 请按需要修改用户名和密码;
1
shell> mysql -u -p zabbix < database/mysql/schema.sql
# 如果仅为proxy创建数据库,只导入schema.sql即可;否则,请继续下面的步骤;
1
2
shell> mysql -u -p zabbix < database/mysql/images.sql
shell> mysql -u -p zabbix < database/mysql/data.sql
编译安装zabbix:
同时安装server和agent,并支持将数据放入mysql数据中,可使用类似如下配置命令:
1
./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-ssh2
如果仅安装server,并支持将数据放入mysql数据中,可使用类似如下配置命令:
1
./configure --enable-server --with-mysql --with-net-snmp --with-libcurl
如果仅安装proxy,并支持将数据放入mysql数据中,可使用类似如下配置命令:
1
./configure --prefix=/usr --enable-proxy --with-net-snmp --with-mysql --with-ssh2
如果仅安装agent,可使用类似如下配置命令:
1
./configure --enable-agent
而后编译安装zabbix即可:
1
2
# make
# make install
复制zabbix前端页面
1
# cp -a /usr/local/src/zabbix-2.4.3/frontends/php /usr/loca/nginx/html/zabbix
复制windows下的字体,不然显示不了中文
控制面板-->字体 复制简体中文到下面的目录,并改名
1
2
3
4
5
6
7
8
# cd /usr/local/nginx/html/zabbix/fonts
# ls
DejaVuSans.ttfsimkai.ttf
# mv DejaVuSans.ttf DejaVuSans.ttf.bak
# mv simkai.ttf DejaVuSans.ttf
# vim /etc/default/locale
#File generated by update-locale
LANG=zh_CN.UTF-8
安装中文包
修改zabbix配置文件
1
2
3
4
5
6
7
root@node144 src]# vim /usr/local/zabbix/etc/zabbix_server.conf
DBHost=127.0.0.1#连接数据库的主机
DBName=zabbix
DBUser=zabbix
DBPassword=redhat
AlertScriptsPath=${datadir}/zabbix/alertscripts#报警脚本的路径,有时候脚本不能报警可修改
ExternalScripts=${datadir}/zabbix/externalscripts
现在的版本可以看到哪个进程是干嘛用的
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# ps -ef|grep zabbix_ser
zabbix 37952 10 22:20 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server
zabbix 38142 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: configuration syncer
zabbix 38143 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: db watchdog
zabbix 38144 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #1
zabbix 38145 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #2
zabbix 38147 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #3
zabbix 38149 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #4
zabbix 38151 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: poller #5
zabbix 38153 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: unreachable poller #1
zabbix 38155 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #1
zabbix 38157 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #2
zabbix 38159 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #3
zabbix 38161 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #4
zabbix 38163 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: trapper #5
zabbix 38164 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: icmp pinger #1
zabbix 38166 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: alerter
zabbix 38167 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: housekeeper
zabbix 38169 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: timer #1
zabbix 38170 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: http poller #1
zabbix 38172 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: discoverer #1
zabbix 38174 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: history syncer #1
zabbix 38176 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: history syncer #2
zabbix 38178 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: history syncer #3
zabbix 38180 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: history syncer #4
zabbix 38182 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: escalator
zabbix 38184 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: proxy poller #1
zabbix 38186 379520 22:21 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_server: self-monitoring
启动不了记得看日志
都ok了才能下一步
连接数据库的配置
页:
[1]