序:这是我个人的一些笔记和总结,有不当和错误的地方欢迎指出纠正!

整个环境所需要的软件包
php-5.5.35
libmcrypt-2.5.8
mysql-5.5.49
nginx-1.9.15
zabbix-3.2.1

我们需要先构建 LNMP 的环境,因为 Zabbix 通过 PHP 页面展示(相关包会在后面做一个汇总分享)

1.安装 Nginx

[[email protected] ~]# yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre* make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel

zlib:给 Nginx 提供 gzip 模块,需要的支持;
OPenssl 提供 SSL 功能;
PCRE,地址重写
下载nginx软件包并进入到目录中:

wget http://nginx.org/download/nginx-1.9.15.tar.gz && tar xvf nginx-1.9.15.tar.gz && cd nginx-1.9.15

进行源码安装

tar xvf nginx-1.9.15.tar.gz -C /usr/local/src/ && cd /usr/local/src/nginx-1.9.15
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre
make && make install

--with-http_stub_status_module:支持nginx状态查询
--with-http_ssl_module:支持https
--with-http_spdy_module:支持google的spdy,想了解请百度spdy,这个必须有ssl的支持
--with-pcre:为了支持rewrite重写功能,必须制定pcre

添加一个nginx用户

[[email protected] nginx-1.9.15]# useradd -u 8001 -M -s /sbin/nologin nginx

修改/usr/local/nginx/conf/nginx.conf

#user nobody;
user nginx nginx; #此行添加
........
location ~ \.php$ { #这里默认注释手动去掉注释
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}

启动nginx并加入开机自启

[[email protected] nginx-1.9.15]# /usr/local/nginx/sbin/nginx
[[email protected] nginx-1.9.15]# echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local

设置防火墙通过nginx

[[email protected] nginx-1.9.15]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[[email protected] nginx-1.9.15]# /etc/rc.d/init.d/iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[[email protected] nginx-1.9.15]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80

2.安装mysql

下载MySQL安装

wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49.tar.gz
[[email protected] ~]# tar xvf mysql-5.5.49.tar.gz -C /usr/local/src/ ; cd /usr/local/src/mysql-5.5.49

添加mysql用户和组

groupadd mysql
useradd mysql -s /sbin/nologin -M -g mysql

#先安装cmake(mysql5.5以后是通过cmake来编译的)

yum install -y cmake

#创建mysql的安装目录及数据库存放目录

[[email protected] mysql-5.5.49]# mkdir -p /usr/local/mysql
[[email protected] mysql-5.5.49]# mkdir -p /usr/local/mysql/data
[[email protected] mysql-5.5.49]# chmod +w /usr/local/mysql/
[[email protected] mysql-5.5.49]# chown -R mysql:mysql /usr/local/mysql/
[[email protected] mysql-5.5.49]# mkdir -p /var/mysql
[[email protected] mysql-5.5.49]# mkdir -p /var/mysql/data/
[[email protected] mysql-5.5.49]# mkdir -p /var/mysql/log/
[[email protected] mysql-5.5.49]# chown -R mysql:mysql /var/mysql/

安装mysql

[[email protected] mysql-5.5.49]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/var/mysql/data \
-DMYSQL_USER=mysql

…… ……

CMake Warning:

Manually-specified variables were not used by the project:

MYSQL_USER

WITH_MEMORY_STORAGE_ENGINE

-- Build files have been written to: /usr/local/src/mysql-5.5.49

[[email protected] mysql-5.5.22]#make

