系统环境:
——CentOS Linux release 7.4.1708 (Core)
zabbix版本:
——zabbix-4.0.5
首先我们需要搭建的是lnmp平台:
——nginx
1、安装依赖包:
yum -y install pcre pcre-devel openssl openssl-devel gcc-c++ autoconf automake zlib-devel libxml2 libxml2-dev libxslt-devel gd-devel perl-devel perl-ExtUtils-Embed GeoIP GeoIP-devel GeoIP-data
2、创建nginx用户:
useradd -s /sbin/nologin nginx
3、解压nginx的tar包,并进入生产的目录进行编译安装:
tar zxvf nginx-1.12.2.tar.gz
./configure --prefix=/usr/local/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 --user=nginx --group=nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_image_filter_module
每个包对应的模块可以参考https://blog.csdn.net/sanchan/article/details/51213382
模块也可以按照自身需求进行更改,接下来是编译了
make&&make install
4、添加软连接:
ln -s /usr/local/nginx/sbin/nginx /sbin/
5、修改nginx配置文件让其支持php:
如果想要nginx支持PHP文件,则需要修改配置nginx.conf让其支持PHP文件(两处地方):
http{
fastcgi_buffers 8 16k; //缓存php生成的页面内容,8个16k
fastcgi_buffer_size 32k; //缓存php生产的头部信息
fastcgi_connect_timeout 300; //连接PHP的超时时间
fastcgi_send_timeout 300; //发送请求的超时时间
fastcgi_read_timeout 300;
..........
..............
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 /scripts$fastcgi_script_name;
include fastcgi.conf;
}
启动nginx:
nginx
——mysql:
1、解压MySQL包:
tar zxvf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
2、安装依赖包:
yum -y install perl-JSON
yum -y install libaio-devel numactl
3、mv生成的目录到想要的路径下,我这里是/usr/local/下,并创建mysql用户:
mv mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql
groupadd mysql
useradd -r -g mysql mysql
4、到mysql目录里创建存储目录(这里按自己喜欢即可,只要在最后编译时指定说明就好):
cd /usr/local/mysql
mkdir data
chown -R mysql.mysql /usr/local/mysql
5、复制启动脚本到/etc/init.d/下,并且修改安装目录路径,存储路径:
cp support-files/mysql.server /etc/init.d/mysqld
vim /etc/init.d/mysql
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data
6、修改my.cnf:
vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
user=mysql
symbolic-links=0
character-set-server=utf8
default_storage_engine = INNODB
log-bin=mysql-bin
server-id=10
[client]
socket=/usr/local/mysql/mysql.sock
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
7、给启动脚本对应权限,并配置环境变量:
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
echo export PATH=/usr/local/mysql/bin:$PATH >> /etc/profile
source /etc/profile
8、编译,此处会回显默认密码:
/usr/local/mysql/bin/mysqld --initialize
–user=mysql
–basedir=/usr/local/mysql/
–datadir=/usr/local/mysql/data/
–lc_messages_dir=/usr/local/mysql/share
–lc_messages=en_US
9、启动mysql:
service mysqld start
mysql -uroot -p"+B+_-:dkI41h"
PHP:
需要装好yum的epel-release,这上面有相对应的依赖包!!!
1、安装依赖包:
yum -y install gcc gcc-c++ php php-mysql bzip2-devel libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-deve php-mcrypt libmcrypt libmcrypt-devel freetype-devel
2、创建用户:
groupadd www
useradd -g www -s /sbin/nologin -M www
3、解压并进入生成目录移动到路径:
tar -zxvf php-5.6.37.tar.gz
mv php-5.6.37 /usr/local/php-5.6.37
4、进入生成目录编译安装:
cd /usr/local/php-5.6.37
./configure --prefix=/usr/local/php --with-pdo-mysql --with-mysqli=mysqlnd --with-mysql=mysqlnd --with-mysql-sock=/usr/local/mysql/mysql.sock --without-pdo-sqlite --with-gd --with-bz2 --enable-bcmath --enable-soap --with-openssl --enable-opcache --with-zlib --enable-zip --with-mhash --enable-exif --enable-mbstring --with-iconv --with-mcrypt --with-curl --with-freetype-dir --with-jpeg-dir --with-png-dir --enable-fpm --enable-pcntl --with-fpm-user=www --with-fpm-group=www --with-config-file-path=/usr/local/php/etc --with-gettext --enable-sockets
make&&make install
5、可能出生成下面这段话:
You may want to add: /usr/local/php/php/lib/php to your php.ini include_path
跟着这句话的提示,首先修改php.ini里面的include_path的值,路径上面有说,然后继续执行他下面的两个命令
6、复制相关配置文件、脚本到合适的路径下:
cp /usr/local/php-5.6.37/php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
ln -s /usr/local/php/sbin/php-fpm /usr/local/sbin/php-fpm
cp /usr/local/php-5.6.37/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
/etc/init.d/php-fpm start
ss -anput | grep php
zabbix:
1、安装依赖包:
yum -y install net-snmp net-snmp-devel fping unixODBC-devel openssl-devel OpenIPMI-devel libevent libevent-devel pcre-devel
2、创建用户,并限制不能登陆:
useradd zabbix -s /sbin/nologin
3、编译安装:
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
make && make install
4、修改目录所属组跟所属者:
chown -R zabbix.zabbix /usr/local/zabbix*
以上相关搭建已经搭建完成,接下来是给zabbix创建库并把数据导入进MySQL里,然后修改php相关参数:
1、登入MySQL创建数据库:
create database zabbix character set utf8;
2、创建可以访问的用户并给与相关权限:
grant all on zabbix.* to zabbix@’%’ identified by ‘zabbix’;
3、进入zabbix目录下的mysql目录里把里面的数据导入刚刚创建好的数据库:
cd /usr/local/zabbix-4.0.5/database/mysql/
mysql -uzabbix -pzabbix zabbix < schema.sql
mysql -uzabbix -pzabbix zabbix < images.sql
mysql -uzabbix -pzabbix zabbix < data.sql
格式:mysql -u用户名 -p密码 库名 < 文件
4、修改/etc/init.d/zabbix_server
cp /usr/local/zabbix-4.0.5/misc/init.d/tru64/zabbix_server /etc/rc.d/init.d/
vim /etc/init.d/zabbix_server
BASEDIR=/usr/local/zabbix-4.0.5 ###修改该处到编译目录
5、给mysql.sock软连接一下到/tmp/下,然后做一下启动项
find / -name ‘mysql.sock’
ln -s /usr/local/mysql/mysql.sock /tmp/
cp /usr/local/zabbix-4.0.5/misc/init.d/tru64/zabbix_server /etc/init.d/
chmod +x /etc/init.d/zabbix_server
ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
cp -rp /usr/local/zabbix-4.0.5/frontends/php/* /usr/local/nginx/html/
chown -R nginx.nginx /usr/local/nginx/html/*
nginx -s reload
启动zabbix_server
service zabbix_server start
如果该处出现如下错误:error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
解决方案:find / -name ‘libmysqlclient.so.20’
找到该文件的路径(如果没有那就是依赖包没有安装完整),做一个软连接到/usr/lib64/下面即可:ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64/
然后根据页面的提示修改php里面的配置文件
zabbix_agent:
安装依赖包:yum -y install gcc pcre-devel
1、解压包:
[root@mysqlslave ~]# tar zxvf zabbix-4.0.5.tar.gz
2、移动到/usr/local/下并且编译安装
mv zabbix-4.0.5 /usr/local/zabbix-4.0.5
./configure --prefix=/usr/local/zabbix --enable-agent
make&&make install
3、修改zabbix_agentd.conf:
vim /usr/local/zabbix/etc/zabbix_agentd.conf
Server= #服务端ip地址
ServerActive= #服务端ip地址(主动模式)
Hostname= #该值跟zabbix web上配置的主机名称要一致
UnsafeUserParameters=1 #是否允许自定义key监控
4、配置启动项:
useradd -s /sbin/nologin zabbix
cp /usr/local/zabbix-4.0.5/misc/init.d/tru64/zabbix_agentd /etc/init.d/
chmod +x /etc/init.d/zabbix_agentd
ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/
service zabbix_agentd start