很久沒有接觸監控類的軟件了,今天抽空搭建了下php
首先系統環境html
zabbix-server-1 centos7.2 mysql
本次所需的第三方軟件包nginx
如下軟件包經過官網下載c++
zabbix-3.0.3.tar.gz http://www.zabbix.com/download.php 官網下載頁面
http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.0.3/zabbix-3.0.3.tar.gz/download 下載連接sql
nginx-1.10.1.tar.gz http://nginx.org/en/download.html 官網下載頁面
http://nginx.org/download/nginx-1.10.1.tar.gz 下載連接數據庫
php-5.6.22.tar.gz http://php.net/downloads.php 官網下載頁面
http://cn2.php.net/get/php-5.6.22.tar.gz/from/this/mirror 選擇中國站點下載vim
配置yum倉庫centos
[root@zabbix-server-1 yum.repos.d]# cat zabbix.repo瀏覽器
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=1
yum clean all # 清除yum緩存
yum makecache # 生成yum緩存
開始安裝nginx
#安裝依賴包
yum install pcre pcre-devel openssl openssl-devel gcc-c++
useradd -s /sbin/nologin -M nginx
tar xf nginx-1.10.1.tar.gz
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
make install
/usr/local/nginx/sbin/nginx #start nginx service
ps -ef|grep nginx
ss -lntup|grep nginx
[root@zabbix-server-1 conf]# pwd
/usr/local/nginx/conf
egrep -v "#|^$" nginx.conf.default > nginx.conf
#修改部分配置
[root@zabbix-server-1 conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~\.(php|php5)?$ {
root /application/nginx/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;
}
}
}
#殺死進程,重啓服務
ps -ef|grep nginx
/usr/local/nginx/sbin/nginx
安裝php依賴包
yum –y install zlib-devel libxml2-devel libjpeg-devel libiconv-devel freetype-devel libpng-devel gd-devel curl-devel libxslt-devel mysql-devel
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install
編輯安裝時報錯
make[2]: *** [progname.o] Error 1
make[2]: Leaving directory `/root/libiconv-1.14/srclib'
make[1]: *** [install] Error 2
make[1]: Leaving directory `/root/libiconv-1.14/srclib'
make: *** [install] Error 2
解決方法:進入srclib目錄 執行 sed -i -e '/gets is a security/d' ./stdio.in.h
安裝php
tar xf php-5.6.22.tar.gz
tar -zxvf mirror
cd php-5.6.22
./configure \
--prefix=/usr/local/php \
--with-mysql \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-gettext \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-short-tags \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp \
--enable-opcache=no
安裝時報錯
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解決方法
yum install -y epel-release
yum install -y libmcrypt-devel
兩個不能一塊兒安裝,由於CentOs6 7默認的yum源沒有 libmcrypt-devel這個包,只能藉助epel的yum源,因此先安裝epel,再安裝
libmcrypt。
make
make install
[root@zabbix-server-1 php-5.6.22]# pwd
/root/php-5.6.22
[root@zabbix-server-1 php-5.6.22]# cp php.ini-production /usr/local/php/lib/php.ini
[root@zabbix-server-1 php-5.6.22]# cd /usr/local/php/etc/
[root@zabbix-server-1 etc]# ls
pear.conf php-fpm.conf.default
[root@zabbix-server-1 etc]# pwd
/usr/local/php/etc
[root@zabbix-server-1 etc]# cp php-fpm.conf.default php-fpm.conf
[root@zabbix-server-1 etc]# /usr/local/php/sbin/php-fpm
[root@zabbix-server-1 etc]# netstat -lntup|grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3689/php-fpm
安裝zabbix
tar zxvf zabbix-3.0.3.tar.gz
tar -zxvf download
cd zabbix-3.0.3
groupadd zabbix
useradd -g zabbix zabbix
#安裝依賴包,若是一次安裝錯誤,就多試幾回
yum -y install net-snmp net-snmp-devel libssh2-devel OpenIPMI-devel
[root@zabbix-server-1 zabbix-3.0.3]# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --with-ssh2
make
make install
[root@zabbix-server-1 zabbix-3.0.3]# egrep -v "#|^$" /usr/local/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DBHost=192.168.11.5
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
ListenIP=0.0.0.0
Timeout=4
AlertScriptsPath=${datadir}/zabbix/alertscripts
LogSlowQueries=3000
#拷貝啓動腳本
cp misc/init.d/fedora/core/zabbix_* /etc/rc.d/init.d/
zabbix_server
#修改配置文件
vim /application/php/lib/php.ini
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
always_populate_raw_post_data = -1
date.timezone = Asia/Shanghai
#重啓php
[root@zabbix-server-1 zabbix-3.0.3]# pkill -9 php-fpm
[root@zabbix-server-1 zabbix-3.0.3]# /application/php/sbin/php-fpm
#從zabbix源碼包拷貝網站到nginx
[root@zabbix-server-1 zabbix-3.0.3]# pwd
/root/zabbix-3.0.3
[root@zabbix-server-1 zabbix-3.0.3]# cp -rf frontends/php /application/nginx/html/zabbix/
#若是有防火牆,要麼開放80端口,要麼臨時中止
Systemctl stop firewalld
#給目錄設置權限
chown -R nginx.nginx /application/nginx/html/
基本上zabbix服務器算是安裝差很少了
這裏準備配置mysql服務器了,須要在mysql服務器上受權,及初始化zabbix數據庫
#配置mysql服務器了。
Mysql5.7安裝yum
介紹在CentOS7上yum安裝數據庫服務器MySQL Community Server 5.7的方法。
準備
CentOS7默認安裝了和MySQL有兼容性的MariaDB數據庫,在咱們安裝MySQL5.7以前爲了不發生衝突首先刪除MariaDB。
# rpm -qa | grep maria
mariadb-libs-5.5.50-1.el7_2.x86_64
# yum remove mariadb-libs -y
添加MySQL的yum源
在CentOS7上yum安裝MySQL需使用MySQL的yum源。執行如下命令首先添加MySQL的yum源。
# yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
以上yum info命令是2016年8月28日的執行結果,當前安裝的MySQL版本是5.7.14。確認安裝版本以後執行如下命令進行安裝。
# yum install mysql-community-server -y
到此MySQL5.7安裝就完成了,接下來確認安裝的MySQL版本。
# mysqld --version
mysqld Ver 5.7.14 for Linux on x86_64 (MySQL Community Server (GPL))
完成安裝步驟以後,首先配置MySQL的開機自動啓動,在這裏使用systemctl命令
。
# systemctl enable mysqld.service
接着使用systemctl start mysqld.service
命令啓動MySQL。
# systemctl start mysqld.service
而中止MySQL時使用systemctl stop mysqld.service
命令。
# systemctl stop mysqld.service
以上是在CentOS7.2安裝MySQL Community Server 5.7的步驟,但僅限於安裝後續還須要根據開發的系統進行配置。
MySQL5.7開始MySQL管理用戶root的密碼,會默認生成並記錄到/var/log/mysqld.log
文件裏,不要忘記修改默認密碼。
[Note] A temporary password is generated for root@localhost: lQidlh;BX4*x
mysql -uroot -plQidlh;BX4*x
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@’%’ identified by 'zabbix';
mysql> flush privileges;
mysql> quit;
#按照SQL語句順序導入SQL:
mysql -uzabbix -pzabbix zabbix < zabbix-3.0.3/database/mysql/schema.sql
數據導入時報錯ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES)
解決方法
mysql -uroot -plQidlh;BX4*x
mysql> use mysql
mysql> select host,user,password from user;
+-----------+--------+-------------------------------------------+
| host | user | password |
+-----------+--------+-------------------------------------------+
| localhost | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |
| zabbix | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | | |
| zabbix | | |
| % | wgldjc | *70E31422FB5C781D112D6C944FAB09312088255B |
+-----------+--------+-------------------------------------------
mysql> delete from user where user=' ';
Query OK, 2 rows affected (0.00 sec)
mysql> exit
Bye
mysql -uzabbix -pzabbix zabbix < zabbix-3.0.3/database/mysql/images.sql
mysql -uzabbix -pzabbix zabbix < zabbix-3.0.3/database/mysql/data.sql
打開瀏覽器,輸入如下連接
http://ip/zabbix/setup.php