Centos7 Zabbix4.0.3源码安装
作者:互联网
一、nginx编译安装
1、下载安装包编译安装
yum install -y wget gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel
cd /usr/local/src
yum install lrzsz -y
wget 'http://nginx.org/download/nginx-1.14.2.tar.gz'
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure --prefix=/usr/local/nginx
make && make install
2、检查配置文件、启动、重新加载、停止nginx命令
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -s reload
/usr/local/nginx/sbin/nginx -s stop
3、使用systemctl管理Nginx,vim /usr/lib/systemd/system/nginx.service
systemctl详情可以参考http://www.siguoya.name/pc/home/article/46
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
[Install]
WantedBy=multi-user.target
systemctl启动、重新加载、停止、开机自启nginx命令
systemctl start nginx
systemctl restart nginx
systemctl stop nginx
systemctl enable nginx.service
二、PHP编译安装
1、下载安装包编译安装
yum -y install epel-release
yum -y install gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openldap openldap-devel libmcrypt libmcrypt-devel
cd /usr/local/src/
wget 'http://hk1.php.net/distributions/php-5.6.40.tar.gz'
tar -zxf php-5.6.40.tar.gz
cd php-5.6.40
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-ctype --with-mysql=mysqlnd --with-mysqli=mysqlnd --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 --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-fpm
make && make install
cp php.ini-production /usr/local/php/etc/php.ini
php编译安装说明
--prefix 指定php的安装目录
--with-config-file-path 指定php的配置文件位置
--with-mysql、--with-mysqli 让php可以操作mysql
--enable-fpm 主要是nginx要来调用php语言得使用php-fpm
2、使用默认配置文件
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
3、添加环境变量
echo "export PATH=$PATH:/usr/local/php/sbin/:/usr/local/php/bin/" >> /etc/profile
source /etc/profile
4、检查配置文件、启动php命令:
/usr/local/php/sbin/php-fpm -t
/usr/local/php/sbin/php-fpm
5、使用systemctl管理php-fpm,vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
ExecStop=/bin/pkill -9 php-fpm
[Install]
WantedBy=multi-user.target
systemctl启动、重新加载、停止、开机自启php命令
systemctl start php-fpm.service
systemctl restart php-fpm.service
systemctl stop php-fpm.service
systemctl enable php-fpm.service
6、nginx的默认配置无法处理php程序/usr/local/nginx/html/test.php
<?php
echo "zabbix";
?>
nginx+php-fpm结合的配置
location / {
root html;
index index.html index.htm index.php;
}
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;
}
三、mysql编译安装
1、在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索"$basedir/my.cnf",若在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。
mv /etc/my.cnf /etc/my.cnf.bak
2、新增mysql用户
useradd -s /sbin/nologin mysql
3、下载安装包编译安装
yum install -y gcc gcc-c++ make tar openssl openssl-devel cmake ncurses ncurses-devel
cd /usr/local/src
wget 'https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.39.tar.gz'
tar -zxvf mysql-5.6.39.tar.gz
cd mysql-5.6.39
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=all -DWITH_DEBUG=0 -DENABLED_LOCAL_INFILE=1
make && make install
cp support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
编译选项说明
CMACK_INSTALL_PREFIX 指定安装的目录
MYSQL_DATADIR 指定Mysql的数据目录
4、mysql环境变量配置
echo "export PATH=$PATH:/usr/local/mysql/bin/" >>/etc/profile
source /etc/profile
5、创建 mysql数据库数据文件目录,数据目录在/data/mysql下
mkdir -pv /data/mysql
mkdir -p /data/mysql/{var,tmp,log}
chown -R mysql:mysql /usr/local/mysql /data/mysql/
6、更新mysql配置vim /etc/my.cnf
[mysqld]
bind-address=0.0.0.0
port=3306
tmpdir=/data/mysql/tmp
pid_file = /data/mysql/var/mysql.pid
log-error = /data/mysql/log/mysql.err
basedir = /usr/local/mysql/
datadir=/data/mysql
user=mysql
skip-name-resolve
long_query_time=2
slow_query_log_file=/data/mysql/log/mysql-slow.log
expire_logs_days=2
innodb-file-per-table=1
innodb_flush_log_at_trx_commit = 2
log_warnings = 1
max_allowed_packet = 512M
connect_timeout = 60
net_read_timeout = 120
7、mysql数据库初始化
yum install -y perl-Module-Install
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --user=mysql --datadir=/data/mysql/
8、启动mysql
/etc/init.d/mysqld start
或 service mysqld start
9、设为开机自启
chkconfig mysqld on
10、使用systemctl管理mysqld,/usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysqld
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/mysqld start
[Install]
WantedBy=multi-user.target
11、systemctl启动、重新加载、停止、开机自启mysql命令
systemctl start mysqld.service
systemctl restart mysqld.service
systemctl stop mysqld.service
systemctl enable mysqld.service
12、访问mysql
默认127.0.0.1,用户名root,不需要密码
mysql -uroot -h 127.0.0.1
- mysql设置密码
mysqladmin -h 127.0.0.1 -u root password '123456'
- 使用密码登陆登陆
mysql -uroot -h 127.0.0.1 -p123456
四、LNMP环境验证
1、创建一个php文件
vim /usr/local/nginx/html/test_mysql.php
<?php
$link=mysql_connect("127.0.0.1","root","zabbixpwd");
if(!$link){
echo "mysql_connect fail";
}else{
echo "mysql_connect success";
}
?>
2、访问这个文件 http://10.0.0.104/test_mysql.php,可以访问成功。
五、Zabbix Server编译安装
zabbix的官网:https://www.zabbix.com/
1、下载安装包编译安装
yum install -y libevent-devel wget tar gcc gcc-c++ make net-snmp-devel libxml2-devel libcurl-devel
cd /usr/local/src/
wget 'https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz'
tar -zxvf zabbix-4.0.3.tar.gz
cd zabbix-4.0.3
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2
make && make install
选项说明
--prefix指定安装目录
--enable-server安装zabbix server
--enable-agent安装zabbix agent
--with-mysql用mysql来存储
2、添加zabbix用户
useradd -s /sbin/nologin zabbix
chown -R zabbix:zabbix /usr/local/zabbix
3、设置zabbix环境变量并查看版本
echo "export PATH=$PATH:/usr/local/zabbix/sbin/:/usr/local/zabbix/bin/" >> /etc/profile
source /etc/profile
zabbix_server --version
4、mysql数据库初始化,先创建数据库再授权
mysql -h 127.0.0.1 -uroot -p123456
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@'127.0.0.1' identified by '123456';
flush privileges;
set names utf8;
exit;
5、按顺序导入zabbix表
可以进入mysql然后选择zabbix库,在mysql里source导入
mysql -h 127.0.0.1 -uroot -p123456
use zabbix;
source /usr/local/src/zabbix-4.0.3/database/mysql/schema.sql;
source /usr/local/src/zabbix-4.0.3/database/mysql/images.sql;
source /usr/local/src/zabbix-4.0.3/database/mysql/data.sql;
也可以在外面用shell命令直接导入
mysql -uroot -p123456 zabbix < /usr/local/zabbix-4.0.2/database/mysql/schema.sql
mysql -uroot -p123456 zabbix < /usr/local/zabbix-4.0.2/database/mysql/images.sql
mysql -uroot -p123456 zabbix < /usr/local/zabbix-4.0.2/database/mysql/data.sql
6、zabbix server的配置,可以将原来的备份一下,然后重新创建一下,省得一个一个配置找
vim /usr/local/zabbix/etc/zabbix_server.conf
ListenPort=10051
LogFile=/usr/local/zabbix/zabbix_server.log
PidFile=/usr/local/zabbix/zabbix_server.pid
DBHost=127.0.0.1
DBName=zabbix
DBUser=zabbix
DBPassword=123456
DBPort=3306
Timeout=30
#告警脚本位置
AlertScriptsPath=/usr/local/zabbix/alertscripts
ExternalScripts=/usr/local/zabbix/externalscripts
LogSlowQueries=3000
再设置一下目录所属用户
chown -R zabbix:zabbix /usr/local/zabbix
7、Zabbix Web的安装
mkdir /usr/local/nginx/html/zabbix
cp -a /usr/local/src/zabbix-4.0.3/frontends/php/* /usr/local/nginx/html/zabbix/
8、修改nginx,将nginx启动用户改为root,防止有不能访问的资源,然后index中加上index.php,这个就可以直接访问到zabbix的主页而不用再加index.php
server {
listen 80;
server_name 10.191.80.199;
access_log /data/log/nginx/zabbix.access.log main;
index index.html index.php index.html;
root /data/app/nginx/html/;
location /zabbix/{
try_files $uri $uri/ /index.php?$args;
}
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;
}
}
9、zabbix web需要php做配置优化
vim /usr/local/php/etc/php.ini
post_max_size = 32M
max_execution_time = 350
max_input_time = 350
date.timezone = Asia/Shanghai
always_populate_raw_post_data = -1
然后重启php
systemctl restart php-fpm
启动zabbix_server
zabbix_server
10、访问首页,前面设置了index.php,所以可以直接访问
http://IP/zabbix
php配置已经改过,是正常的
数据库配置,根据前面设置的进行填写
最后可能会提示无法创建配置文件,需要下载后放到提示的文件夹下,并且设置权限,否则可能会提示无法访问配置。
chmod 644 /usr/local/nginx/html/zabbix/conf/zabbix.conf.php
11、然后可以进行登陆,默认用户名和密码:Admin zabbix
首页如下
在左上角的用户按钮点进入可以设置为中文,以及修改密码
设置为中文,在管理–用户里也可以设置密码,还可以创建新用户。
六、zabbix解决中文乱码
1、虽然在用户的设置里可以设置为中文,但默认的中文可能有乱码
例如在(监测–图形)里选选择cpu load,可以看到有一部分内容乱码了
2、默认的字体文件在zabbix web目录的fonts目录下,默认是DejaVuSans字体,这个字体在中文会有部分乱码
[root@localhost ~]# cd /usr/local/nginx/html/zabbix/fonts/
[root@localhost fonts]# ls
DejaVuSans.ttf
3、可以在window的C:\Windows\Fonts目录下找到微软雅黑字体,然后放到zabbix的fonts目录下改名为msyh.ttf,也可以网上下载一个,然后权限设为644,让zabbix能够读取这个字体文件
[root@localhost fonts]# chmod 644 msyh.ttf
[root@localhost fonts]# ls
DejaVuSans.ttf msyh.ttf
4、将配置文件里的DejaVuSans改为msyh,有两个地方要改。
vim /usr/local/nginx/html/zabbix/include/defines.inc.php
5、然后再刷新下页面,可以看到中文正常了
安装包和中文字体网盘地址
链接:https://pan.baidu.com/s/1D6YDRY3xGCc66hP28M79rg
提取码:7p3n
参考资料:https://blog.csdn.net/qq_41475058/article/details/106056778
标签:php,--,Centos7,zabbix,源码,usr,mysql,Zabbix4.0,local 来源: https://blog.csdn.net/ichen820/article/details/118027835