centos下的zabbix(全部编译)安装搭建

前端之家收集整理的这篇文章主要介绍了centos下的zabbix(全部编译)安装搭建前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Zabbix-3.0.4安装教程

一.安装环境

系统: CentOS release 6.8 (Final)

数据库:MysqL-5.7.15

Web:Nginx-1.6.3

PHP: PHP 7.0.11

MysqL-5.7.15编译安装

1.下载解压安装包到指定目录

Wget

http://ftp.ntu.edu.tw/pub/MysqL/Downloads/MysqL-5.7/MysqL-5.7.15.tar.gz

tar -zvxf MysqL-5.7.15.tar.gz -C /usr/local/src(应自己需求调整解压目录)

2.安装支撑包

yum -y installcmake readline-devel ncurses-devel ncurses vimlibxml2-devel libxml2 bzip2-devellibcurl-devel libjpeg-devel libpng-devel freetype-devel libXpm-devel

3.创建MysqL用户

/usr/sbin/groupadd MysqL

/usr/sbin/useradd -g MysqL MysqL

4.编译安装

cd /usr/local/src/MysqL-5.7.15

Cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/MysqL DMysqL_DATADIR=/usr/local/MysqL/data -DWITH_STORAGE_ENGINE=1 -DMysqL_UBIX_ADDR=/usr/local/MysqL/MysqL.sock -DMysqL_USER=MysqL -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost

make && make install

5.配置启动脚本

cp support-files/MysqL.server /etc/init.d/MysqLd

如果已经安装MysqL,将原MysqL的/etc/my.cnf移除

配置MysqL配置文件

vi /etc/my.cnf

[client]

password = "redhat"

user = "root"

port = 3306

socket = /usr/local/MysqL/MysqL.sock

default-character-set = utf8mb4

[MysqLd]

port = 3306

socket = /usr/local/MysqL/MysqL.sock

basedir = /usr/local/MysqL

datadir = /usr/local/MysqL/data

pid-file = /usr/local/MysqL/data/MysqL.pid

user = MysqL

bind-address = 0.0.0.0

server-id = 1

init-connect = 'SET NAMES utf8mb4'

character-set-server = utf8mb4

#skip-name-resolve

#skip-networking

back_log = 300

max_connections = 1000

max_connect_errors = 6000

open_files_limit = 65535

table_open_cache = 128

max_allowed_packet = 4M

binlog_cache_size = 1M

max_heap_table_size = 8M

tmp_table_size = 16M

read_buffer_size = 2M

read_rnd_buffer_size = 8M

sort_buffer_size = 8M

join_buffer_size = 8M

key_buffer_size = 4M

thread_cache_size = 8

query_cache_type = 1

query_cache_size = 8M

query_cache_limit = 2M

ft_min_word_len = 4

log_bin = MysqL-bin

binlog_format = mixed

expire_logs_days = 30

log_error = /usr/local/MysqL/data/MysqL-error.log

slow_query_log = 1

long_query_time = 1

slow_query_log_file = /usr/local/MysqL/data/MysqL-slow.log

performance_schema = 0

explicit_defaults_for_timestamp

#lower_case_table_names = 1

skip-external-locking

default_storage_engine = InnoDB

#default-storage-engine = MyISAM

innodb_file_per_table = 1

innodb_open_files = 500

innodb_buffer_pool_size = 64M

innodb_write_io_threads = 4

innodb_read_io_threads = 4

innodb_thread_concurrency = 0

innodb_purge_threads = 1

innodb_flush_log_at_trx_commit = 2

innodb_log_buffer_size = 2M

innodb_log_file_size = 32M

innodb_log_files_in_group = 3

innodb_max_dirty_pages_pct = 90

innodb_lock_wait_timeout = 120

bulk_insert_buffer_size = 8M

myisam_sort_buffer_size = 8M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

interactive_timeout = 28800

wait_timeout = 28800

[MysqLdump]

quick

max_allowed_packet = 16M

[myisamchk]

key_buffer_size = 8M

sort_buffer_size = 8M

read_buffer = 4M

write_buffer = 4M

6.配置MysqL的环境变量

在/etc/profile文件尾部加入以下内容

vi /etc/profile

#MysqL path

PATH=/usr/local/MysqL/bin:$PATH

export PATH

加入之后让环境变量生效

source /etc/profile

7.初始化数据库

cd /usr/local/MysqL

./bin/MysqLd --initialize --user=MysqL --datadir=/usr/local/MysqL/data/

A temporary password is generated for root@localhost:AB7YGWlAa6/r

记好这个密码,后面会用到

8.启动数据库

service MysqLd start

chkconfig MysqL on (设置开机自启动)

9.登录数据库更改root密码

MysqLd -uroot -pAB7YGWlAa6/r

MysqL> alter user ‘root’@’localhost’identified by ‘redhat’;

MysqL>create database zabbix default character set utf8;

MysqL>grant all privileges on zabbix.* to 'zabbix'@'localhost'identified by 'zabbix';

MysqL>flush privileges;

MysqL>exit;

Nginx-1.6.3编译安装

