1. 安装MySQL
yum install -y yum-utils
rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm ---使用官方的mysql源
yum-config-manager --disable mysql80-community ---关闭mysql8.0的yum源
yum-config-manager --enable mysql57-community ---启用mysql5.7的yum源
yum install -y mysql-community-server
systemctl start mysqld
grep 'temporary password' /var/log/mysqld.log ---获取mysql的初始随机root密码,mysql5.7后新增的
mysql -uroot -p ---使用root进入数据库,输入密码
mysql > ALTER USER 'root'@'localhost' IDENTIFIED BY 'Zabbix2018!'; ---修改mysql中root用户的密码
mysql > flush privileges; ---刷新权限
mysql > quit
vi /etc/my.cnf ---把原来的都删掉,把下面两段复制过去
[mysql]
socket = /var/lib/mysql/mysql.sock
[mysqld]
user = mysql
port = 3306
datadir = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock
bind-address = 0.0.0.0
pid-file = /var/run/mysqld/mysqld.pid
character-set-server = utf8
collation-server = utf8_general_ci
log-error = /var/log/mysqld.log
调优配置
max_connections = 10240
open_files_limit = 65535
innodb_buffer_pool_size = 1G
innodb_flush_log_at_trx_commit = 2
innodb_log_file_size =256M
systemctl restart mysqld ---修改完配置重启mysql
2. 源码编译部署Zabbix服务器
- 部署Nginx
wget http://nginx.org/download/nginx-1.15.3.tar.gz
yum install gcc pcre-devel openssl-devel -y
useradd -M -s /sbin/nologin nginx
tar zxvf nginx-1.15.3.tar.gz -C /usr/local/src/
cd /usr/local/src/nginx-1.15.3
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-stream=dynamic
make && make install
chown nobody -R /usr/local/nginx/
vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
- 部署PHP
yum install -y gcc gcc-c++ make gd-devel libxm12-devel libcurl-devel libjpeg-devel libpng-devel openssl-devel libxslt-devel
wget http://docs.php.net/distributions/php-5.6.36.tar.gz
tar zxf php-5.6.36.tar.gz -C /usr/local/src/
cd /usr/local/src/php-5.6.36/
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc \
--enable-fpm --enable-opcache --with-mysql --with-mysqli \
--enable-session --with-zlib --with-curl --with-gd --with-jpeg-dir \
--with-png-dir --with-freetype-dir --enable-mbstring --enable-xmlwriter \
--enable-xmlreader --enable-xml --enable-sockets --enable-bcmath --with-gettext
make -j 4 && make install --- -j 4表示使用4个线程去进行操作,对于多线程机器来说,效率更高,这个根据实际情况使用
cp php.ini-production /usr/local/php/etc/php.ini
cp sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
vi /usr/lib/systemd/system/php-fpm.service ---修改以下内容
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/usr/local/php/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start php-fpm
systemctl enable php-fpm
- 部署Zabbix-Server
去https://www.zabbix.com/download_sources下载zabbix4.0源码包,放进服务器里
tar -zxf zabbix-4.0.1.tar.gz -C /usr/local/src/ ---版本号根据实际情况进行修改
导入表结构
mysql -uroot -p
mysql > create database zabbix_src;
mysql > grant all on zabbix_src.* to 'zabbix_src'@'%' identified by 'Zabbix2018!';
mysql > flush privileges;
mysql > quit
cd /usr/local/src/zabbix-4.0.1/database/mysql/
mysql -uzabbix_src -p'Zabbix2018!' zabbix_src < schema.sql ---schema、images、data这3个按顺序导入
mysql -uzabbix_src -p'Zabbix2018!' zabbix_src < images.sql
mysql -uzabbix_src -p'Zabbix2018!' zabbix_src < data.sql
yum install libxml2-devel libcurl-devel libevent-devel net-snmp-devel mysql-community-devel java-1.8.0-openjdk java-1.8.0-openjdk-devel -y
groupadd zabbix
useradd -g zabbix zabbix -s /sbin/nologin
cd /usr/local/src/zabbix-4.0.1
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --enable-java --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
注意:如果时间不同步可能会报错,可以用ntpdate -u ntp.api.bz进行同步
make install
vi /usr/local/zabbix/etc/zabbix_server.conf ---修改下面的项
DBHost=localhost ---可以直接写当前Zabbix服务器的IP
DBName=zabbix_src ---也可以直接用zabbix
DBUser=zabbix_src ---也可以直接用zabbix
DBPassword=Zabbix2018!
vi /usr/lib/systemd/system/zabbix_server.service
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
[Service]
Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_server.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/usr/local/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0
[Install]
WantedBy=multi-user.target
启动Agent
/usr/local/zabbix/sbin/zabbix_agentd
- 部署Zabbix Web界面
Zabbix前端使用PHP写的,所以必须运行在PHP支持的Web服务器上
cd /usr/local/src/
cp zabbix-4.0.1/frontends/php/* /usr/local/nginx/html -rf
vi /usr/local/nginx/conf/nginx.conf ---在原处进行修改
server {
listen 80;
server_name localhost;
access_log logs/zabbix.access.log main;
location / {
root html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
/usr/local/nginx/sbin/nginx -s reload
vi /usr/local/php/etc/php.ini ---修改以下项,如果是注释掉的要把注释去掉
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
always_populate_raw_post_data = -1
date.timezone = Asia/Shanghai
在浏览器上输入192.168.1.107进入Zabbix的管理web界面(这里后面不用加/zabbix,因为前面已经把根目录改成/zabbix了)