侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

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

2023-12-16 星期六 / 0 评论 / 0 点赞 / 126 阅读 / 31269 字

Zabbix-3.0.4安装教程 一.安装环境 系统: CentOS release 6.8 (Final) 数据库:Mysql-5.7.15 Web:nginx-1.6.3 php: php 7.0

 

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 install cmake readline-devel ncurses-devel ncurses vim libxml2-devel libxml2 bzip2-devel libcurl-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/php --with-config-file-path=/usr/local/php-7.0.11/etc --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-zip --with-pcre-regex --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir  --enable-sockets --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --disable-debug --enable-fpm --with-openssl  --with-bz2 --with-curl --enable-bcmath --with-gettext --with-xpm-dir

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出现以下界面表示,nginx与php连接无问题。出现问题,请自己查看是否按文档步骤执行

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

接下来测试php和mysql的联通性

还是在前面的目录下

vi testmysql.php

<?php

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

If (!$link) {

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

}

echo ‘Connected successfully’;

?>

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

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

 

 

                                                          Zabbix-3.0.4编译安装

1.下载解压zabbix安装包

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

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

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

yum y install mbedtls-devel gnutls-devel fping sqlite-devel net-snmp-devel libssh2-devel OpenIPMI-devel

./configure --prefix=/usr/local/zabbix --with-iconv --with-libcurl --with-openssl --with-openipmi --with-ssh2 --with-net-snmp --with-libxml2  --with-mysql --enable-ipv6 --enable-agent --enable-server

make && make install

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

3.配置zabbix监控

/usr/sbin/groupadd zabbix

/usr/sbin/useradd -g zabbix zabbix

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中增加更改以下内容:

LogFile=/tmp/zabbix_server.log

DBHost=localhost

DBName=zabbix

DBUser=root

DBPassword=redhat

DBSocket=/usr/local/mysql/mysql.sock

DBPort=3306

 

Timeout=5

AlertScriptsPath=/usr/local/zabbix/zabbix/alertscripts

ExternalScripts=/usr/local/zabbix/zabbix/externalscripts

LogSlowQueries=3000

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

LogFile=/tmp/zabbix_agentd.log

EnableRemoteCommands=1

LogRemoteCommands=1

Server=127.0.0.1

ListenIP=0.0.0.0

ServerActive=127.0.0.1

Hostname=ceshi2  #跟主机名一样

AllowRoot=1

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

 

 

 

广告 广告

评论区