可以选择更高版本的,安装流程基本一致,我因为之前下载过,所以没用最新版的Nginx

1.下载解压缩Nginx安装包并安装相关依赖包

wget http://Nginx.org/download/Nginx-1.6.3.tar.gz

yum install pcre pcre-devel openssl-devel geoip geoip-devel -y

2.创建Nginx用户

/usr/sbin/groupadd Nginx

/usr/sbin/useradd -g Nginx Nginx

3.编译安装Nginx

tar -zvxf Nginx-1.6.3.tar.gz -C /usr/local/src/

cd /usr/local/src/Nginx-1.6.3/

./configure --user=Nginx --group=Nginx --with-http_stub_status_module --with-http_ssl_module

make && make install

--with-http_stub_status_module 启用status网页(模块能够获取Nginx自上次启动以来的工作状态)

--with-http_ssl_module 支持ssl模块

make && make install

4.更改Nginx所属目录权限

chown Nginx:Nginx -R /usr/local/Nginx

5.修改配置文件支持PHP

[root@ceshi2 src]# more /usr/local/Nginx/conf/Nginx.conf

user Nginx;

worker_processes 2;

error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

#pid logs/Nginx.pid;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

client_max_body_size 10m;

#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 ;

sendfile on;

tcp_nopush on;

#keepalive_timeout 0;

keepalive_timeout 65;

#gzip on;