解决报错:-- Configuring incomplete, errors occurred!
先安装 ncurses-devel 包
yum install ncurses-devel
再删除刚才编译生成的 CMakeCache.txt 文件
rm CMakeCache.txt
再次执行一次cmake ...
一般都可以顺利安装的。
[[email protected] mysql-5.5.49]#make && make install
ln -s /usr/local/mysql/bin/* /usr/bin/  #添加软链接

LNMP环境 + Zabbix 搭建-林小屋博客

配置mysql

[[email protected] mysql-5.5.49]# cd support-files/
[[email protected] support-files]# cp my-medium.cnf /etc/my.cnf
[[email protected] support-files]# cp mysql.server /etc/init.d/mysql

初始化安装。

/usr/local/mysql/scripts/mysql_install_db \

--defaults-file=/etc/my.cnf \

--basedir=/usr/local/mysql \

--datadir=/var/mysql/data \

--user=mysql
…… ……

You can start the MySQL daemon with:

cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/local/mysql/scripts/mysqlbug script!

修改配置文件

[[email protected] support-files]# vi /etc/init.d/mysql
basedir=/usr/local/mysql
datadir=/var/mysql/data
[[email protected] support-files]# chmod +x /etc/init.d/mysql
[[email protected] support-files]# vi /etc/init.d/mysql
[[email protected] support-files]# chkconfig --add mysql
[[email protected] support-files]# chkconfig --level 345 mysql on
[[email protected] support-files]# cd /usr/local/mysql
[[email protected] mysql]# service mysql start
Starting MySQL.. [ OK ]

设置开机自启

chkconfig mysql on

设置密码

/usr/local/mysql/bin/mysql_secure_installation
.......
ew password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
.......

测试登录

[[email protected] mysql]# mysql -uroot -p123456
..........
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

登录数据库,创建zabbix数据库及用户名和密码:

mysql> create database zabbix default charset utf8; #新加一个zabbix的库
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to [email protected]'localhost' identified by 'zabbix'; #添加一个zabbix用户并给他zabbix库权限并设置密码为zabbix
Query OK, 0 rows affected (0.03 sec)
mysql> flush privileges; #刷新缓存
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)ot创建密码:

3.安装PHP

下载PHP安装包

wget http://cn2.php.net/get/php-5.5.35.tar.gz/from/this/mirror

解压并编译

mv mirror php-5.5.35.tar.gz && tar xvf php-5.5.35.tar.gz -C /usr/local/src/ ; cd /usr/local/src/php-5.5.35

编译安装

[[email protected] php-5.5.35]#./configure --prefix=/usr/local/src/php-5.5.35

#提示“freetype-config not found” FreeType是一个完全开源的、可扩展、可定制且可移植的字体引擎,它提供TrueType字体驱动的实现统一的接口来访问多种字体格式文件
yum -y install freetype*
再配置

make && make install
ln -s /usr/local/src/php-5.5.35 /usr/local/php
cp php.ini-production /usr/local/php/etc/php.ini
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf

修改php.ini参数:(zabbix环境需要修改的参数)

cd /usr/local/php/etc/
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone = PRC

4.安装zabbix server

安装zabbix

[[email protected] ~]# tar zxf zabbix-3.0.3.tar.gz && cd zabbix-3.0.3

编译zabbix

./configure --prefix=/usr/local/zabbix-3.0.3/ --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2

make && make install

编译过程中如果有报错:
故障:

checking for mysql_config... no
configure: error: MySQL library not found

解决:

yum install mysql-devel -y

故障:

checking for net-snmp-config... no
configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config

解决:

yum install net-snmp-devel -y

创建zabbix用户:

[[email protected] zabbix-3.0.3]# groupadd zabbix
[[email protected] zabbix-3.0.3]# useradd zabbix -s /sbin/nologin -M –g zabbixzabbix server需要导入3个sql文件:
[[email protected] zabbix-3.0.3]# mysql -uroot -pzabbix zabbix < database/mysql/schema.sql
[[email protected] zabbix-3.0.3]# mysql -uroot -pzabbix zabbix < database/mysql/images.sql
[[email protected] zabbix-3.0.3]# mysql -uroot -pzabbix zabbix < database/mysql/data.sql

如遇以下报错:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

解决办法:

Mkdir /var/lib/mysql
[[email protected] ~]# ln -s /tmp/mysql.sock /var/lib/mysql/

五、zabbix管理网站配置(nginx)

创建项目目录:

[[email protected] zabbix-3.0.3]# mkdir /data/web/zabbix.lifec.com -p
[[email protected] zabbix-3.0.3]# mkdir /data/logs/zabbix -p

将前端文件拷贝到项目目录下

[[email protected] zabbix-3.0.3]# cp -rp frontends/php/* /data/web/zabbix.lifec.com/

编辑nginx虚拟主机

cd /usr/local/nginx/conf/
[[email protected] conf]# mkdir extra
[[email protected] conf]# cd extra/
[[email protected] extra]# vim zabbix.conf
server {
listen 8027;
server_name zabbix.lifec.com;
access_log /data/logs/zabbix/zabbix.lifec.com.access.log main;
index index.html index.php index.html;
root /data/web/zabbix.lifec.com;
location /{
try_files $uri $uri/ /index.php?$args;
}
location ~ ^(.+.php)(.*)$ {
fastcgi_split_path_info ^(.+.php)(.*)$;
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}

编辑nginx.conf配置文件:

[[email protected] conf]# cat nginx.conf
user nginx;
worker_processes 1;
#error_log logs/error.log warning;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include extra/*.conf;
}

编辑zabbix_server.conf文件

[[email protected] etc]# pwd
/usr/local/zabbix-3.0.2/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix



未完待续......