離線電商數倉(六十二)之叢集監控(二)Zabbix(二)安裝server節點(centos)
Zabbix安裝之server節點
1 叢集規劃
節點 |
服務 |
hadoop102 |
zabbix-server、zabbix-agent、MySQL、zabbix-web |
hadoop103 |
zabbix-agent |
hadoop104 |
zabbix-agent |
2準備工作
2.1關閉防火牆(已關閉)
sudo service iptables stop
sudo chkconfig iptablesoff
2.2關閉SELinux
1) 修改配置檔案/etc/selinux/config
sudo vim /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted
2)重啟伺服器
sudoreboot
3 Zabbix-server/agent編譯及安裝
3.1建立使用者
sudo groupadd --system zabbix
sudo useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
3.2上傳zabbix安裝包並解壓
將安裝包上傳至/opt/software路徑並解壓到當前路徑
tar -zxvf zabbix-4.2.8.tar.gz
3.3建立zabbix資料庫和表
1)進入/opt/software/zabbix-4.2.8/database/mysql路徑
cd/opt/software/zabbix-4.2.8/database/mysql
2)進入MySQL客戶端執行建表語句,並匯入zabbix提供的sql指令碼
mysql> create database zabbix default character set utf8 collate utf8_bin; use zabbix; source schema.sql; source data.sql; source images.sql;
3.4 編譯環境準備
1)上傳並安裝安裝MySQL相關rpm包
sudo rpm -ivh MySQL-devel-5.6.24-1.el6.x86_64.rpm sudo rpm -ivh MySQL-embedded-5.6.24-1.el6.x86_64.rpm sudo rpm -ivh MySQL-shared-5.6.24-1.el6.x86_64.rpm sudo rpm -ivh MySQL-shared-compat-5.6.24-1.el6.x86_64.rpm
2)安裝所需依賴
sudo rpm -ivh http://www.city-fan.org/ftp/contrib/yum-repo/rhel6/x86_64/city-fan.org-release-2-1.rhel6.noarch.rpm sudo yum-config-manager --enable city-fan.org sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/Packages/l/libnghttp2-1.6.0-1.el6.1.x86_64.rpm sudo rpm -e --nodeps libxml2-python-2.7.6-21.el6.x86_64 sudo yum install -y libcurl libcurl-devel libxml2 libxml2-devel net-snmp-devel libevent-devel pcre-devel gcc-c++
3.5編譯及安裝
1)進入/opt/software/zabbix-4.2.8路徑
cd/opt/software/zabbix-4.2.8
2)編譯安裝
./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
sudo make install
3.6修改配置檔案
1)修改zabbix-server配置檔案
sudo vim /usr/local/etc/zabbix_server.conf DBHost=hadoop102 DBName=zabbix DBUser=root DBPassword=123456
2)修改zabbix-agent配置檔案
sudo vim /usr/local/etc/zabbix_agentd.conf Server=hadoop102 #ServerActive=127.0.0.1 #Hostname=Zabbix server
3.7 編寫系統服務指令碼
1)編輯zabbix-server檔案
sudovim/etc/init.d/zabbix-server
2)內容如下
#!/bin/sh # # chkconfig: - 85 15 # description: Zabbix server daemon # config: /usr/local/etc/zabbix_server.conf # ### BEGIN INIT INFO # Provides: zabbix # Required-Start: $local_fs $network # Required-Stop: $local_fs $network # Default-Start: # Default-Stop: 0 1 2 3 4 5 6 # Short-Description: Start and stop Zabbix server # Description: Zabbix server ### END INIT INFO # Source function library. . /etc/rc.d/init.d/functions if [ -x /usr/local/sbin/zabbix_server ]; then exec=/usr/local/sbin/zabbix_server else exit 5 fi prog=zabbix_server conf=/usr/local/etc/zabbix_server.conf pidfile=/tmp/zabbix_server.pid timeout=10 if [ -f /etc/sysconfig/zabbix-server ]; then . /etc/sysconfig/zabbix-server fi lockfile=/var/lock/subsys/zabbix-server start() { echo -n $"Starting Zabbix server: " daemon $exec -c $conf rv=$? echo [ $rv -eq 0 ] && touch $lockfile return $rv } stop() { echo -n $"Shutting down Zabbix server: " killproc -p $pidfile -d $timeout $prog rv=$? echo [ $rv -eq 0 ] && rm -f $lockfile return $rv } restart() { stop start } case "$1" in start|stop|restart) $1 ;; force-reload) restart ;; status) status -p $pidfile $prog ;; try-restart|condrestart) if status $prog >/dev/null ; then restart fi ;; reload) action $"Service ${0##*/} does not support the reload action: " /bin/false exit 3 ;; *) echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}" exit 2 ;; esac
3)加執行許可權
sudochmod+x /etc/init.d/zabbix-server
4)編輯zabbix-agent檔案
sudovim/etc/init.d/zabbix-agent
5)內容如下
#!/bin/sh # # chkconfig: - 86 14 # description: Zabbix agent daemon # processname: zabbix_agentd # config: /usr/local/etc/zabbix_agentd.conf # ### BEGIN INIT INFO # Provides: zabbix-agent # Required-Start: $local_fs $network # Required-Stop: $local_fs $network # Should-Start: zabbix zabbix-proxy # Should-Stop: zabbix zabbix-proxy # Default-Start: # Default-Stop: 0 1 2 3 4 5 6 # Short-Description: Start and stop Zabbix agent # Description: Zabbix agent ### END INIT INFO # Source function library. . /etc/rc.d/init.d/functions if [ -x /usr/local/sbin/zabbix_agentd ]; then exec=/usr/local/sbin/zabbix_agentd else exit 5 fi prog=zabbix_agentd conf=/usr/local/etc/zabbix_agentd.conf pidfile=/tmp/zabbix_agentd.pid timeout=10 if [ -f /etc/sysconfig/zabbix-agent ]; then . /etc/sysconfig/zabbix-agent fi lockfile=/var/lock/subsys/zabbix-agent start() { echo -n $"Starting Zabbix agent: " daemon $exec -c $conf rv=$? echo [ $rv -eq 0 ] && touch $lockfile return $rv } stop() { echo -n $"Shutting down Zabbix agent: " killproc -p $pidfile -d $timeout $prog rv=$? echo [ $rv -eq 0 ] && rm -f $lockfile return $rv } restart() { stop start } case "$1" in start|stop|restart) $1 ;; force-reload) restart ;; status) status -p $pidfile $prog ;; try-restart|condrestart) if status $prog >/dev/null ; then restart fi ;; reload) action $"Service ${0##*/} does not support the reload action: " /bin/false exit 3 ;; *) echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}" exit 2 ;; esac
6)加執行許可權
sudochmod+x /etc/init.d/zabbix-agent
4 部署Zabbix-web
4.1 部署httpd
1)安裝httpd
sudoyum-y install httpd
2)修改httpd配置檔案
sudo vim /etc/httpd/conf/httpd.conf
將以下紅色部分放至改配置檔案的對應位置
317 <Directory "/var/www/html"> 318 319 # 320 # Possible values for the Options directive are "None", "All", 321 # or any combination of: 322 # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews 323 # 324 # Note that "MultiViews" must be named *explicitly* --- "Options All" 325 # doesn't give it to you. 326 # 327 # The Options directive is both complicated and important. Please see 328 # http://httpd.apache.org/docs/2.2/mod/core.html#options 329 # for more information. 330 # 331 Options Indexes FollowSymLinks 332 333 # 334 # AllowOverride controls what directives may be placed in .htaccess files. 335 # It can be "All", "None", or any combination of the keywords: 336 # Options FileInfo AuthConfig Limit 337 # 338 AllowOverride None 339 340 # 341 # Controls who can get stuff from this server. 342 # 343 Order allow,deny 344 Allow from all 345 <IfModule mod_php5.c> 346 php_value max_execution_time 300 347 php_value memory_limit 128M 348 php_value post_max_size 16M 349 php_value upload_max_filesize 2M 350 php_value max_input_time 300 351 php_value max_input_vars 10000 352 php_value always_populate_raw_post_data -1 353 php_value date.timezone Asia/Shanghai 354 </IfModule> 355 356 </Directory>
3)拷貝zabbix-web的php檔案到httpd的指定目錄
sudo mkdir /var/www/html/zabbix
sudo cp -a /opt/software/zabbix-4.2.8/frontends/php/* /var/www/html/zabbix/
4.2安裝php5.6
1)安裝yum源
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm sudo rpm -ivh epel-release-6-8.noarch.rpm remi-release-6.rpm
2)啟用yum源
sudo yum-config-manager --enable remi-php56
3)安裝php及相關元件
sudo yum install -y php php-bcmath php-mbstring php-xmlwriter php-xmlreader php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo
5 Zabbix啟動
5.1啟動Zabbix-Server
1)啟動
sudoservicezabbix-server start
2)開機自啟
sudochkconfig--add zabbix-server
sudo chkconfig zabbix-server on
2.5.2啟動Zabbix-Agent
1)啟動
sudoservicezabbix-agent start
2)開機自啟
sudochkconfig--add zabbix-agent
sudo chkconfig zabbix-agent on
2.5.3 啟動Zabbix-Web(httpd)
1)啟動
sudoservicehttpdstart
2)開機自啟
sudo chkconfig httpdon
6Zabbix登入
1)瀏覽器訪問http://hadoop102/zabbix
2)檢查配置
3)配置資料庫
4)配置zabbix-server
5)下載配置檔案,並上傳至指定路徑
6)登入,使用者名稱:Admin,密碼zabbix