系統環境準備:
redhat 6.6 64位
mysql-5.6.34
php-5.6.28
zabbix-3.2.1
配置前先關閉iptables和SELINUX,避免安裝過程當中報錯。
# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
SELINUX=disabled
zabbix3.2.0對環境的要求 :
MySQL 5.1以上最好是 5.6或者更高的版本
PHP 5.4或者更高的版本
安裝Apahce, PHP, MySQL以及php鏈接mysql庫組件。
#yum -y install httpd httpd-devel
yum install \ make \ gcc \ gcc-c++ \ ncurses-devel \ cmake
groupadd mysql php
useradd -g mysql mysql -s /sbin/nologinhtml
chmod 755 /home/mysql/mysql
新建mysql安裝目錄:linux
mkdir -p /usr/local/mysql c++
新建mysql數據庫數據文件目錄:web
mkdir -p /data/mysqldb sql
編譯安裝:數據庫
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysqldb/ \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_SSL=system \
-DMYSQL_TCP_PORT=3306 \
--enable-proxy \
-DWITH_SSL=bundled
注:從新運行配置,須要刪除CMakeCache.txt文件apache
rm -f CMakeCache.txt
make
make install
修改mysql安裝目錄
chown -R mysql:mysql /usr/local/mysql
修改mysql數據庫文件目錄
chown -R mysql:mysql /data/mysqldb
進入安裝路徑
# cd /usr/local/mysql
進入安裝路徑,執行初始化配置腳本,建立系統自帶的數據庫和表
# scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysqldb --user=mysql
注:在啓動MySQL服務時,會按照必定次序搜索my.cnf,先在/etc目錄下找,找不到則會搜索"$basedir/my.cnf"json
注意:若在/etc目錄下會存在一個my.cnf,須要將此文件改名爲其餘的名字,如:/etc/my.cnf.bak,不然,該文件會干擾源碼安裝的MySQL的正確配置,形成沒法啓動。
在使用"yum update"更新系統後,須要檢查下/etc目錄下是否會多出一個my.cnf,若是多出,將它重命名成別的。不然,MySQL將使用這個配置文件啓動,可能形成沒法正常啓動等問題。
# mv /etc/my.cnf /etc/my.cnf.bak
# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
添加服務,拷貝服務腳本到init.d目錄,並設置開機啓動
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
設置開機啓動
chkconfig mysqld on
service mysqld start
MySQL啓動成功後,root默認沒有密碼,咱們須要設置root密碼。
設置以前,咱們須要先設置PATH,要不不能直接調用mysql
修改/etc/profile文件,在文件末尾添加
PATH=/usr/local/mysql/bin:$PATH
export PATH
讓配置當即生效
source /etc/profile
修改數據庫的root密碼:
mysql -uroot
mysql> SET PASSWORD = PASSWORD('123abc');
或是
# mysqladmin -uroot -p password 123abc
Enter password: 這裏直接回車
Warning: Using a password on the command line interface can be insecure.
若要設置root用戶能夠遠程訪問,執行
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.16.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
紅色的password爲遠程訪問時,root用戶的密碼,能夠和本地不一樣。
防火牆的3306端口默認沒有開啓,若要遠程訪問,須要開啓這個端口
打開/etc/sysconfig/iptables文件,在「-A INPUT –m state --state NEW –m tcp –p –dport 22 –j ACCEPT」,下添加:
-A INPUT -m state --state NEW -m tcp -p -dport 3306 -j ACCEPT
而後保存,並關閉該文件,在終端內運行下面的命令,刷新防火牆配置:
service iptables restart
添加依賴應用
yum install -y gcc \
gcc-c++ \
autoconf \
libjpeg \
libjpeg-devel \
libpng \
libpng-devel \
freetype \
freetype-devel \
libpng \
libpng-devel \
libxml2 \
libxml2-devel \
zlib \
zlib-devel \
glibc \
glibc-devel \
glib2 \
glib2-devel \
bzip2 \
bzip2-devel \
ncurses \
curl \
openssl-devel \
db4-devel \
libXpm-devel \
libX11-devel \
gmp-devel \
readline-devel \
libxslt-devel \
expat-devel \
xmlrpc-c \
libcurl \
libcurl-devel
1 tar zxvf libmcrypt-2.5.8.tar.gz 2 3 cd libmcrypt-2.5.8 4 5 ./configure 6 7 make 8 9 make install
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--with-apxs2=/usr/sbin/apxs \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-inline-optimization \
--enable-fpm \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--disable-mbregex \
--disable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-pdo-mysql \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear
其中--with-apxs2是用來生成Apache的PHP模塊libphp5.so的,不須要能夠去掉.
make
make install
php.ini是php運行核心配置文件
php-fpm.conf是php-fpm進程服務的配置文件
1 # cd php-5.6.28 2 3 # cp php.ini-production /etc/php.ini 4 5 # cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf 6 7 # cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 8 9 # chmod +x /etc/init.d/php-fpm
# /usr/local/php/sbin/php-fpm -t
[23-May-2016 20:03:52] NOTICE:
configuration file /usr/local/php/etc/php-fpm.conf test is successful
# chkconfig --add php-fpm
# chkconfig php-fpm on
# service php-fpm start
Starting php-fpm done
netstat –anpt
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 705/php-fpm
vi /usr/local/php/etc/php-fpm.conf
listen = 127.0.0.1:8000
# vi /usr/local/apache/conf/httpd.conf
找到 AddType application/x-gzip .gz .tgz (369)在其下添加以下內
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html //調整首頁文件設置
LoadModule php5_module /usr/lib64/httpd/modules/libphp5.so 這個模塊會在編譯的自動生成加入進去
vi /var/www/html/test.php <?php phpinfo(); ?>
官網:http://www.zabbix.com/download.php
下載zabbix-3.2.1.tar.gz
yum -y install curl libcurl-devel net-snmp net-snmp-devel perl-DBI libdbi-dbd-mysql mysql-devel gcc gcc++ make libxml2 libxml2-devel
建立zabbix用戶組與用戶:
# groupadd zabbix
# useradd -g zabbix -s /sbin/nologin zabbix
# tar xzvf zabbix-3.2.1.tar.gz
編譯安裝:
# cd zabbix-3.2.1
# ./configure --prefix=/usr/local/zabbix-server --enable-server --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --enable-agent --enable-ipv6
make && make install
說明:數據文件導入的順序不能變,也能夠在命令行使用mysql命令導入數據文件
[root@test ~]# service mysqld start
mysql> create database zabbix character set utf8; mysql> grant all on zabbix.* to zabbix@'localhost' identified by '123456'; mysql> flush privileges;
# cd zabbix-3.2.1
在解壓的zabbix目錄下,將database/mysql目錄下三個sql文件導入到zabbix數據庫裏。(下面用的是zabbix用戶來導入文件,這個用戶在數據庫是默認存在的)
# mysql -uzabbix -p123456 zabbix < database/mysql/schema.sql
# mysql -uzabbix -p123456 zabbix < database/mysql/images.sql
# mysql -uzabbix -p123456 zabbix < database/mysql/data.sql
或是
# mysql -uzabbix -p123456 zabbix < database/mysql/schema.sql
# mysql -uzabbix -p123456 zabbix < database/mysql/images.sql
# mysql -uzabbix -p123456 zabbix < database/mysql/data.sql
mkdir -p /var/www/zabbix
cp -R frontends/php /var/www/zabbix
chmod 777 /var/www/zabbix/php/conf
修改過濾掉註釋的名字
cat /usr/local/zabbix-server/etc/zabbix_server.conf |grep -v "^#" |grep -v "^$" > /usr/local/zabbix-server/etc/zabbix_server.conf.back
咱們只須要關注DBHost、DBName、DBUser、DBPassword幾項便可。這幾項是配置zabbix server鏈接mysql數據庫的參數。
vim /usr/local/zabbix-server/etc/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=123456
建立日誌文件存放位置:
mkdir /var/log/zabbix
chown -R zabbix:zabbix /var/log/zabbix
啓動zabbix服務:
/usr/local/zabbix-server/sbin/zabbix_server
# cd zabbix-3.2.1
# cp misc/init.d/fedora/core/zabbix_server /etc/init.d/
# chkconfig --add zabbix_server
# chkconfig zabbix_server on
建立軟連接:
ln -s /usr/local/zabbix/sbin/zabbix_server /usr/local/sbin/
啓動服務:
service zabbix_server start
建立zabbix用戶組與用戶:
# groupadd zabbix
# useradd -g zabbix -s /sbin/nologin zabbix
# cd zabbix-3.2.1
# ./configure --prefix=/usr/local/zabbix-agent --enable-agent
make && make install
# cd /usr/local/zabbix-agent
# vi etc/zabbix_agentd.conf
LogFile=/var/log/zabbix/zabbix_agentd.log
Server=172.28.3.103
ServerActive=172.28.3.103
Hostname=172.28.3.100
# cd zabbix-3.2.1
# cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
# chkconfig --add zabbix_agentd
# chkconfig zabbix_agentd on
建立軟連接:
# ln -s /usr/local/zabbix/sbin/zabbix_agentd/usr/local/sbin/
啓動服務:
service zabbix_agentd start
注:若要服務器端也安裝客戶端相關參數能夠參考:http://meiling.blog.51cto.com/6220221/1339389
vim /etc/httpd/conf.d/zabbix.conf # # Zabbix monitoring system php web frontend # #Alias /zabbix/usr/share/zabbix Alias /zabbix /var/www/zabbix/php <Directory "/var/www/zabbix/php"> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all #Require all granted <IfModule mod_php5.c> php_value max_execution_time 300 php_value memory_limit 128M php_value post_max_size 16M php_value upload_max_filesize 2M php_value max_input_time 300 php_value always_populate_raw_post_data -1 # php_value date.timezone Europe/Riga php_value date.timezone Asia/Chongqing </IfModule> </Directory>
其中php_value date.timezone Asia/Chongqing主要是定義php的時區。
最後重啓apache,zabbix服務,以下:
services httpd restart
services zabbix_server restart
而後訪問http://172.28.3.103/zabbix/setup.php這個地址,以下進行安裝:
完成後便可登陸:zabbix默認的用戶名和密碼是Admin/zabbix
vi /var/www/zabbix/php/conf/zabbix.conf.php <?php // Zabbix GUI configuration file. global $DB; $DB['TYPE'] = 'MYSQL'; $DB['SERVER'] = '172.28.3.103'; $DB['PORT'] = '3306'; $DB['DATABASE'] = 'zabbix'; $DB['USER'] = 'zabbix'; $DB['PASSWORD'] = 'zabbix'; // Schema name. Used for IBM DB2 and PostgreSQL. $DB['SCHEMA'] = ''; $ZBX_SERVER = '172.28.3.103'; $ZBX_SERVER_PORT = '10051'; $ZBX_SERVER_NAME = ''; $IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;