操做系統:php
[root@mysql ~]# cat /etc/redhat-releasehtml
CentOS Linux release 7.5.1804 (Core)java
Mysql : 版本5.7.23 192.168.75.251node
Zabbix Server:版本3.4.12 192.168.75.250mysql
關閉防火牆linux
# systemctl stop firewalldc++
# systemctl disable firewalldgit
vi /etc/selinux/configweb
SELINUX=enforcing 改成 SELINUX= disabledredis
Centos7 默認數據庫爲mariadb ,先卸載
rpm –qa |grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
這個版本須要boost 1.9,也要下載
[root@mysql soft]# ll
total 132444
-rw-r--r-- 1 root root 83709983 Aug 10 10:26 boost_1_59_0.tar.gz
-rw-r--r-- 1 root root 51907462 Aug 10 10:26 mysql-5.7.23.tar.gz
添加mysql用戶,
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
yum install -y cmake bison bison-devel libaio-devel gcc gcc-c++ git ncurses-devel
解壓mysql ,把boost的壓縮版放到解壓後的mysql目錄內
tar xzvf mysql-5.7.23.tar.gz
mv boost_1_59_0.tar.gz mysql-5.7.23
進入MySQL源文件目錄,新建configure作爲編譯目錄,並進入該目
cd mysql-5.7.23
mkdir configure
cd configure
使用cmake進行生成編譯環境,
cmake .. -DBUILD_CONFIG=mysql_release \
-DINSTALL_LAYOUT=STANDALONE \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DENABLE_DTRACE=OFF \
-DWITH_EMBEDDED_SERVER=OFF \
-DWITH_INNODB_MEMCACHED=ON \
-DWITH_SSL=bundled \
-DWITH_ZLIB=system \
-DWITH_PAM=ON \
-DCMAKE_INSTALL_PREFIX=/var/mysql/ \
-DINSTALL_PLUGINDIR="/var/mysql/lib/plugin" \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EDITLINE=bundled \
-DFEATURE_SET=community \
-DCOMPILATION_COMMENT="MySQL Server (GPL)" \
-DWITH_DEBUG=OFF \
-DWITH_BOOST=..
安裝
make && make install
修改配置文件
vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/mysql/mysql.sock
port=3306
log_error=/var/mysql/log/error.log
basedir=/var/mysql/
[client]
socket=/var/mysql/mysql.sock
chown mysql.mysql /etc/my.cnf
建立日誌文件
mkdir -p /var/mysql/log
touch /var/mysql/log/error.log
touch /var/mysql/mysql.sock
chown -R mysql.mysql /var/mysql/
#/var/mysql/bin/mysqld --initialize --user=mysql
查看數據文件是否生成
#ll /var/lib/mysql
total 110628
-rw-r----- 1 mysql mysql 56 Aug 10 11:06 auto.cnf
-rw-r----- 1 mysql mysql 417 Aug 10 11:06 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Aug 10 11:06 ibdata1
-rw-r----- 1 mysql mysql 50331648 Aug 10 11:06 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Aug 10 11:06 ib_logfile1
drwxr-x--- 2 mysql mysql 4096 Aug 10 11:06 mysql
drwxr-x--- 2 mysql mysql 8192 Aug 10 11:06 performance_schema
drwxr-x--- 2 mysql mysql 8192 Aug 10 11:06 sys
查看日誌文件是否生成
# ll /var/mysql/log
臨時密碼生成放在 error.log中
# cat /var/mysql/log/error.log
2019-11-18T09:06:22.922254Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-18T09:06:24.600401Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-11-18T09:06:24.853258Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-11-18T09:06:24.915246Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 5dbf9eac-9c4a-11e8-8768-000c29a48522.
2019-11-18T09:06:24.916709Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-11-18T09:06:24.917772Z 1 [Note] A temporary password is generated for root@localhost: NS0+>RzwvHWl
修改初始密碼、修改環境變量
從模板文件中複製啓動文件:
cp /var/mysql/support-files/mysql.server /etc/init.d/mysqld
修改啓動文件:
vim /etc/init.d/mysqld
找到以下二行:
basedir=
datadir=
修改成:
basedir=/var/mysql/
datadir=/var/lib/mysql
更改權限
#chown -R mysql.mysql /var/mysql /var/lib/mysql
啓動
/etc/init.d/mysqld start
ln -s /var/mysql/bin/mysql /usr/bin
配置MySQL環境變量:
vim /root/.bash_profile
找到下面一行:
PATH=$PATH:$HOME/bin
修改成:
PATH=$PATH:$HOME/bin:/var/mysql/bin
利用上面生成的臨時密碼,登陸
# mysql –u root –p NS0+>RzwvHWl
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.23
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
更改初始密碼
mysql> alter user 'root'@'localhost' identified by '123456';
安裝php7.1版本,zabbix3.0版本要求php5.4及以上。
先查看本地php版本
php -v
檢查當前php的安裝包
yum list installed | grep php
將本地php安裝包卸載乾淨
yum remove php*
默認的yum源沒法升級PHP,須要添加第三方yum源,咱們選擇webtatic庫
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安裝php7.1
yum install -y php71w
安裝相關插件
yum install -y php71w-fpm php71w-opcache php71w-cli php71w-gd php71w-imap php71w-mysqlnd php71w-mbstring php71w-mcrypt php71w-pdo php71w-pecl-apcu php71w-pecl-mongodb php71w-pecl-redis php71w-pgsql php71w-xml php71w-xmlrpc php71w-devel mod_php71w php71w-ldap php71w-bcmath
修改PHP的配置參數
vim /etc/php.ini
date.timezone= Asia/Shanghai
max_execution_time = 300
post_max_size = 32M
memory_limit = 128M
mbstring.func_overload = 1
max_input_time = 300
Session調整權限,
chmod -R 777 /var/lib/php/session/
安裝依賴包
yum -y install gcc* make curl curl-devel net-snmp net-snmp-devel perl-DBI httpd mariadb* mysql-devel libxml2-devel curl-devel unixODBC-devel net-snmp-devel OpenIPMI-devel openldap openldap-devel libevent-devel java-devel libssh2-devel
建立zabbix用戶和組
groupadd zabbix
useradd -g zabbix zabbix
編譯、安裝
tar zxvf zabbix-3.4.12.tar.gz
cd zabbix-3.4.12/
./configure --prefix=/usr/local/zabbix --enable-server --enable-proxy --enable-agent --enable-ipv6 --with-mysql --with-net-snmp --with-libcurl --with-openipmi --with-unixodbc --with-ldap --with-ssh2 --enable-java
make && make install
chown -R zabbix.zabbix /usr/local/zabbix
修改zabbix配置文件
vi /usr/local/zabbix/etc/zabbix_server.conf
LogFile=/tmp/zabbix_server.log
DebugLevel=3
DBHost=192.168.75.251 #server和數據庫分離的寫法
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/mysql/mysql.sock
DBPort=3306
StartPollers=10
Timeout=4
AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts
LogSlowQueries=3000
CacheSize=1024M
後期配置文件的參數,根據需求作調整。
把zabbix程序包中的幾個sql文件傳到上面的mysql服務器,導入數據庫文件
[root@zabbix ~]# cd /opt/soft/zabbix-3.4.12/database/mysql
[root@zabbix mysql]# ll
total 4876
-rw-r--r--. 1 1001 1001 2877497 Jul 30 19:41 data.sql
-rw-r--r--. 1 1001 1001 1978341 Jul 30 19:41 images.sql
-rw-r--r--. 1 1001 1001 134791 Jul 30 19:41 schema.sql
[root@zabbix mysql]# scp * root@192.168.75.251:/opt/
下面在mysql(192.168.75.251)服務器上操做
#mysql -u root –p
Enter password:
建立zabbix數據庫,字符集設置爲utf8
mysql>create database zabbix character set utf8 collate utf8_bin;
在mysql數據庫中建立zabbix用戶,賦予zabbix用戶對zabbix數據庫的所有權限,容許zabbix服務器遠程訪問mysql
mysql>GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@192.168.75.250 IDENTIFIED BY 'zabbix';
mysql>GRANT ALL PRIVILEGES ON zabbix.* TO zabbix@localhost IDENTIFIED BY 'zabbix';
mysql> flush privileges ;
mysql> show databases ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)
導入數據文件,在控制檯操做
#mysql -u zabbix -p zabbix <schema.sql
#mysql -u zabbix -p zabbix <images.sql
#mysql -u zabbix -p zabbix <data.sql
回到Zabbix Server主機操做。在上面已經安裝好httpd , 建立apache下建立zabbix目錄
mkdir /var/www/html/zabbix
拷貝zabbix包中的web界面到apache zabbix目錄下
\cp–rf /opt/soft/zabbix-3.4.12/frontends/php/* /var/www/html/zabbix/
配置web安全
chown -R apache.apache /var/www/html/zabbix
chmod a+x /var/www/html/zabbix/conf/
拷貝zabbix包中服務啓動腳本(server/agentd)到linux系統服務啓動目錄
cp /opt/soft/zabbix-3.4.12/misc/init.d/fedora/core/zabbix_server zabbix_agentd/etc/init.d/
修改/etc/init.d/zabbix_server和/etc/init.d/zabbix_agentd
BASEDIR=/usr/local修改爲
BASEDIR=/usr/local/zabbix/
設置開機啓動
systemctl enable httpd
systemctl enable zabbix_server
systemctl enable zabbix_agentd
/etc/init.d/zabbix_server start
/etc/init.d/zabbix_agentd start
systemctl start httpd
http://192.168.75.250/zabbix/setup.php
鏈接數據庫設置,寫mysql服務器所在機器,端口,數據庫名稱,用戶、密碼
首先,在proxy機器上安裝mysql ,跟上面的安裝步驟同樣,只是在導入mysql文件時,只導入一個文件,
#mysql –uzabbix –p zabbix <schema.sql
安裝依賴包
yum -y install gcc* make curl curl-devel net-snmp net-snmp-devel perl-DBI httpd mariadb* mysql-devel libxml2-devel curl-devel unixODBC-devel net-snmp-devel OpenIPMI-devel openldap openldap-devel libevent-devel java-devel libssh2-devel
建立zabbix用戶和組
groupadd zabbix
useradd -g zabbix zabbix
編譯、安裝
tar zxvf zabbix-3.4.12.tar.gz
cd zabbix-3.4.12/
./configure --prefix=/opt/server/zabbix_proxy --enable-proxy --enable-agent --enable-ipv6 --with-mysql --with-net-snmp --with-libcurl --with-openipmi --with-unixodbc --with-ldap --with-ssh2 --enable-java
make && make install
chown -R zabbix.zabbix /opt/server/zabbix_proxy
配置文件修改
Vi /usr/local/zabbix/etc/zabbix_proxy.conf
Server=192.168.75.250
ServerPort=10051
Hostname=zabbix_proxy
LogFile=/tmp/zabbix_proxy.log
DBHost=localhost #由於mysql和proxy安裝在同一臺機器
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/var/mysql/mysql.sock
ConfigFrequency=60
DataSenderFrequency=60
StartPollers=5
Timeout=4
LogSlowQueries=3000
啓動proxy(要加入到開機自啓)
#/opt/server/zabbix_proxy/sbin/zabbix_proxy-c /opt/server/zabbix_proxy/etc/zabbix_proxy.conf
systemctl enable zabbix_proxy
同上,編譯安裝zabbix時,客戶端也一塊兒編譯了,把/usr/local 下面的zabbix目錄拷貝到客戶端,
修改配置文件
vi /usr/local/zabbix/etc/zabbix_agentd.conf
Server=zabbix_proxy_IP #建議因此客戶端都掛在proxy上,擴展性強
Hostname=zabbix_agentd_hostname #填寫客戶端的主機名
啓動(要加入到開機自啓)
/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf
echo "/usr/local/agent/sbin/zabbix_agentd -c /usr/local/agent/etc/zabbix_agentd.conf" >> /etc/rc.local
添加監控主機
選擇主機監控模版
主機監控成功
原文出處:https://www.cnblogs.com/canyezhizi/p/11891312.html