本文檔分爲四個部分javascript
一、安裝要求php
二、服務器優化配置css
三、安裝lnmp環境html
四、安裝zabbix-server及zabbix-agent前端
第一部分:安裝要求java
Zabbix4.0官方文檔表示:若是剛接觸 Zabbix,128Mb的物理內存和 256Mb的可用磁盤空間多是一個很好的起點。 然而,所需的內存和磁盤空間顯然取決於被監控的主機數量和配置參數。 若是您計劃調整參數以保留較長的歷史數據,那麼您應該考慮至少有幾Gb磁盤空間,以便有足夠的磁盤空間將歷史數據存儲在數據庫中。node
建議初次安裝使用2C4G的服務器mysql
如下是官方給出的數據服務器配置信息nginx
規模 | 平臺 | CPU/內存 | 數據庫 | 受監控的主機數量 |
---|---|---|---|---|
小型 | CentOS | Virtual Appliance | MySQL InnoDB | 100 |
中型 | CentOS | 2 CPU cores/2GB | MySQL InnoDB | 500 |
大型 | RedHat Enterprise Linux | 4 CPU cores/8GB | RAID10 MySQL InnoDB 或 PostgreSQL | >1000 |
極大型 | RedHat Enterprise Linux | 8 CPU cores/16GB | Fast RAID10 MySQL InnoDB 或 PostgreSQL | >10000 |
##本次安裝使用的是2C4G 40G的雲主機,c++
##本次安裝須要的安裝包,能夠去官方網站下載,也能夠在個人網盤提取 https://pan.baidu.com/s/1Fr5isbMT3j76tt1g2PRHjA
提取碼g2xu
第二部分,服務器優化(操做用戶:root)
一、設置主機名
hostnamectl set-hostname tianyiyun
二、安裝經常使用包
yum -y install lrzsz openssl openssl-devel gcc-c++
三、調整系統內核參數
cp /etc/sysctl.conf /etc/sysctl.conf.bak
vi /etc/sysctl.conf
net.ipv4.ip_forward = 1 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0 kernel.core_uses_pid = 1 net.ipv4.tcp_syncookies = 1 kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 68719476736 kernel.shmall = 4294967296 net.ipv4.tcp_max_tw_buckets = 65536 net.ipv4.tcp_sack = 1 net.ipv4.tcp_window_scaling = 1 net.ipv4.tcp_rmem = 4096 87380 4194304 net.ipv4.tcp_wmem = 4096 16384 4194304 net.ipv4.tcp_max_orphans = 3276800 net.ipv4.tcp_max_syn_backlog = 819200 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_synack_retries = 1 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_mem = 94500000 915000000 927000000 net.ipv4.tcp_fin_timeout = 1 net.ipv4.tcp_keepalive_time = 30 net.ipv4.tcp_sack = 0 net.ipv4.ip_local_port_range = 1024 65000 net.ipv4.conf.default.rp_filter = 0 net.core.optmem_max = 65535 net.ipv4.tcp_keepalive_probes = 5 net.ipv4.tcp_keepalive_intvl = 15 net.ipv4.tcp_retries2 = 5 net.ipv4.tcp_orphan_retries = 3 net.ipv4.tcp_reordering = 5 net.ipv4.tcp_retrans_collapse = 0 net.core.wmem_default = 8388608 net.core.rmem_default = 8388608 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.core.netdev_max_backlog = 262144 net.core.somaxconn = 262144 fs.file-max = 2000000
sysctl -p
四、建立nginx系統用戶
groupadd -r nginx
useradd -r -g nginx -s /sbin/nologin nginx
五、設置打開文件數限制
vi /etc/security/limits.conf
* soft nofile 65535* hard nofile 65535* soft noproc 65535* hard noproc 65535
六、重啓使以前設置生效
reboot
官方文檔表示:Zabbix 前端是 PHP 編寫的,因此必須運行在支持 PHP 的 Web 服務器上。而zabbix須要數據庫的支持,官方建議的數據庫管理系統有MySQL、Oracle、SQLite等。
因此咱們首先須要安裝nginx web服務以及php中間件;而數據庫固然使用開源的MySQL
第三部分:安裝lnmp環境提供zabbix ui管理界面和數據庫
安裝nginx
一、下載nginx安裝包,同時你也須要下載zlib-1.2.8.tar.gz,pcre-8.39.tar.gz
[安裝包nginx-1.16.1.tar.gz pcre-8.39.tar.gz zlib-1.2.8.tar.gz上傳到/opt]
cd /opt/
wget http://nginx.org/download/nginx-1.16.1.tar.gz
二、解壓3個源碼包
tar zxf zlib-1.2.8.tar.gz
tar zxf pcre-8.39.tar.gz
tar zxf nginx-1.16.1.tar.gz
三、編譯安裝nginx
cd nginx-1.16.1/
./configure --prefix=/opt/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre=/opt/pcre-8.39 --with-zlib=/opt/zlib-1.2.8 --user=nginx --group=nginx
make
make install
/opt/nginx/sbin/nginx -t
(可使用nginx -t用於測試是否完成安裝)
四、修改nginx配置文件
(此次nginx配置文件沒有進行優化,直接拿nginx自帶的修改瞭如下)
cp /opt/nginx/conf/nginx.conf /opt/nginx/conf/nginx.conf.bak
vi /opt/nginx/conf/nginx.conf
user nginx; worker_processes 2; worker_cpu_affinity 01 10; error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info;pid logs/nginx.pid; events { use epoll; worker_connections 65535; multi_accept on; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; tcp_nopush on; keepalive_timeout 65; tcp_nodelay on; client_header_buffer_size 4k; open_file_cache max=102400 inactive=20s; open_file_cache_valid 30s; open_file_cache_min_uses 1; client_header_timeout 15; client_body_timeout 15; reset_timedout_connection on; send_timeout 15; server_tokens off; client_max_body_size 10m; fastcgi_connect_timeout 600; fastcgi_send_timeout 600; fastcgi_read_timeout 600; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; fastcgi_temp_path /opt/nginx/nginx_tmp; fastcgi_intercept_errors on; fastcgi_cache_path /opt/nginx/fastcgi_cache levels=1:2 keys_zone=cache_fastcgi:128m inactive=1d max_size=10g; gzip on; gzip_min_length 2k; gzip_buffers 4 32k; gzip_http_version 1.1; gzip_comp_level 6; gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml; gzip_vary on; gzip_proxied any; server { listen 8008; server_name localhost; charset utf-8; location / { root html; index index.php index.html index.htm; } location ~* \.(ico|jpe?g|gif|png|bmp|swf|flv)$ { root html; expires 30d; access_log off; } location ~* \.(js|css)$ { root html; expires 7d; log_not_found off; access_log off; } location = /(favicon.ico|roboots.txt) { root html; access_log off; log_not_found off; } location /status { stub_status on; } location ~ .*\.(php|php5)?$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_cache cache_fastcgi; fastcgi_cache_valid 200 302 1h; fastcgi_cache_valid 301 1d; fastcgi_cache_valid any 1m; fastcgi_cache_min_uses 1; fastcgi_cache_use_stale error timeout invalid_header http_500; fastcgi_cache_key http://$host$request_uri; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
五、啓動nginx
/opt/nginx/sbin/nginx
安裝php
一、[安裝包php-7.3.16.tar.gz上傳至/opt]
安裝php所需
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libzip-devel pcre-devel
二、編譯安裝php
cd /opt
tar -zxf php-7.3.16.tar.gz
cd /opt/php-7.3.16
./configure --prefix=/opt/php --with-config-file-path=/opt/php/etc --with-config-file-scan-dir=/opt/php/etc/php.d --enable-mysqlnd --with-mysqli --with-pdo-mysql --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-gd --with-iconv --with-zlib --enable-xml --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-ftp --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --enable-opcache
make test
make
make install
三、準備php配置文件以及啓動文件
cp /opt/php-7.3.16/php.ini-production /opt/php/etc/php.ini
cp /opt/php-7.3.16/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf
cp /opt/php/etc/php-fpm.d/www.conf.default /opt/php/etc/php-fpm.d/www.conf
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
(查看狀態)
chkconfig --list php-fpm
sed -i 's#;pid = run/php-fpm.pid#pid = run/php-fpm.pid#g' /opt/php/etc/php-fpm.conf
sed -i 's/listen = 127.0.0.1:9000/listen = 0.0.0.0:9000/g' /opt/php/etc/php-fpm.conf
sed -i 's/pm.max_children = 5/pm.max_children = 300/g' /opt/php/etc/php-fpm.conf
sed -i 's/pm.start_servers = 2/pm.start_servers = 10/g' /opt/php/etc/php-fpm.conf
sed -i 's/pm.min_spare_servers = 1/pm.min_spare_servers = 10/g' /opt/php/etc/php-fpm.conf
sed -i 's/pm.max_spare_servers = 3/pm.max_spare_servers = 50/g' /opt/php/etc/php-fpm.conf
四、啓動php-fpm
service php-fpm start
netstat -anpt | grep 9000
(查看狀態)
安裝MySQL
一、上傳mysql安裝包,建立mysql用戶
[上傳安裝包mysql-5.7.29-el7-x86_64.tar.gz到/opt]
groupadd -r mysql
useradd -r -g mysql -s /bin/false -M mysql
二、安裝
cd /opt
tar zxf mysql-5.7.29-el7-x86_64.tar.gz
將mysql綠色軟件包改個名字
mv mysql-5.7.29-el7-x86_64 mysql
卸載自帶的mariadb
rpm -e --nodeps mariadb-libs
建立一個mysql數據目錄
mkdir /opt/mysql/data
chown -R mysql:mysql /opt/mysql/
修改mysql配置文件
vi /etc/my.cnf
[client] socket=/opt/mysql/data/mysql.sock [mysqld] basedir=/opt/mysql datadir=/opt/mysql/data port=3306 pid-file=/opt/mysql/data/mysql.pid server_id=1 socket=/opt/mysql/data/mysql.sock log-error=/opt/mysql/data/mysql.err
安裝numactl
yum -y install numactl
優化一下mysql二進制文件執行路徑
ln -s /opt/mysql/bin/* /usr/local/bin
初始化
mysqld --initialize --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data
取密碼
cat /opt/mysql/data/mysql.err | grep localhost | awk -F"localhost: " {'print $2'}
cp /opt/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
systemctl daemon-reload
systemctl start mysqld
修改密碼
mysqladmin -uroot -p password '123456'
在彈出的輸入框輸出剛剛用cat等命令截取的密碼
第四部分:安裝zabbix-server以及在本地安裝zabbix-agent
[上傳zabbix-4.0.19.tar.gz到/opt下]
一、安裝所需包
yum -y install net-snmp-devel libevent-devel
##官方文檔給出的安裝zabbix-server的configure命令是這樣的
./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
本文檔參照官方文檔按照 ./configure --enable-server --enable-agent --with-net-snmp --with-mysql=/opt/mysql/bin/mysql_config --with-libcurl --with-libxml2 的配置來安裝
這樣咱們在安裝以前還要安裝以上依賴包
二、編譯安裝zabbix
cd /opt
tar zxf zabbix-4.0.19.tar.gz
cd zabbix-4.0.19/
./configure --enable-server --enable-agent --with-mysql=/opt/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2
make install
##若是須要其餘的其餘功能,能夠參照./configure --help並結合官方文檔安裝https://www.zabbix.com/documentation/4.0/zh/manual/installation/install
三、初始化zabbix數據庫
建立zabbix數據庫,並受權
mysql -uroot -p
mysql> create database zabbix character set utf8; Query OK, 1 row affected (0.01 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix'; Query OK, 0 rows affected, 1 warning (0.00 sec)
使用zabbix數據庫用戶導入zabbix初始化數據
cd /opt/zabbix-4.0.19/database/mysql/
mysql -uzabbix -pzabbix -hlocalhost zabbix < schema.sql
mysql -uzabbix -pzabbix -hlocalhost zabbix < images.sql
mysql -uzabbix -pzabbix -hlocalhost zabbix < data.sql
四、編輯配置文件
建立一個目錄用戶保存zabbix日誌和pid
mkdir -p /opt/zabbix/logs
chown -R zabbix:zabbix /opt/zabbix
vi /usr/local/etc/zabbix_server.conf
LogFile=/opt/zabbix/logs/zabbix_server.log PidFile=/opt/zabbix/logs/zabbix_server.pid DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=123456 DBSocket=/opt/mysql/data/mysql.sock DBPort=3306 Timeout=4 LogSlowQueries=3000
##以上配置是過濾掉空行和#開頭行的配置,可根據上面配置找到對應的逐條更改
五、編輯/etc/ld.so.conf
vi /etc/ld.so.conf
include ld.so.conf.d/*.conf /opt/mysql/lib /usr/local/lib
ldconfig
##此文件記錄了編譯時使用的動態庫的路徑,也就是加載so庫的路徑。默認狀況下,編譯器只會使用/lib和/usr/lib這兩個目錄下的庫文件。
對於此種狀況有2種解決辦法:
(1)在用源碼安裝時,用--prefix指定安裝路徑爲/usr/lib。
(2) 直接將源碼安裝的軟件的lib路徑加入到文件/etc/ld.so.conf文件的中,也就是上面的操做
四、啓動zabbix-server
zabbix_server
netstat -anpt | grep 10051
ps -elf | grep zabbix
##經過以上兩個命令能夠看到是否成功啓動,若是沒有成功能夠查詢zabbix_server.log
cat /opt/zabbix/logs/zabbix_server.log
五、安裝zabbix-ui(圖形)管理界面
cp -rf /opt/zabbix-4.0.19/frontends/php/* /opt/nginx/html
六、訪問zabbix-ui界面
http://121.204.**.**:8008/
##安全須要我ip就不給你們看了