server {

listen 80;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

### zabbix zhan dian

location / {

root html;

index index.html index.htm index.PHP;

}

# location / {

# root /data/www/;

# index index.PHP index.html index.htm;

# }

location ~ \.PHP$ {

root html;

fastcgi_pass unix:/var/run/PHP-fpm.sock;

fastcgi_index index.PHP;

fastcgi_param SCRIPT_FILENAME

$document_root$fastcgi_script_name;

fastcgi_param SCRIPT_FILENAME /usr/local/Nginx/html/$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;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.PHP$ {

# proxy_pass http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

# deny access to .htaccess files,if Apache's document root

# concurs with Nginx's one

#

#location ~ /\.ht {

# deny all;

#}

}

# another virtual host using mix of IP-,name-,and port-based configuration

#

#server {

# listen 8000;

# listen somename:8080;

# server_name somename alias another.alias;

# location / {

# root html;

# index index.html index.htm;

# }

#}

# HTTPS server

#

#server {

# listen 443 ssl;

# server_name localhost;

# ssl_certificate cert.pem;

# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;

# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;

# ssl_prefer_server_ciphers on;

# location / {

# root html;

# index index.html index.htm;

# }

#}

}

6.启动Nginx

/usr/local/Nginx/sbin/Nginx

7.设置开机自启动

在/etc/rc.local中添加

/usr/local/Nginx/sbin/Nginx

PHP-7.0.11编译安装

1.下载解压缩PHP安装包

wget http://php.net/downloads.php/php-7.0.11.tar.gz

tar -zxvf PHP-7.0.11.tar.gz -C /usr/local/src

2.编译安装

cd /usr/local/src/PHP-7.0.11/

./configure --prefix=/usr/local/PHPwith-configfilepathPHP-7.0.11etc MysqLiMysqLbinMysqL_config enablesysvsem sysvshm pcntl mbregex zip pcreregex libxmldir gd jpegpngfreetypeiconvzlibsockets soap gdnativettf ftp mbstring exif disableipv6 debug fpm openssl bz2 curl bcmath gettext xpmdir

make && make install

3.准备PHP配置文件

cp /usr/local/src/PHP-7.0.11/PHP.ini-production /usr/local/PHP/etc/PHP.ini

cp /usr/local/PHPetc/PHP-fpm.conf.default PHP-fpm.conf

4.修改配置文件

更改/usr/local/PHP/etc/PHP.ini 文件内容

在该文件中找到以下内容并更改

;date.timezone =改为 date.timezone=Asia/Shanghai

post_size = 8M改为 post_max_size = 32M

max_input_time = 60改为 max_input_time = 300

Max_execution_time = 30 改为 max_execution_time=300

在/usr/local/PHP/etc/PHP-fpm.conf尾部加入以下内容

[www]

user = Nginx

group = Nginx

listen = /var/run/PHP-fpm.sock

pm = dynamic

listen.owner = Nginx

listen.group = Nginx

listen.mode = 0660

pm.max_children = 5

pm.start_servers = 2

pm.min_space_servers = 1

pm.max_space_servers = 3

5.启动PHP-fpm组件

/usr/local/PHP/sbin/PHP-fpm -c /usr/local/PHP-7.0.11/etc/PHP.ini -y /usr/local/PHP/etc/PHP-fpm.conf

6.设置开机自启动

vi /etc/rc.local

添加如下内容

/usr/local/PHP/sbin/PHP-fpm -c /usr/local/PHP/etc/PHP.ini -y /usr/local/PHP/etc/PHP-fpm.conf

测试lnmp环境的连通性

看前面的文档我设置的Nginx反代的目录是/usr/local/Nginx/html,所以我的测试文件都放在了这个目录

cd /usr/local/Nginx/html

vi wdostest.PHP(名字随便,后面要加.PHP)

<?PHP

PHPinfo();

?>

使用网页访问自己服务器的ip/wdotest.PHP出现以下界面表示,NginxPHP连接无问题。出现问题,请自己查看是否按文档步骤执行

此处注意检查观察PHP模块是否都安装成功

接下来测试PHPMysqL的联通性

还是在前面的目录下

vi testMysqL.PHP

<?PHP

$link = MysqLi_connect(‘localhost’,’root’,’redhat’);

If (!$link) {

die (‘Could not connect:’. MysqL_error());

}

echo ‘Connected successfully’;

?>

使用网页访问自己服务器的ip/testMysqL.PHP出现以下界面表示成功,否则表示MysqLPHP连通失败

如果以上都成功了,证明你已经完成了百分之80。

Zabbix-3.0.4编译安装

1.下载解压zabbix安装包

wget http://www.zabbix.com/download.php/zabbix-3.0.4.tar.gz

链接可能有点问题,实在不行,大家自己去官网下载吧

2.安装依赖组件及编译安装

yum y install mbedtlsdevel gnutlsdevel fping sqlite-devel net-snmp-devel libssh2-devel OpenIPMI-devel

./configure zabbix iconv libcurl openipmi ssh2 netsnmp libxml2 with-MysqLagent server

make && make install

注: --with-mbedtls --with-gnutls 这两个编译检查无法通过是因为mbedtls和gnutls这两个组件没有安装找不到编译所需要的组件.我已经yum安装了mbedtls这个组件,编译依然无法通过.这两个是ssl用到的,可以不加到编译过程中

3.配置zabbix监控

/usr/sbin/groupadd zabbix

/usr/sbin/useradd -g zabbixzabbix

chmod -R 775 /usr/local/zabbix

chown -R zabbix:zabbix /usr/local/zabbix

4.准备启动脚本

cp -a /usr/local/src/zabbix-3.0.4/misc/init.d/fedora/core/* /etc/init.d

chmod +x /etc/init.d/zabbix_agentd

chmod +x /etc/init.d/zabbix_server

复制zabbix的web程序,前面Nginx已经配置了zabbix站点,所以只要拷贝到该路径就可以了.

cp -R /usr/local/src/zabbix-3.0.4/frontends/PHP/*/usr/local/Nginx/html/zabbix/

5.修改配置文件

在 /usr/local/zabbix/etc/zabbix_server.conf中增加更改以下内容:

LogFiletmpzabbix_server.log

DBHost=localhost

DBNamezabbix

DBUser=root

DBPassword=redhat

DBSocket=/usr/local/MysqL/MysqL.sock

DBPort=3306

Timeout5

AlertScriptsPathzabbixalertscripts

ExternalScriptsexternalscripts

LogSlowQueries3000

在/usr/local/zabbix/etc/zabbix_agentd.conf中加入如下内容

zabbix_agentdEnableRemoteCommands1

LogRemoteCommandsServer127.00.1

ListenIP0.00.0

ServerActiveHostname=ceshi2#跟主机名一样

AllowRoot1

6.导入数据文件

MysqL> use zabbix;

MysqL> source/usr/local/src/zabbix-3.0.4/database/MysqL/schema.sql

MysqL> source/usr/local/src/zabbix-3.0.4/database/MysqL/images.sql

MysqL> source/usr/local/src/zabbix-3.0.4/database/MysqL/data.sql

MysqL> quit;

7.添加环境变量zabbix

vi /etc/profile

在尾部添加

#zabbix path

PATH=/usr/local/zabbix/sbin:/usr/local/zabbix/bin:$PATH

export PATH

8.设置开机自启动

vi /etc/profile

加入以下内容

service zabbix_server start

service zabbix_agentd start

9.启动zabbix服务

service zabbix_server start

server zabbix_agentd start

访问服务器ip/zabbix就可以到安装界面进行安装了,按顺序走就可以了,这里我就不写步骤了

编译安装zabbix客户端

1.新建Zabbix运行账户

useradd -M -s/sbin/nologin zabbix

2.在被监控服务器上编译安装zabbix-agent

cd /usr/local/src/

tar -xvzf zabbix-3.0.4.tar.gz

cd zabbix-3.0.4

./configure --prefix=/usr/local/zabbix/ --enable-agent

make && make install

3.编辑zabbix-agent配置文件

vi /usr/local/zabbix-agent/etc/zabbix_agentd.conf

Server=192.168.1.182

ServerActive=192.168.1.182

Hostname=ceshi2(这里注意写的是zabbix server服务器的主机名,不是本机的)

User=zabbix

4.添加zabbix环境变量

vim /etc/profile.d/zabbix.sh

export PATH=/usr/local/zabbix/sbin:/usr/local/zabbix/bin:$PATH

source /etc/profile.d/zabbix.sh

5.拷贝zabbix_agent启动脚本

cp /usr/local/src/zabbix-3.0.4/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd

6.启动zabbix_agent客户端

/usr/local/zabbix-agent/sbin/zabbix_agentd

猜你在找的CentOS相关文章