系統環境:
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
——————————————————————————————
zabbix 3.2.0對環境的要求
MySQL 5.1以上最好是 5.6或者更高的版本
PHP 5.4或者更高的版本
安裝Apahce, PHP, MySQL以及php連接配接mysql庫元件。
<code>#yum -y install httpd httpd-devel</code>
<code>yum install \</code>
<code>make \</code>
<code>gcc \</code>
<code>gcc-c++ \</code>
<code>ncurses-devel \</code>
<code>cmake</code>
新增mysql使用者組:
<code>groupadd mysql</code>
新增mysql使用者:
<code>useradd -g mysql mysql -s /sbin/nologin</code>
<code>chmod 755 /home/mysql/</code>
建立mysql安裝目錄
<code>mkdir -p /usr/local/mysql</code>
<code>cmake \</code>
<code>-DCMAKE_INSTALL_PREFIX=</code><code>/usr/local/mysql</code> <code>\</code>
<code>-DMYSQL_DATADIR=</code><code>/home/mysql/</code> <code>\</code>
<code>-DMYSQL_UNIX_ADDR=</code><code>/home/mysql/mysql</code><code>.sock \</code>
<code>-DWITH_MYISAM_STORAGE_ENGINE=1 \</code>
<code>-DWITH_INNOBASE_STORAGE_ENGINE=1 \</code>
<code>-DWITH_ARCHIVE_STORAGE_ENGINE=1 \</code>
<code>-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \</code>
<code>-DENABLED_LOCAL_INFILE=1 \</code>
<code>-DDEFAULT_CHARSET=utf8 \</code>
<code>-DDEFAULT_COLLATION=utf8_general_ci \</code>
<code>-DEXTRA_CHARSETS=all \</code>
<code>-DWITH_SSL=system \</code>
<code>-DMYSQL_TCP_PORT=3306 \</code>
<code>--</code><code>enable</code><code>-proxy \</code>
<code>-DWITH_SSL=bundled</code>
注:重新運作配置,需要删除CMakeCache.txt檔案
rm -f CMakeCache.txt
make
make install
修改mysql安裝目錄
chown -R mysql:mysql /usr/local/mysql
進入安裝路徑
# cd /usr/local/mysql
進入安裝路徑,執行初始化配置腳本,建立系統自帶的資料庫和表
<code># scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/home/mysql --user=mysql</code>
注:在啟動MySQL服務時,會按照一定次序搜尋my.cnf,先在/etc目錄下找,找不到則會搜尋"$basedir/my.cnf"
注意:若在/etc目錄下會存在一個my.cnf,需要将此檔案更名為其他的名字,如:/etc/my.cnf.bak,否則,該檔案會幹擾源碼安裝的MySQL的正确配置,造成無法啟動。
在使用"yum update"更新系統後,需要檢查下/etc目錄下是否會多出一個my.cnf,如果多出,将它重命名成别的。否則,MySQL将使用這個配置檔案啟動,可能造成無法正常啟動等問題。
<code># mv /etc/my.cnf /etc/my.cnf.bak</code>
<code># cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf</code>
添加服務,拷貝服務腳本到init.d目錄,并設定開機啟動
<code># cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld</code>
設定開機啟動
chkconfig mysqld on
service mysqld start
MySQL啟動成功後,root預設沒有密碼,我們需要設定root密碼。
設定之前,我們需要先設定PATH,要不不能直接調用mysql
修改/etc/profile檔案,在檔案末尾添加
<code>PATH=</code><code>/usr/local/mysql/bin</code><code>:$PATH</code>
<code>export</code> <code>PATH</code>
關閉檔案,運作下面的指令,讓配置立即生效
source /etc/profile
執行下面的指令修改root密碼
<code>mysql -uroot </code>
<code>mysql> SET PASSWORD = PASSWORD(</code><code>'123456'</code><code>);</code>
或是
<code># mysqladmin -uroot -p password 123qwe</code>
<code>Enter password: 這裡直接回車</code>
<code>Warning: Using a password on the </code><code>command</code> <code>line interface can be insecure.</code>
若要設定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 –jACCEPT”,下添加:
<code>-A INPUT -m state --state NEW -m tcp -p -dport 3306 -j ACCEPT</code>
然後儲存,并關閉該檔案,在終端内運作下面的指令,重新整理防火牆配置:
service iptables restart
OK,一切配置完畢,你可以通路你的MySQL了~
添加依賴應用
<code>yum </code><code>install</code> <code>-y gcc \</code>
<code>autoconf \</code>
<code>libjpeg \</code>
<code>libjpeg-devel \</code>
<code>libpng \</code>
<code>libpng-devel \</code>
<code>freetype \</code>
<code>freetype-devel \</code>
<code>libxml2 \</code>
<code>libxml2-devel \</code>
<code>zlib \</code>
<code>zlib-devel \</code>
<code>glibc \</code>
<code>glibc-devel \</code>
<code>glib2 \</code>
<code>glib2-devel \</code>
<code>bzip2</code> <code>\</code>
<code>bzip2</code><code>-devel \</code>
<code>ncurses \</code>
<code>curl \</code>
<code>openssl-devel \</code>
<code>gdbm-devel \</code>
<code>db4-devel \</code>
<code>libXpm-devel \</code>
<code>libX11-devel \</code>
<code>gd-devel \</code>
<code>gmp-devel \</code>
<code>readline-devel \</code>
<code>libxslt-devel \</code>
<code>expat-devel \</code>
<code>xmlrpc-c \</code>
<code>xmlrpc-c-devel \</code>
<code>libcurl \</code>
<code>libcurl-devel</code>
<code>tar</code> <code>zxvf libmcrypt-2.5.8.</code><code>tar</code><code>.gz </code>
<code>cd</code> <code>libmcrypt-2.5.8</code>
<code>.</code><code>/configure</code>
<code>make</code>
<code>make</code> <code>install</code>
<code>.</code><code>/configure</code> <code>\</code>
<code>--prefix=</code><code>/usr/local/php</code> <code>\</code>
<code>--with-config-</code><code>file</code><code>-path=</code><code>/etc</code> <code>\</code>
<code>--with-apxs2=</code><code>/usr/sbin/apxs</code> <code>\</code>
<code>--with-mysql=</code><code>/usr/local/mysql</code> <code>\</code>
<code>--with-mysqli=</code><code>/usr/local/mysql/bin/mysql_config</code> <code>\</code>
<code>--</code><code>enable</code><code>-inline-optimization \</code>
<code>--</code><code>enable</code><code>-fpm \</code>
<code>--</code><code>enable</code><code>-soap \</code>
<code>--with-libxml-</code><code>dir</code> <code>\</code>
<code>--with-xmlrpc \</code>
<code>--with-openssl \</code>
<code>--with-mcrypt \</code>
<code>--with-mhash \</code>
<code>--with-pcre-regex \</code>
<code>--with-sqlite3 \</code>
<code>--with-zlib \</code>
<code>--</code><code>enable</code><code>-bcmath \</code>
<code>--with-iconv \</code>
<code>--with-bz2 \</code>
<code>--</code><code>enable</code><code>-calendar \</code>
<code>--with-curl \</code>
<code>--with-cdb \</code>
<code>--</code><code>enable</code><code>-dom \</code>
<code>--</code><code>enable</code><code>-exif \</code>
<code>--</code><code>enable</code><code>-fileinfo \</code>
<code>--</code><code>enable</code><code>-filter \</code>
<code>--with-pcre-</code><code>dir</code> <code>\</code>
<code>--</code><code>enable</code><code>-</code><code>ftp</code> <code>\</code>
<code>--with-gd \</code>
<code>--with-openssl-</code><code>dir</code> <code>\</code>
<code>--with-jpeg-</code><code>dir</code> <code>\</code>
<code>--with-png-</code><code>dir</code> <code>\</code>
<code>--with-zlib-</code><code>dir</code> <code>\</code>
<code>--with-freetype-</code><code>dir</code> <code>\</code>
<code>--</code><code>enable</code><code>-gd-native-ttf \</code>
<code>--with-gettext \</code>
<code>--with-gmp \</code>
<code>--</code><code>enable</code><code>-json \</code>
<code>--</code><code>enable</code><code>-mbstring \</code>
<code>--disable-mbregex \</code>
<code>--disable-mbregex-backtrack \</code>
<code>--with-libmbfl \</code>
<code>--with-onig \</code>
<code>--</code><code>enable</code><code>-pdo \</code>
<code>--with-pdo-mysql \</code>
<code>--with-zlib-</code><code>dir</code> <code>\</code>
<code>--with-pdo-sqlite \</code>
<code>--with-readline \</code>
<code>--</code><code>enable</code><code>-session \</code>
<code>--</code><code>enable</code><code>-shmop \</code>
<code>--</code><code>enable</code><code>-simplexml \</code>
<code>--</code><code>enable</code><code>-sockets \</code>
<code>--</code><code>enable</code><code>-sysvmsg \</code>
<code>--</code><code>enable</code><code>-sysvsem \</code>
<code>--</code><code>enable</code><code>-sysvshm \</code>
<code>--</code><code>enable</code><code>-wddx \</code>
<code>--with-libxml-</code><code>dir</code> <code>\</code>
<code>--with-xsl \</code>
<code>--</code><code>enable</code><code>-zip \</code>
<code>--</code><code>enable</code><code>-mysqlnd-compression-support \</code>
<code>--with-pear</code>
注:
--with-mysql=/usr
--with-mysqli=/usr/bin/mysql_config
--with-apxs2=/usr/sbin/apxs
--enable-gd-jis-conv 會讓中文亂碼的不需要這個參數的
其中--with-apxs2是用來生成Apache的PHP子產品libphp5.so的,不需要可以去掉。
php.ini是php運作核心配置檔案
php-fpm.conf是php-fpm程序服務的配置檔案
<code># cd php-5.6.28</code>
<code># cp php.ini-production /etc/php.ini</code>
<code># cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf</code>
<code># cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm</code>
<code># chmod +x /etc/init.d/php-fpm</code>
<code># /usr/local/php/sbin/php-fpm -t</code>
<code>[23-May-2016 20:03:52] NOTICE: </code>
<code>configuration </code><code>file</code> <code>/usr/local/php/etc/php-fpm</code><code>.conf </code><code>test</code> <code>is successful</code>
<code> </code>
<code># chkconfig --add php-fpm</code>
<code># chkconfig php-fpm on</code>
<code># service php-fpm start</code>
<code>Starting php-fpm </code><code>done</code>
<code>netstat</code> <code>–anpt</code>
<code>tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 705</code><code>/php-fpm</code>
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)在其下添加如下内容
<code>AddType application</code><code>/x-httpd-php</code> <code>.php</code>
<code>AddType application</code><code>/x-httpd-php-source</code> <code>.phps</code>
<code>DirectoryIndex index.php index.html </code><code>//</code><code>調整首頁檔案設定</code>
<code>LoadModule php5_module </code><code>/usr/lib64/httpd/modules/libphp5</code><code>.so</code>
<code>vi</code> <code>/var/www/html/test</code><code>.php </code>
<code><?php</code>
<code>phpinfo();</code>
<code>?></code>
下載下傳zabbix-3.2.1.tar.gz
<code>yum -y </code><code>install</code> <code>curl libcurl-devel net-snmp net-snmp-develperl-DBI libdbi-dbd-mysql mysql-devel gcc gcc++ </code><code>make</code> <code>libxml2 libxml2-devel</code>
# groupadd zabbix
# useradd -g zabbix -s /sbin/nologin zabbix
# tar xzvf zabbix-3.2.1.tar.gz
<code># cd zabbix-3.2.1 </code>
<code># ./configure --prefix=/usr/local/zabbix-server --enable-server --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --enable-agent --enable-ipv6 </code>
<code>make</code> <code>&& </code><code>make</code> <code>install</code>
編譯時加 --prefix=/usr/local/zabbix-server 參數,則zabbix配置檔案預設在/usr/local/zabbix-server/etc目錄下。(若編譯時沒有指定路徑,則zabbix配置檔案使用的預設路徑,在/usr/local/etc/下)
說明:
資料檔案導入的順序不能變,也可以在指令行使用mysql指令導入資料檔案
[root@test ~]# service mysqld start
修改資料庫的root密碼
[root@test ~]# mysqladmin -u root -p password 123qwe
Enter password: 這裡不用填寫直接回車即可
<code>mysql> create database zabbix character </code><code>set</code> <code>utf8; mysql> grant all on zabbix.* to zabbix@</code><code>'localhost'</code> <code>identified by </code><code>'123456'</code><code>; </code>
<code>mysql> flush privileges;</code>
<code>mysql> grant all on zabbix.* to zabbix@</code><code>'%'</code> <code>identified by </code><code>'zabbix'</code><code>;</code>
# 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> use zabbix;
Database changed
mysql> source /root/zabbix-3.2.1/database/mysql/schema.sql;
mysql> source /root/zabbix-3.2.1/database/mysql/images.sql;
mysql> source /root/zabbix-3.2.1/database/mysql/data.sql;
mkdir -p /var/www/zabbix
cp -R frontends/php /var/www/zabbix
chmod 777 /var/www/zabbix/php/conf
編輯配置檔案(server,agent)
# cd /usr/local/zabbix-server/etc
去掉配置檔案裡的注釋:
# cat zabbix_server.conf |grep -v"#" |grep -v "^$" > zabbix_server.conf.bak
# cp zabbix_server.conf.bak zabbix_server.conf
# cat zabbix_agentd.conf |grep -v"#" |grep -v "^$" > zabbix_agentd.conf.bak
# cp zabbix_agentd.conf.bak zabbix_agentd.conf
我們隻需要關注DBHost、DBName、DBUser、DBPassword幾項即可。這幾項是配置zabbix server連接配接mysql資料庫的參數。
服務端配置:
<code># vim /usr/local/zabbix-server/etc/zabbix_server.conf</code>
<code> </code><code>LogFile=</code><code>/var/log/zabbix/zabbix_server</code><code>.log</code>
<code> </code><code>DBHost=localhost</code>
<code> </code><code>DBName=zabbix</code>
<code> </code><code>DBUser=zabbix</code>
<code> </code><code>DBPassword=123456</code>
用戶端配置:
<code># vi /usr/local/zabbix-server/etc/zabbix_agentd.conf</code>
<code>LogFile=</code><code>/var/log/zabbix/zabbix_agentd</code><code>.log</code>
<code>Server=172.28.3.103</code>
<code>ServerActive=172.28.3.103</code>
<code>Hostname=172.28.3.103</code>
建立日志檔案存放位置:
mkdir /var/log/zabbix
chown -R zabbix:zabbix /var/log/zabbix
啟動zabbix服務:
/usr/local/zabbix-server/sbin/zabbix_server
<code># cd zabbix-3.2.1</code>
<code># cp misc/init.d/fedora/core/zabbix_server /etc/init.d/</code>
<code># cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/</code>
<code># chkconfig --add zabbix_server</code>
<code># chkconfig --add zabbix_agentd</code>
<code># chkconfig zabbix_server on</code>
<code># chkconfig zabbix_agentd on</code>
建立軟連結:
<code>ln</code> <code>-s </code><code>/usr/local/zabbix/sbin/zabbix_server</code> <code>/usr/local/sbin/</code>
<code>ln</code> <code>-s </code><code>/usr/local/zabbix/sbin/zabbix_agentd</code> <code>/usr/local/sbin/</code>
啟動服務:
service zabbix_server start
service zabbix_agentd start
<code># ./configure --prefix=/usr/local/zabbix-agent --enable-agent</code>
<code># cd /usr/local/zabbix-agent</code>
<code># vi etc/zabbix_agentd.conf</code>
<code>Hostname=172.28.3.100</code>
<code># ln -s /usr/local/zabbix/sbin/zabbix_agentd/usr/local/sbin/</code>
啟動服務:
<code>vim </code><code>/etc/httpd/conf</code><code>.d</code><code>/zabbix</code><code>.conf</code>
<code>#</code>
<code># Zabbix monitoring system php web frontend</code>
<code>#Alias /zabbix/usr/share/zabbix</code>
<code>Alias </code><code>/zabbix</code> <code>/var/www/zabbix/php</code>
<code><Directory</code><code>"/var/www/zabbix/php"</code><code>></code>
<code> </code><code>Options FollowSymLinks</code>
<code> </code><code>AllowOverride None</code>
<code> </code><code>Order allow,deny</code>
<code> </code><code>Allow from all</code>
<code> </code><code>#Require all granted</code>
<code> </code><code><IfModule mod_php5.c></code>
<code> </code><code>php_value max_execution_time 300</code>
<code> </code><code>php_value memory_limit 128M</code>
<code> </code><code>php_value post_max_size 16M</code>
<code> </code><code>php_value upload_max_filesize 2M</code>
<code> </code><code>php_value max_input_time 300</code>
<code> </code><code>php_value always_populate_raw_post_data -1</code>
<code> </code><code># php_value date.timezone Europe/Riga</code>
<code> </code><code>php_value </code><code>date</code><code>.timezone Asia</code><code>/Chongqing</code>
<code> </code><code><</code><code>/IfModule</code><code>></code>
<code><</code><code>/Directory</code><code>></code>
其中php_value date.timezone Asia/Chongqing主要是定義php的時區。
最後重新開機apache,zabbix服務,如下:
services httpd restart
services zabbix_server restart
然後通路http://172.28.3.103/zabbix/setup.php這個位址,如下進行安裝:
<a href="http://s4.51cto.com/wyfs02/M02/8A/FE/wKioL1hBFCHQHoSCAAD_z0IPekQ118.png-wh_500x0-wm_3-wmp_4-s_1720828857.png" target="_blank"></a>
<a href="http://s1.51cto.com/wyfs02/M00/8B/01/wKiom1hBFISC4UipAABq6MxKmkU669.jpg-wh_500x0-wm_3-wmp_4-s_1207649993.jpg" target="_blank"></a>
<a href="http://s4.51cto.com/wyfs02/M00/8A/FE/wKioL1hBFIbxxW-sAABWFbAqVek161.jpg-wh_500x0-wm_3-wmp_4-s_2347680601.jpg" target="_blank"></a>
<a href="http://s4.51cto.com/wyfs02/M01/8B/02/wKiom1hBFIbzWz4OAABpEQBPUG8093.jpg-wh_500x0-wm_3-wmp_4-s_760428242.jpg" target="_blank"></a>
<a href="http://s2.51cto.com/wyfs02/M01/8A/FE/wKioL1hBFIvRp9dNAABN51-mpPg207.jpg-wh_500x0-wm_3-wmp_4-s_3033146843.jpg" target="_blank"></a>
<a href="http://s2.51cto.com/wyfs02/M01/8B/02/wKiom1hBFIyxzmfYAAB1x1bk27Q866.jpg-wh_500x0-wm_3-wmp_4-s_2618823273.jpg" target="_blank"></a>
<code>vi /var/www/zabbix/php/conf/zabbix.conf.php</code>
<code>// Zabbix GUI configuration file.</code>
<code>global $DB;</code>
<code>$DB['TYPE'] = 'MYSQL';</code>
<code>$DB['SERVER'] = '172.28.3.103';</code>
<code>$DB['PORT'] = '3306';</code>
<code>$DB['DATABASE'] = 'zabbix';</code>
<code>$DB['USER'] = 'zabbix';</code>
<code>$DB['PASSWORD'] = 'zabbix';</code>
<code>// Schema name. Used for IBM DB2 and PostgreSQL.</code>
<code>$DB['SCHEMA'] = '';</code>
<code>$ZBX_SERVER = '172.28.3.103';</code>
<code>$ZBX_SERVER_PORT = '10051';</code>
<code>$ZBX_SERVER_NAME = '';</code>
<code>$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;</code>
<code></code>
本文轉自ling118 51CTO部落格,原文連結:http://blog.51cto.com/meiling/1878579,如需轉載請自行聯系原作者