您好,登錄后才能下訂單哦!
1. zabbix3.0實驗環境
Nginx:1.10.2 Mysql: 5.6.33 PHP:5.6.12 Zabbix:3.0.5 Zabbix_server_IP: 192.168.10.150(基于LNMP) Zabbix_client_IP: 192.168.10.106
2. 準備環境LAMP
# 更換下載源 wget -O /etc/yum.repos.d/CentOS-Base.repo yum clean all yum makecache # 清理已經安裝的包 rpm -e httpd mysql php yum remove -y httpd php mysql* # 下載NMP源碼包 wget -P /tmp http://nginx.org/download/nginx-1.10.2.tar.gz wget -P /tmp http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.33.tar.gz wget -P /tmp http://mirrors.sohu.com/php/php-5.6.12.tar.gz # 下載編譯環境的依賴包 yum install -y gcc gcc-c++ ncurses-devel
3. 安裝mysql
# 創建mysql用戶和組,不允許登陸和不創建主目錄(如果提示用戶存在,修改命令為usermod) groupadd mysql useradd -s /sbin/nologin -g mysql -m mysql # 安裝cmake(Mysql從5.5版本./configure配置方式已取消,所以需要安裝cmake工具) # tar -zxvf cmake-2.18.2.2.tar.gz -C /opt cd /opt/cmake-2.18.2.2 ./configure make && make install # 使用cmake來編譯安裝mysql,如果提示缺少某包,安裝某包后刪除CMakeCache.txt重新運行cmake tar -zxvf /tmp/mysql-5.6.33.tar.gz -C /opt/ cd /opt/mysql-5.6.33 cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DSYSCONFDIR=/etc \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_MEMORY_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DMYSQL_USER=mysql \ -DWITH_DEBUG=0 \ -DWITH_SSL=system make && make install # 修改/usr/local/mysql權限 chmod +w /usr/local/mysql chown -R mysql:mysql /usr/local/mysql # 拷貝配置文件 cp ./support-files/my-default.cnf /etc/my.cnf # 初始化數據庫 /usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql # 拷貝啟動文件,設置開機啟動 cp support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld chkconfig mysqld on /etc/init.d/mysqld start echo 'export PATH=$PATH:/usr/local/mysql/bin/' >> /etc/profile # 默認登錄不需要密碼,需要設置個root密碼 mysqladmin -uroot -p password 'Admin123' # 查看數據庫里的用戶 select user,host from mysql.user; # 刪除沒必要的用戶 drop user root@'::1'; # 賦予賬號遠程訪問的權限 GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY '你的密碼' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '你的密碼' WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'root'@'zabbix' IDENTIFIED BY '你的密碼' WITH GRANT OPTION; # 查看數據庫版本 mysql -uroot -p"密碼" -e "select version();"
4. 安裝php
# 下載php依賴包 yum install -y libxml2-devel openssl-devel libcurl-devel libjpeg-turbo-devel libpng-devel freetype-devel libmcrypt-devel # 解壓php壓縮包 tar -zxvf /tmp/php-5.6.12.tar.gz -C /opt cd /opt/php-5.6.12 ./configure --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --enable-fpm \ --with-fpm-user=www \ --with-fpm-group=www \ --with-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --with-iconv-dir \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir=/usr \ --enable-xml \ --disable-rpath \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --with-curl \ --enable-mbregex \ --enable-mbstring \ --with-mcrypt \ --enable-ftp \ --with-gd \ --enable-gd-native-ttf \ --with-openssl \ --with-mhash \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --enable-soap \ --without-pear \ --with-gettext \ --disable-fileinfo \ --enable-maintainer-zts make && make install # 修改fpm配置php-fpm.conf.default名稱 mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf # 復制php.ini配置文件 cp php.ini-production /usr/local/php/etc/php.ini # 復制啟動腳本到init.d下 cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x !$ # 添加啟動項 chkconfig php-fpm on # 按照上面標準,給php創建用戶和用戶組 groupadd www useradd -s /sbin/nologin -g www -M www # 啟動php-fpm service php-fpm start
5. 安裝nginx
# 安裝nginx依賴包,一般我們都需要先裝pcre, zlib,前者為了重寫rewrite,后者為了gzip壓縮 yum install zlib-devel pcre-devel # 開始安裝nginx tar -zxvf /tmp/nginx-1.10.2.tar.gz -C /opt cd /opt/nginx-1.10.2 ./configure --prefix=/usr/local/nginx \ --pid-path=/usr/local/nginx/nginx.pid \ --error-log-path=/usr/local/nginx/error.log \ --http-log-path=/usr/local/nginx/access.log \ --with-http_ssl_module --with-mail \ --with-mail_ssl_module --with-stream \ --with-threads make && make install # 編輯nginx配置文件 vim /usr/local/nginx/conf/nginx.conf 如果nginx無法解析php文件,訪問為404.則將此段修改為如下 location ~ \.php$ { root /usr/local/nginx/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; } # 編輯nginx啟動腳本 vim /etc/init.d/nginx #!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) sysconfig="/etc/sysconfig/$prog" lockfile="/var/lock/subsys/nginx" pidfile="/usr/local/nginx/nginx.pid" NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" [ -f $sysconfig ] && . $sysconfig start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc -p $pidfile $prog retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest_q || return 6 stop start } reload() { configtest_q || return 6 echo -n $"Reloading $prog: " killproc -p $pidfile $prog -HUP echo } configtest() { $nginx -t -c $NGINX_CONF_FILE } configtest_q() { $nginx -t -q -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } # Upgrade the binary with no downtime. upgrade() { local oldbin_pidfile="${pidfile}.oldbin" configtest_q || return 6 echo -n $"Upgrading $prog: " killproc -p $pidfile $prog -USR2 retval=$? sleep 1 if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]]; then killproc -p $oldbin_pidfile $prog -QUIT success $"$prog online upgrade" echo return 0 else failure $"$prog online upgrade" echo return 1 fi } # Tell nginx to reopen logs reopen_logs() { configtest_q || return 6 echo -n $"Reopening $prog logs: " killproc -p $pidfile $prog -USR1 retval=$? echo return $retval } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest|reopen_logs) $1 ;; force-reload|upgrade) rh_status_q || exit 7 upgrade ;; reload) rh_status_q || exit 7 $1 ;; status|status_q) rh_$1 ;; condrestart|try-restart) rh_status_q || exit 7 restart ;; *) echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}" exit 2 esac # 啟動nginx chmod +x /etc/init.d/nginx service nginx start chkconfig nginx on # 測試訪問php是否正常 vim /usr/local/nginx/www/phpinfo.php <?php phpinfo(); ?> curl localhost/phpinfo.php -I
6. 編譯安裝zabbix3.0.5
tar -zxvf /tmp/zabbix-3.0.5.tar.gz -C /opt cd /opt/zabbix-3.0.5 # 創建zabbix進程用戶和組 groupadd zabbix useradd -s /sbin/nologin -g zabbix -M zabbix # 下載依賴包 yum install -y net-snmp-devel libssh3-devel # 開始安裝zabbix ./configure --prefix=/usr/local/zabbix \ --enable-server --enable-agent \ --with-mysql --with-net-snmp \ --with-libcurl --with-libxml2 \ --with-ssh3 make && make install # 驗證安裝結果 /usr/local/zabbix/sbin/zabbix_server -V 檢查到錯誤:error while loading shared libraries: libmysqlclient.so.18: ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18 /usr/local/zabbix/sbin/zabbix_server -V /usr/local/zabbix/sbin/zabbix_agentd -V netstat -lnp|grep zabbix # 如果server端未啟動,檢查日志文件/tmp/zabbix_server.log # 修改/usr/local/zabbix/etc/zabbix_server.conf配置文件數據庫連接 [root@zabbix_server ~]# egrep -v "^#|^$" /usr/local/zabbix/etc/zabbix_server.conf LogFile=/tmp/zabbix_server.log DBHost=127.0.0.1 DBName=zabbix DBUser=zabbix DBSocket=/var/lib/mysql/mysql.sock DBPassword=Admin123 DBPort=3306 Timeout=4 LogSlowQueries=3000 # 配置zabbix數據庫 mysql -uroot -p -e 'create database zabbix;' # 創建數據庫授權用戶,僅允許192.168.0.0網段登錄 mysql -uroot -p -e "grant all privileges on zabbix.* to zabbix@'192.168.%' identified by 'Admin123';" mysql -uroot -p -e "grant all privileges on zabbix.* to zabbix@'127.0.0.1' identified by 'Admin123';" mysql -uroot -p -e "flush privileges;" # 導入zabbix數據庫,文件在解壓包下的database里 mysql -u zabbix -p -h 192.168.10.150 zabbix < database/mysql/schema.sql mysql -u zabbix -p -h 192.168.10.150 zabbix < database/mysql/p_w_picpaths.sql mysql -u zabbix -p -h 192.168.10.150 zabbix < database/mysql/data.sql # 查看zabbix是否有數據 mysql -u zabbix -p -h 192.168.10.150 -e "show tables from zabbix;" # # 添加啟動腳本 cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd cp misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server # 修改啟動腳本 sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g" /etc/init.d/zabbix_server sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g" /etc/init.d/zabbix_agentd # 修改zabbix配置文件(/usr/local/zabbix/etc/zabbix_server.conf) # 添加到開機啟動 chmod +x /etc/init.d/zabbix_server chmod +x /etc/init.d/zabbix_agentd chkconfig zabbix_server --level 35 on chkconfig zabbix_agentd --level 35 on # 拷貝網頁到nginx目錄下 cp -rfp frontends/php/* /usr/local/nginx/zabbix/ -R chown -R root:root /usr/local/nginx/zabbix # 修改nginx配置文件為如下(/usr/local/nginx/nginx.conf) server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { # root zabbix; root /usr/local/nginx/zabbix; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { root /usr/local/nginx/zabbix; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi_params; } # 重新加載nginx(/etc/init.d/nginx reload)
7. zabbix界面安裝
界面檢查配置出錯
錯誤1:
Minimum required size of PHP post is 16M (configuration option "post_max_size").
Minimum required limit on execution time of PHP scripts is 300 (configuration option "max_execution_time").
Minimum required limit on input parse time for PHP scripts is 300 (configuration option "max_input_time").
Time zone for PHP is not set (configuration parameter "date.timezone").
PHP option "always_populate_raw_post_data" must be set to "-1"
這一步默認的php.ini一般都有錯誤:
修改/usr/local/php/etc/php.ini即可解決
post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = "Asia/Shanghai"
always_populate_raw_post_data = -1
重啟php-fpm即可
#/etc/init.d/php-fpm56 restart
錯誤2:
Install
Cannot create the configuration file.
Details
Unable to create the configuration file.
下載那個頁面,然后上傳到/usr/local/nginx/zabbix/conf下(網頁有提升具體路徑)
8. 配置中文支持
左上角倒數第二個圖標---language---Chinese(zh_CN)
9. 配置圖片中文支持
將/usr/local/nginx/zabbix/include/defines.inc.php
第45行改為
define('ZBX_GRAPH_FONT_NAME', 'simkai'); // font file name
第93行改為
define('ZBX_FONT_NAME', 'simkai');
1)從windows控制面板->字體>選擇一種中文字庫例如“楷體”
2)將字體復制到/usr/local/nginx/zabbix/fonts下
3)最后在用戶中設置
zabbix網頁界面---管理--用戶---admin--語言選擇中文
注意:
如果有防火墻的話,添加幾條語句
iptables -A INPUT -p tcp --dport 80 -d 192.168.10.150 -j ACCEPT iptables -A INPUT -P tcp --dport 10050 -d 192.168.10.150 -j ACCEPT iptables -A INPUT -P tcp --dport 10051 -d 192.168.10.150 -j ACCEPT
zabbix就安裝完成了
參考zabbix界面安裝文檔:http://blog.csdn.net/cy309173854/article/details/52608015
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。