环境说明:centos6.8
selinux 关闭 iptables 关闭
准备安装源码包:
openssl-1.0.2l.tar.gz 下载点我
nginx-1.12.2.tar.gz 下载点我
pcre-8.39.tar.gz 下载点我
zlib-1.2.8.tar.gz 下载点我
libmcrypt-2.5.8.tar.gz 下载点我
php-5.6.31.tar.gz 下载点我(国内下载地址)国外下载地址
fping-3.12.tar.gz 下载点我
zabbix-4.2.4.tar.gz 下载点我
mysql-5.6.24
安装工具包
yum -y groupinstall "Development Tools"
yum -y install cmake
部署MySQL
- 安装依赖
yum install ncurses-devel -y
tar -xf mysql-5.6.24.tar.gz
cd mysql-5.6.24
cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql/ -DMYSQL_DATADIR=/opt/mysql/data/ -DSYSCONFDIR=/opt/mysql/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/opt/mysql/etc/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make && make install
- 初始化MySQL
groupadd mysql
useradd -s /sbin/nologin -g mysql mysql
/opt/mysql/scripts/mysql_install_db --user=mysql --datadir=/opt/mysql/data --basedir=/opt/mysql
- 配置MySQL启动脚本
cp /opt/mysql/support-files/mysql.server /etc/init.d/mysql
chkconfig --add /etc/init.d/mysql
chkconfig mysql on
- 启动MySQL
chown -R mysql:mysql /opt/mysql
service mysql start
- 配置MySQL环境变量
vim /etc/profile
添加以下内容
PATH=$PATH:/opt/mysql/bin/:/opt/mysql/bin/
export PATH
mysql
首次进入不需要密码
> set password=password('设置的密码');
> create database zabbix;
> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by '密码2';
> flush privileges;
安装zlib
tar -xf zlib-1.2.8.tar.gz
cd zlib-1.2.8/
./configure --shared
make && make install
安装openssl
tar -xf openssl-1.0.2l.tar.gz
cd openssl-1.0.2l/
./config shared zlib
make && make install
mv /usr/bin/openssl /usr/bin/openssl.bak
ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/ssl/include/openssl /usr/include/openssl
ln -s /usr/local/ssl/lib/libssl.so.1.0.0 /usr/local/lib64/libssl.so
echo "/usr/local/ssl/lib/" >> /etc/ld.so.conf
ldconfig -v
安装nginx
tar -xf pcre-8.39.tar.gz
tar -xf nginx-1.12.2.tar.gz
cd nginx-1.12.2
./configure \
--prefix=/opt/nginx \
--with-http_dav_module \
--with-http_stub_status_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-pcre=/root/pcre-8.39 \
--with-zlib=/root/zlib-1.2.8 \
--with-openssl=/root/openssl-1.0.2l \
--with-http_ssl_module \
--with-http_gzip_static_module \
--user=www --group=www
make && make install
groupadd www
useradd -s /sbin/nologin -g www www
- 启动nginx
/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
部署PHP
- 安装依赖
yum -y install openldap-devel openldap libxml2 libxml2-devel bzip2 bzip2-devel curl curl-devel libjpeg-devel libpng-devel libpng freetype-devel libicu-devel libxslt-devel gmp-devel readline-devel
cp -frp /usr/lib64/libldap* /usr/lib/
tar -xf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
tar -xf php-5.6.31.tar.gz
cd php-5.6.31
./configure --prefix=/opt/php56 --with-config-file-path=/etc --with-mysql --with-mysqli --with-mysql-sock --with-gd --with-iconv --with-libxml-dir=/usr --with-mhash --with-mcrypt --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-zlib --with-freetype-dir --with-png-dir --with-jpeg-dir --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-ldap
make && make install
- php配置文件
cp php.ini-production /etc/php.ini
vim /etc/php.ini
修改以下内容
;date.timezone = 改为 date.timezone = Asia/Shanghai
short_open_tag = Off 改为 short_open_tag = On
post_max_size = 8M 改为 post_max_size = 16M
max_execution_time = 30 改为 max_execution_time = 300
max_input_time = 60 改为 max_input_time = 300
always_populate_raw_post_data = -1 去掉注释
mbstring.func_overload = 0 去掉注释
- 配置php-fpm
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
cp /opt/php56/etc/php-fpm.conf.default /opt/php56/etc/php-fpm.conf
vim /opt/php56/etc/php-fpm.conf
修改以下内容
pid = run/php-fpm.pid
user = www
group = www
listen = 127.0.0.1:9000
- 启动php-fpm
service php-fpm start
- 检查运行情况
netstat -anptlu |grep php-fpm
部署zabbix
- 安装依赖
yum -y install net-snmp net-snmp-devel curl-devel java-1.8.0-openjdk java-1.8.0-openjdk-devel OpenIPMI-devel libssh2-devel pcre* libevent-devel
grouapdd zabbix
useradd -s /sbin/nologin -g zabbix zabbix
tar -xf fping-3.12.tar.gz
cd fping-3.12
./configure
make && make install
chown root:zabbix /usr/local/sbin/fping
chmod 4710 /usr/local/sbin/fping
tar -xf zabbix-4.2.4.tar.gz
cd zabbix-4.2.4
./configure \
--prefix=/opt/zabbix \
--enable-server \
--enable-agent \
--with-mysql \
--with-net-snmp \
--with-libcurl \
--with-openipmi \
--enable-java
如本机已安装MySQL,可以指定mysql_config文件位置 --mysql=/.../mysql_config
如需监控tomcat 需加上--enable-java 编译参数
make && make install
导入zabbix基础数据到MySQL
mysql -uroot -pMySQL密码 zabbix < schema.sql
mysql -uroot -pMySQL密码 zabbix < images.sql
mysql -uroot -pMySQL密码 zabbix < data.sql
配置zabbix
cp misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix-server
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix-agent
chmod +x /etc/init.d/zabbix-*
chkconfig --add /etc/init.d/zabbix-server
chkconfig --add /etc/init.d/zabbix-agent
chkconfig zabbix-server on
vim /opt/zabbix/etc/zabbix_server.conf
修改以下内容
LogFile=/opt/zabbix/logs/zabbix_server.log
PidFile=/opt/zabbix/logs/zabbix_server.pid
SocketDir=/opt/zabbix/logs/
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=密码2
DBPort=3306
FpingLocation=/usr/sbin/fping
mkdir /opt/zabbix/logs
chown -R zabbix:zabbix /opt/zabbix/
- 启动zabbix
service zabbix_server start
使用service zabbix-server start启动报错:
Starting zabbix_server: /etc/init.d/functions: line 722: /usr/local/sbin/zabbix_server: No such file or directory
[FAILED]
vim /etc/init.d/zabbix-server
BASEDIR=/opt/zabbix
按照实际情况修改BASEDIR
- 配置nginx动态页面
vim /opt/nginx/conf/nginx.conf
以下为修改内容部分,并非全部配置文件内容,仅供参考
user www www;
...
location / {
root html;
index 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;
}
...
- 拷贝zabbix源代码
cp -r frontends/php/ /opt/nginx/html/zabbix
chown -R www:www /opt/nginx/html/zabbix
- reload nginx
/opt/nginx/sbin/nginx -s reload
浏览器访问
http://localhostIP/zabbix