本文描述zabbix在lnmp环境中的搭建过程,为减少配置难度,mysql,php采用yum安装。系统版本是centos6.4。
本安装过程以直接高效的方式叙述。
1、Yum安装mysql
mysql使用yum安装方式
yum install mysql-servermysql-devel mysql
/etc/init.d/mysqld start
2、Yum安装php
yum安装后的php配置文件是/etc/php.ini。
yum install -y php php-mysqlphp-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpcphp-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel php-fpm
sed -i 's/^user =.*/user =nginx/g' /etc/php-fpm.d/www.conf
sed -i 's/^group =.*/group =nginx/g' /etc/php-fpm.d/www.conf
/etc/init.d/php-fpm start
3、编译安装nginx
3.1 安装pcre
nginx安装需要pcre的支持。
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gz
yum install gcc* #解决编译无gcc包问题
tar -zxf pcre-8.33.tar.gz
cd pcre-8.33
./configure
echo $?
make && make install
3.2 安装nginx
wget http://nginx.org/download/nginx-1.4.7.tar.gz
useradd nginx -s /sbin/nologin-M
./configure --user=nginx--group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module--with-http_ssl_module
echo $?
make && make install
3.3 测试nginx
[[email protected]]# /usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx:error while loading shared libraries: libpcre.so.1: cannot open shared objectfile: No such file or directory
echo /usr/local/lib>>/etc/ld.so.conf
ldconfig
[[email protected]]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file/usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file/usr/local/nginx/conf/nginx.conf test is successful
#此时可以在浏览器输入nginx的IP地址。
4、配置nginx关联php
4.1 修改nginx配置文件
在nginx.conf中加入如下红色内容
vi/usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm index.php;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf;
}
}
#红色这段作用是把php结尾的url交给php进程处理。
4.2 添加phpinfo
创建phpinfo文件
cat >/usr/local/nginx/html/index.php <
phpinfo(); ?> EOF
在浏览器输入测试urlhttp://IP/index.php,出现如下界面则解析成功。 5.1 安装zabbix server端 yum -y install libcurl-develnet-snmp-devel #视实际情况系统环境,如果后面欠缺某些库,可以再次yum useradd zabbix -s/sbin/nologin cd /usr/local/src wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.2.2/zabbix-2.2.2.tar.gz/download tar zxf zabbix-2.2.2.tar.gz cd zabbix-2.2.2 ./configure--prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql--with-net-snmp --with-libcurl make && make install 5.2 创建数据库,添加授权账号 create database zabbix characterset utf8; grant all privileges on zabbix.*to zabbix@'%' identified by 'zabbix'; delete from mysql.user whereuser=""; #删除空用户名 flush privileges; 5.3 导入数据库 cd /usr/local/src/zabbix-2.2.2 mysql -uzabbix -pzabbix-h127.0.0.1 zabbix < database/mysql/schema.sql mysql -uzabbix -pzabbix-h127.0.0.1 zabbix < database/mysql/p_w_picpaths.sql mysql -uzabbix -pzabbix-h127.0.0.1 zabbix < database/mysql/data.sql 5.4 拷贝zabbix启动文件 cpmisc/init.d/fedora/core/zabbix_server /etc/init.d/ cpmisc/init.d/fedora/core/zabbix_agentd /etc/init.d/ 5.5 修改配置文件及启动文件 sed -i 's/^DBUser=.*$/DBUser=zabbix/g'/usr/local/zabbix/etc/zabbix_server.conf sed -i's/^.*DBPassword=.*$/DBPassword=zabbix/g'/usr/local/zabbix/etc/zabbix_server.conf sed -i 's/^.*DBHost=.*$/DBHost=127.0.0.1/g'/usr/local/zabbix/etc/zabbix_server.conf sed -i's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g'/etc/init.d/zabbix_server sed -i's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g'/etc/init.d/zabbix_agentd 5.6 添加zabbix服务端口 cat >>/etc/services< zabbix-agent 10050/tcp ZabbixAgent zabbix-agent 10050/udp ZabbixAgent zabbix-trapper 10051/tcpZabbix Trapper zabbix-trapper 10051/udpZabbix Trapper EOF 5.7 启动zabbix服务 /etc/init.d/zabbix_serverstart /etc/init.d/zabbix_agentdstart echo "/etc/init.d/zabbix_serverstart" >> /etc/rc.local echo "/etc/init.d/zabbix_agentdstart" >> /etc/rc.local netstat -plnt|grep zabbix tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 834/zabbix_agentd tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 769/zabbix_server 5.8 复制web端到nginx的工作目录 cd /usr/local/src/zabbix-2.2.2 cp -ra frontends/php//usr/local/nginx/html/zabbix chown -R nginx.nginx /usr/local/nginx/html/zabbix 5.9 在浏览器输入http://IP/zabbix/index.php 5.10 修改php配置满足zabbix安装要求 sed -i 's/^\(.*\)date.timezone=.*$/date.timezone = Asia\/Shanghai/g' /etc/php.ini 5.11 zabbix连接数据库 输入上述配置的用户名密码: 数据库名称为:zabbix 数据库用户名:zabbix 数据库密码:zabbix 5.12 登陆zabbix 默认用户名:admin 默认密码:zabbix 点击右上角profile处出现该界面。 useradd zabbix -s/sbin/nologin -M tar -zxf zabbix-2.2.2.tar.gz cd zabbix-2.2.2 ./configure--prefix=/usr/local/zabbix --enable-agent make install cpmisc/init.d/fedora/core/zabbix_agentd /etc/init.d/ #修改/usr/local/zabbix/etc/zabbix_agentd.conf中的server ip #修改/etc/init.d/server_agentd中的BASEDIR [[email protected]]# netstat -plnt|grep zabbix tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 17870/zabbix_agentd apt-get install zabbix-agent vi /etc/zabbix/zabbix_agentd.conf #修改server IP 如果apt-get安装不成功,可删除apt安装的zabbix-agent包:dpkg -r zabbix-agent;dpkg -P zabbix-agent,然后再apt-get安装。 tar -zxf zabbix-2.2.2.tar.gz cd zabbix-2.2.2/ ls ./configure --prefix=/usr/local/zabbix--enable-agent make install cpmisc/init.d/debian/zabbix-agent /etc/init.d vi/usr/local/zabbix/etc/zabbix_agentd.conf #修改server ip vi /etc/init.d/zabbix-agent #指定zabbix_agentd路径 到此zabbix server端与client端都安装完成。4.3 测试Php解析
5、安装zabbix server端
sed -i 's/^\(.*\)post_max_size =.*$/post_max_size = 16M/g' /etc/php.ini
sed -i 's/^\(.*\)max_execution_time =.*$/max_execution_time = 300/g' /etc/php.ini
sed -i 's/^\(.*\)max_input_time =.*$/max_input_time = 300/g' /etc/php.ini
/etc/init.d/php-fpm restart6、调整zabbix显示中文
7、centos安装Zabbix client端
8、ubuntu安装Zabbix client端
9、debian安装zabbix client端