源码编译LNMP+最新版zabbix4.0
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了源码编译LNMP+最新版zabbix4.0相关的知识,希望对你有一定的参考价值。
LNMP+Zabbix4.0
之前发过一篇LAMP中的zabbix,兴趣使然,研究一下LNMP中源码编译zabbix的搭建。话不多说,直接上环境及操作步骤。
系统 | IP | 软件列表 |
---|---|---|
centos7 | 192.168.70.136 | nginx1.8/mysql5.7/php7.3/zabbix4.0 |
zabbix4.0下载地址 https://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.4/zabbix-4.0.4.tar.gz
其他软件包可以在我博客上找:LNMP软件链接
一、nginx安装
1、安装基础环境
[[email protected] opt]# yum -y install gcc gcc-c++ autoconf gd-devel automake zlib zlib-devel openssl openssl-devel pcre*
2、解压编译
[[email protected] opt]# tar zxf nginx-1.8.1.tar.gz
[[email protected] opt]# cd nginx-1.8.1/
./configure
--prefix=/usr/local/nginx
--user=nginx
--group=nginx
--with-http_ssl_module
--with-http_gzip_static_module
--with-http_image_filter_module
--with-http_stub_status_module
3、安装
[[email protected] nginx-1.8.1]# make && make install
4、创建nginx用户,检查配置文件
[[email protected] nginx-1.8.1]# useradd -M -s /sbin/nologin nginx
[[email protected] nginx-1.8.1]# ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
[[email protected] nginx-1.8.1]# nginx -t #配置文件没问题,如下
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
二、mysql解压版安装
1、解压mysql并更名
[[email protected] opt]# tar zxf mysql-5.7.21-linux-glibc2.12-x86_64.tgz
[[email protected] opt]# mv mysql-5.7.21-linux-glibc2.12-x86_64 mysql
2、修改配置文件
[[email protected] opt]# vim /etc/my.cnf #删除原有的内容,添加如下
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
character-set-server = utf8mb4
skip_name_resolve = 1
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /opt/mysql/
datadir = /opt/mysql/data
log-error = /opt/mysql/data/log-error.log
pid-file = /opt/mysql/data/mysql.pid
innodb_data_home_dir = /opt/mysql/data
slow-query-log-file=/opt/mysql/data/slow.log
relay-log-index = /opt/mysql/data/relaylog
relay-log-info-file = /opt/mysql/data/relaylog
relay-log = /opt/mysql/data/relaylog
open_files_limit = 10240
table_open_cache = 2048
back_log = 300
max_connections = 10000
max_connect_errors = 20
explicit_defaults_for_timestamp = 1
max_allowed_packet = 64M
thread_cache_size = 300
query_cache_size = 256M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = InnoDB
thread_stack = 512K
transaction_isolation = READ-COMMITTED
tmp_table_size = 256M
max_heap_table_size = 256M
key_buffer_size = 2G
sort_buffer_size = 2M
join_buffer_size = 6M
read_buffer_size = 4M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 15G
myisam_repair_threads = 1
interactive_timeout = 1800
wait_timeout = 28800
innodb_data_file_path = ibdata1:120M;ibdata2:200M;ibdata3:200M:autoextend
innodb_buffer_pool_size = 2G
innodb_thread_concurrency = 0
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_purge_threads = 0
slow_query_log = 1
long_query_time = 3
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
#slave-skip-errors = 1032,1062,1026,1114,1146,1048,1396
server-id = 1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqldump]
quick
max_allowed_packet = 64M
3、创建mysql用户,并初始化
[[email protected] opt]# adduser -s /sbin/nologin mysql
[[email protected] opt]# ln -s /opt/mysql/bin/* /usr/bin/
[[email protected] opt]# mysqld --initalize-insecure --user=mysql
4、启动,设置数据库密码
[[email protected] mysql]# mysqld_safe &
[[email protected] opt]# mysqladmin -uroot password ‘123123‘
[[email protected] opt]# mysql -uroot -p #使用密码登陆
三、安装PHP7.3
1、安装基础环境
yum -y install pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel openldap-servers openldap-client nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel bzip2 bzip2-devel libxml2 libxml2-devel bzip2 bzip2-devel curl-devel ?gmp-devel readline-devel libxslt-devel
2、解压php压缩包
[[email protected] opt]# tar zxf php-7.3.1.tar.gz
3、解决编译及小问题
●configure:?error:?off_t undefined; check your library configuration
解决方法
echo ‘/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64‘>>/etc/ld.so.conf&&ldconfig -v
●configure: error: Please reinstall the libzip distribution
解决方法
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make
make install
●/usr/local/include/zip.h:59:21: 致命错误:zipconf.h:没有那个文件或目录
解决方法
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
4、编译
[[email protected] opt]# cd php-7.3.1/
./configure
--prefix=/usr/local/php7
--with-pdo-mysql=/opt/mysql
--enable-mysqlnd
--with-pdo-mysql=mysqlnd
-with-mysqli=mysqlnd
--with-mysql-sock=/tmp/mysql.sock
--with-config-file-path=/usr/local/php7
--enable-fpm
--enable-inline-optimization
--disable-debug
--disable-rpath
--enable-shared
--enable-soap
--with-libxml-dir
--with-xmlrpc
--with-openssl
--with-mhash
--with-pcre-regex
--with-sqlite3
--with-zlib
--enable-bcmath
--with-iconv
--with-bz2
--enable-calendar
--with-curl
--with-cdb
--enable-dom
--enable-exif
--enable-fileinfo
--enable-filter
--with-pcre-dir
--enable-ftp
--with-gd
--with-openssl-dir
--with-jpeg-dir
--with-png-dir
--with-zlib-dir
--with-freetype-dir
--enable-gd-jis-conv
--with-gettext
--with-gmp
--with-mhash
--enable-json
--enable-mbstring
--enable-mbregex
--enable-mbregex-backtrack
--with-onig
--enable-pdo
--with-zlib-dir
--with-pdo-sqlite
--with-readline
--enable-session
--enable-shmop
--enable-simplexml
--enable-sockets
--enable-sysvmsg
--enable-sysvsem
--enable-sysvshm
--enable-wddx
--with-libxml-dir
--with-xsl
--enable-zip
--with-pear
--enable-opcache
5、安装
[[email protected] php-7.3.1]# make && make install
6、复制配置文件,创建命令软链接
[[email protected] php-7.3.1]# cp php.ini-development /usr/local/php7/php.ini
[[email protected] php-7.3.1]# ln -s /usr/local/php7/bin/ /usr/local/bin/
[[email protected] php-7.3.1]# ln -s /usr/local/php7/sbin/ /usr/local/sbin/
7、创建php用户
[[email protected] php-7.3.1]# useradd -M -s /sbin/nologin php
8、修改配置文件格式及配置文件
[[email protected] php-7.3.1]# cd /usr/local/php7/etc/php-fpm.d
[[email protected] php-fpm.d]# cp www.conf.default www.conf
[[email protected] php-fpm.d]# vim www.conf
#修改以下内容
user = php
group = php
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
#该文件也需要改格式
[[email protected] php-fpm.d]# cd /usr/local/php7/etc/
[[email protected] etc]# cp php-fpm.conf.default php-fpm.conf
9、启动php,查看进程
[[email protected] etc]# php-fpm
[[email protected] etc]# pgrep php
100537
100538
100539
..........
...........
10、修改nginx配置文件,nginx连接php
[[email protected] etc]# vim /usr/local/nginx/conf/nginx.conf
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#这里一定要改成绝对路径或者$document_root,否则会返回空白页面
include fastcgi_params;
}
11、修改首页,测试连接php
[[email protected] etc]# vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
12、启动nginx,网页访问测试
记得找mysqli和mysqlnd两个参数
四、安装zabbix4.0
1、安装基础环境
[[email protected] etc]# yum install net-snmp net-snmp-devel fping unixODBC-devel openssl-devel OpenIPMI-devel libevent libevent-devel pcre-devel -y
2、创建zabbix用户
[[email protected] etc]# useradd zabbix -s /sbin/nologin
3、解压,编译
[[email protected] etc]# cd /opt/
[[email protected] opt]# tar zxf zabbix-4.0.4.tar.gz
./configure
--prefix=/usr/local/zabbix
--enable-server
--enable-agent
--with-mysql
--enable-ipv6
--with-net-snmp
--with-libcurl
--with-libxml2
--with-openipmi
--with-unixodbc
--with-openssl
--with-gettext
4、安装
[[email protected] zabbix-4.0.4]# make && make install
5、改zabbix目录权限
[[email protected] zabbix-4.0.4]# cd /usr/local && chown -R zabbix:zabbix zabbix
6、创建zabbix数据库,倒sql语句
[[email protected] local]# mysql -uroot -p
#sql语句文件在解压过的zabbix目录当中
mysql> create database if not exists zabbix default character set utf8 collate utf8_general_ci;
mysql> use zabbix;
mysql> source /opt/zabbix-4.0.4/database/mysql/schema.sql
mysql> source /opt/zabbix-4.0.4/database/mysql/images.sql
mysql> source /opt/zabbix-4.0.4/database/mysql/data.sql
7、创建日志文件
[[email protected] local] cd /usr/local/zabbix
[[email protected] zabbix]# mkdir logs
[[email protected] zabbix]# chown zabbix:zabbix logs
8、修改zabbix_server.conf文件
[[email protected] zabbix]# cd /usr/local/zabbix/etc/
LogFile=/usr/local/zabbix/logs/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=123123
DBSocket=/tmp/mysql.sock
Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf
9、修改zabbix_agentd.conf
[[email protected] etc]# vim zabbix_agentd.conf
PidFile=/tmp/zabbix_agentd.pid
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
10、启动服务
[[email protected] etc]# /usr/local/zabbix/sbin/zabbix_server
[[email protected] etc]# /usr/local/zabbix/sbin/zabbix_agentd
如果报错:/usr/local/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
解决方法:
[[email protected] etc]# ln -s /opt/mysql/lib/libmysqlclient.so.20 /usr/lib/
[[email protected] etc]# ldconfig
如果启动后看不到zabbix10050的进程号,日志文件中会有提示,不能连接数据库
这时候去数据库给zabbix用授权即可
mysql> grant all privileges on zabbix.* to ‘zabbix‘@‘localhost‘ identified by ‘123123‘;
11、修改nginx配置文件,指定zabbix安装目录
[[email protected] logs]# cd /usr/local/nginx/conf/
[[email protected] conf]# vim nginx.conf
location / {
root /usr/local/nginx/html/data/zabbix;
index index.html index.htm;
}
location ~ .php$ {
root /usr/local/nginx/html/data/zabbix;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/data/zabbix$fastcgi_script_name;
include fastcgi_params;
}
[[email protected] conf]# cd /usr/local/nginx/html/
[[email protected] html]# mdkir data
[[email protected] html]# mv /opt/zabbix-4.0.4/frontends/php/ data/zabbix
[[email protected] html]# chmod 777 -R data/
12、重启nginx,网页安装
192.168.70.136/index.php
[[email protected] html]# nginx -s reload
这里fail,去修改php.ini配置文件,按照它提示的字段
[[email protected] html]# cd /usr/local/php7/
[[email protected] php7]# vim php.ini
post_max_size = 16M
max_execution_time = 300
date.timezone = Asia/Shanghai
然后重启php
[[email protected] php7]# killall php-fpm
[[email protected] php7]# php-fpm
到这里LNMP的zabbix安装就结束了,之前忙,没有去写zabbix监控的相关使用,下篇博客为大家介绍zabbix相关监控的使用~
以上是关于源码编译LNMP+最新版zabbix4.0的主要内容,如果未能解决你的问题,请参考以下文章