内容参鉴:亲爱的郭老师
1、基础介绍
2、环境准备
2.1 服务器环境
主机类型 | 主机IP | 主机名 |
Zabbix Server | 10.0.7.5 | zabbix |
Zabbix Agent | 10.0.7.6 | saltstack |
2.2 环境需求
环境 | Linux | Apache/Nginx | Mysql | PHP |
LAMP |
|
|
|
|
LNMP | Centos6.5_x64 | 1.8.0 | 5.5.32 | 5.5.31 |
3、LNMP环境搭建
3.1 Mysql安装配置
3.1.1 下载
wget https:// downloads.mariadb.com/archives/mysql-5.5/mysql-5.5.32-linux2.6-x86_64.tar.gz
3.1.2 创建用户及用户组
groupadd -r mysql
useradd -r -g mysql -M -s /sbin/nologin mysql
3.1.3 创建数据目录并设定目录权限
mkdir -p /app/mysql_data/
chown -R mysql.mysql /app/mysql_data/
3.1.4 解压安装包到指定目录
tar zxvf mysql-5.5.32-linux2.6-x86_64.tar.gz -C /app
ln -sv /app/mysql-5.5.32-linux2.6-x86_64/ /app/mysql
chown -R mysql.mysql /app/mysql-5.5.32-linux2.6-x86_64/
3.1.5 初始化配置文件
cd /app/mysql
./scripts/mysql_install_db --user=mysql --basedir=/app/mysql --datadir=/app/mysql_data
3.1.6 复制启动文件与配置文件
cp support-files/mysql.server /etc/init.d/mysqld
/bin/cp -f support-files/my-small.cnf /etc/my.cnf
3.1.7 修改启动脚本内容
sed -i '46c basedir=/app/mysql' /etc/init.d/mysqld
sed -i '47c datadir=/app/mysql_data' /etc/init.d/mysqld
3.1.8 添加到环境变量
echo "PATH=/app/mysql/bin:$PATH" >> /etc/profile
tail -1 /etc/profile
source /etc/profile
3.1.9 启停服务
/etc/init.d/mysqld start|stop
chkconfig --level 35 mysqld on
3.1.10 设置密码
/app/mysql/bin/mysqladmin -u root password '12345'
3.1.11 索引库文件(不然会报错哦)
ln -s /app/mysql-5.5.32-linux2.6-x86_64/lib/libmysqlclient.so.18 /usr/lib64/
3.2 Nginx安装配置
3.2.1 更换Yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
3.2.2 安装依赖软件包
# pcre (建议yum安装,也可以编辑安装)
yum install pcre pcre-devel openssl openssl-devel -y
3.2.3 下载软件包并创建组与用户
wget http://nginx.org/download/nginx-1.8.0.tar.gz
groupadd -r nginx
useradd -r -g nginx -s /sbin/nologin -M nginx
3.2.4 编译安装
tar xf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --user=nginx --group=nginx --prefix=/app/nginx1.8.0 --with-http_stub_status_module --with-http_ssl_module
echo $?
make && make install
cd ..
ln -s /app/nginx1.8.0/ /app/nginx
chown -R nginx.nginx /app/nginx1.8.0/
3.2.5 启动及检查
/app/nginx/sbin/nginx -t # 检查语法
/app/nginx/sbin/nginx # 启动
netstat -tunlp|grep nginx # 检查服务与端口
echo “/app/nginx/sbin/nginx” >> /etc/rc.local
3.2.6 配置环境变量
echo "PATH=$PATH:/app/nginx/sbin/" >> /etc/profile
source /etc/profile
3.3 PHP安装配置
3.3.1下载地址
http://www.php.net
http://php.net/get/php-5.5.31.tar.gz/from/a/mirror
3.3.2 安装依赖包
yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel -y
3.3.3 编译安装PHP
tar zxf php-5.5.31.tar.gz
cd php-5.5.31
./configure --prefix=/app/php-5.5.31 \
--with-config-file-path=/app/php-5.5.31/etc --with-bz2 --with-curl \
--enable-ftp --enable-sockets --disable-ipv6 --with-gd \
--with-jpeg-dir=/usr/local --with-png-dir=/usr/local \
--with-freetype-dir=/usr/local --enable-gd-native-ttf \
--with-iconv-dir=/usr/local --enable-mbstring --enable-calendar \
--with-gettext --with-libxml-dir=/usr/local --with-zlib \
--with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd \
--enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
make && make install
ln -s /app/php-5.5.31 /app/php
3.3.4 配置环境变量
echo "PATH=$PATH:/app/php/sbin" >> /etc/profile
source /etc/profile
3.3.5 配置php.ini
# 复制php.ini文件
cp /data/software/php-5.5.31/php.ini-production /app/php/etc/php.ini
# 配置以下项(zabbix需求)
vim /app/php/etc/php.ini
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone = PRC
# 或 sed替换
sed -i "s/;date.timezone =/date.timezone = Asia\/Shanghai/g" /etc/php.ini
sed -i "s#max_execution_time = 30#max_execution_time = 300#g" /etc/php.ini
sed -i "s#post_max_size = 8M#post_max_size = 32M#g" /etc/php.ini
sed -i "s#max_input_time = 60#max_input_time = 300#g" /etc/php.ini
sed -i "s#memory_limit = 128M#memory_limit = 128M#g" /etc/php.ini
sed -i "/;mbstring.func_overload = 0/ambstring.func_overload = 2\n" /etc/php.ini
3.3.6 配置php配置文件
cp /app/php-5.5.31/etc/php-fpm.conf.default /app/php-5.5.31/etc/php-fpm.conf
vim zabbix.conf.php
# 检查PHP与数据库之间的配置内容
$DB["USER"] = 'zabbix';
$DB["PASSWORD"] = 'zabbix_password';
3.3.7 启动php-fpm
cp /app/php-5.5.31/etc/php-fpm.conf.default /app/php-5.5.31/etc/php-fpm.conf
/app/php/sbin/php-fpm
echo "/app/php/sbin/php-fpm" >> /etc/rc.local
4、Zabbix Server安装配置
4.1 下载zabbix源码包
http://www.zabbix.com/
4.2 安装依赖包
# 有些是必须:net-snamp-devel curl-devel unixODBC-devel
yum -y install gcc gcc-c++ autoconf php-mysql mod_ssl mod_perl \
mod_auth_mysql php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-bcmath \
mysql-connector-odbc mysql-devel libdbi-dbd-mysql net-snmp-devel curl-devel unixODBC-devel \
OpenIPMI-devel java-devel
4.3 创建用户
groupadd -r zabbix
useradd -r -g zabbix -s /sbin/nologin -M zabbix
4.4 安装zabbix server agent
cd /data/software
tar zxf zabbix-2.4.7.tar.gz
cd zabbix-2.4.7
./configure --prefix=/app/zabbix-2.4.7/ \
--enable-java \
--enable-server \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-libxml2
make && make install
ln -s /app/zabbix-2.4.7/ /app/zabbix
4.5 创建数据库
mysql -uroot -p
mysql> drop database test;
mysql> create database zabbix default charset utf8;
4.6 依次导入数据
mysql -uroot -p12345 zabbix < /data/software/zabbix-2.4.7/database/mysql/schema.sql
mysql -uroot -p12345 zabbix < /data/software/zabbix-2.4.7/database/mysql/images.sql
mysql -uroot -p12345 zabbix < /data/software/zabbix-2.4.7/database/mysql/data.sql
4.7 配置zabbix server
vim /app/zabbix/etc/zabbix_server.conf
DBName=zabbix
DBUser=root
DBPassword=12345
DBPort=3306
4.8 启动 zabbix server
# 默认端口10051
/app/zabbix/sbin/zabbix_server
echo "/app/zabbix/sbin/zabbix_server" >> /etc/rc.local
# 默认端口 10050
/app/zabbix/sbin/zabbix_agentd
echo "/app/zabbix/sbin/zabbix_agentd" >> /etc/rc.local
4.9 将zabbxi配置到nginx服务器上
# 拷贝前端文件
mkdir -p /data/logs/nginx/
mkdir -p /data/site/zabbix/
cp -rp /data/software/zabbix-2.4.7/frontends/php/* /data/site/zabbix/
cd /data/site/zabbix/conf/
cp zabbix.conf.php.example zabbix.conf.php
chown -R nginx.nginx /data/site/zabbix/
4.10 配置虚拟主机
server {
listen 80;
server_name 10.0.7.5;
access_log /data/logs/nginx/zabbix.access.log main;
root /data/site/zabbix/;
index index.html index.htm index.php;
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;
}
}
5、Zabbix Agent安装配置
5.1 创建用户及组
groupadd -r zabbix
useradd -r -g zabbix -s /sbin/nologin -M zabbix
5.2 zabbix_agent 安装
mkdir -p /app
cd /data/software
tar zxf zabbix-2.4.7.tar.gz
cd zabbix-2.4.7
./configure --prefix=/app/zabbix-2.4.7/ --enable-agent
make && make install
ln -s /app/zabbix-2.4.7/ /app/zabbix
# 或可以用Yum的方式来安装
rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
yum install zabbix-agent -y
5.3 修改配置文件
vim /app/zabbix/etc/zabbix_agentd.conf
Server=10.0.7.5 # 被动报告
ServerActive=127.0.0.1 # 主动报告
Hostname=Saltstack
5.4 启动服务
/app/zabbix/sbin/zabbix_agentd
echo "/app/zabbix/sbin/zabbix_agentd" >> /etc/rc.local
6、web端配置
7、基础使用