• shell脚本实现---Zabbix5.0快速部署


    shell脚本实现---Zabbix5.0快速部署

    zabbix-server快速安装脚本

    #!/bin/bash
    #Zabbix-Server  5.0
    #author:sunli
    #mail:sunli456@139.com
     
    #安装zabbix源、修改为aliyun源
    cd /etc/yum.repos.d/
    rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
    sed -i.bak 's#repo.zabbix.com#mirrors.aliyun.com/zabbix#' zabbix.repo
    sed -i 's#enabled=0#enabled=1#' zabbix.repo
     
    #安装zabbix
    yum -y install zabbix-server-mysql zabbix-agent
    yum -y install centos-release-scl
    yum -y install zabbix-web-mysql-scl zabbix-apache-conf-scl
     
    #安装启动 mariadb数据库
    yum -y install mariadb mariadb-server httpd
    systemctl start mariadb.service
     
    #创建数据库
    mysql -e 'create database zabbix character set utf8 collate utf8_bin;'
    mysql -e 'grant all privileges on zabbix.* to zabbix@localhost identified by "zabbix";'
    mysql -e 'flush privileges;'
     
    #导入数据
    zcat /usr/share/doc/zabbix-server-mysql-5.0.3/create.sql.gz|mysql -uzabbix -pzabbix -Dzabbix
     
    #配置zabbixserver连接mysql
    sed -i.bak '/^# DBPassword=*/i DBPassword=zabbix' /etc/zabbix/zabbix_server.conf
     
    #添加时区
    sed -i.bak '/^; php_value[date.timezone]*/i php_value[date.timezone] = Asia/Shanghai' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
     
    #解决中文乱码
    yum -y install wqy-microhei-fonts
    cp /usr/share/fonts/wqy-microhei/wqy-microhei.ttc /usr/share/fonts/dejavu/DejaVuSans.ttf
     
    #启动服务
    systemctl restart zabbix-server zabbix-agent httpd rh-php72-php-fpm
     
    #开机自启动
    systemctl enable mariadb.service
    systemctl enable httpd
    systemctl enable zabbix-server
     
    #输出信息
    echo "浏览器访问 http://`hostname -I|awk '{print $1}'`/zabbix"

    zabbix-agent快速部署脚本

    #!/bin/bash
    #Zabbix-Agent  5.0
     
    Zabbix_Service=192.168.10.10#注意此处为你的zabbix service或者zabbix proxy的IP
     
    #安装zabbix源、aliyun YUM源
    cd /etc/yum.repos.d/
    rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
    sed -i.bak 's#repo.zabbix.com#mirrors.aliyun.com/zabbix#' zabbix.repo
    sed -i 's#enabled=0#enabled=1#' zabbix.repo
     
    #安装zabbix
    yum -y install zabbix-agent
     
    #修改配置文件
    sed -i.bak "s/^Server=127.0.0.1/Server=$Zabbix_Service/" /etc/zabbix/zabbix_agentd.conf
    sed -i "s/^ServerActive=127.0.0.1/ServerActive=$Zabbix_Service/" /etc/zabbix/zabbix_agentd.conf
    sed -i "/^Hostname=/c Hostname=$(echo `hostname`)" /etc/zabbix/zabbix_agentd.conf
     
    #开启zabbix-agent服务 10050 端口
    systemctl start zabbix-agent
     
    #设置开机自启
    systemctl enable zabbix-agent
     
    #输出提示
    echo -e "Now you can use 33[32mnetstat -tnlp33[0m check 33[33mport:1005033[0m"

    zabbix-proxy快速安装脚本

    #!/bin/bash
    #Zabbix-Proxy  5.0
     
    Zabbix_Service=192.168.10.10
     
    #安装zabbix源、aliyun YUM源
    cd /etc/yum.repos.d/
    rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
    sed -i.bak 's#repo.zabbix.com#mirrors.aliyun.com/zabbix#' zabbix.repo
    sed -i 's#enabled=0#enabled=1#' zabbix.repo
     
    #安装zabbix-proxy-mysql zabbix-get zabbix-agent zabbix-sender
    yum -y install zabbix-proxy-mysql zabbix-get zabbix-agent zabbix-sender
     
    #安装启动 mariadb数据库
    yum -y install mariadb mariadb-server
    systemctl start mariadb.service
     
    #初始化数据库
    #mysql_secure_installation #设置密码,删除匿名用户,禁止root远程登录,删除test库
     
    #创建数据库
    mysql -e 'create database zabbix_proxy character set utf8 collate utf8_bin;'
    mysql -e 'grant all privileges on zabbix_proxy.* to zabbix_proxy@localhost identified by "zabbix_proxy";'
    mysql -e 'flush privileges;'
     
    #导入数据
    zcat /usr/share/doc/zabbix-proxy-mysql-5.0.3/schema.sql.gz |mysql -uzabbix_proxy -pzabbix_proxy -D zabbix_proxy
     
    #修改配置文件
    cat >>/etc/my.cnf.d/server.cnf<<EOF
    [mysqld]
    skip_name_resolve = ON #跳过主机名解析
    innodb_file_per_table = ON #
    innodb_buffer_pool_size = 256M #缓存池大小
    max_connections = 1000 #最大连接数
    log-bin = logbin #开启二进制日志
    EOF
     
    #重启服务
    systemctl restart mariadb.service
     
    #配置zabbix-proxy
    sed  -i.bak "/^Server=/c Server=$Zabbix_Service" /etc/zabbix/zabbix_proxy.conf
    sed -i "/^Hostname=/c Hostname=$(echo `hostname`)" /etc/zabbix/zabbix_proxy.conf
    sed -i '/^DBName=/c DBName=zabbix_proxy' /etc/zabbix/zabbix_proxy.conf
    sed -i '/^DBUser=/c DBUser=zabbix_proxy' /etc/zabbix/zabbix_proxy.conf
    sed -i '/^# DBPassword=/i DBPassword=zabbix_proxy' /etc/zabbix/zabbix_proxy.conf
    sed -i '/^# ConfigFrequency=/i ConfigFrequency=60' /etc/zabbix/zabbix_proxy.conf
    echo "EnableRemoteCommands=1" >> /etc/zabbix/zabbix_proxy.conf
    echo "LogRemoteCommands=1" >> /etc/zabbix/zabbix_proxy.conf
     
    #启动服务并开机自启
    systemctl start zabbix-proxy
    systemctl enable zabbix-proxy
     
    #安装netsats等网络工具
    yum -y install net-tools
     
    #输出信息
    echo -e "Now you can use 33[32mnetstat -tnlp33[0m check 33[33mport:1005133[0m"
  • 相关阅读:
    20145310《信息安全系统设计基础》第二周学习总结
    20145310《信息安全系统设计基础》第一周学习总结
    20145310 第0周《信息安全系统设计基础》学习总结
    课程总结
    20145310《Java程序设计》第5次实验报告
    20145310 《Java程序设计》第10周学习总结
    20145310 《Java程序设计》第9周学习总结
    20145310《Java程序设计》第4次实验报告
    20145310《Java程序设计》第3次实验报告
    git的安装以及遇到的问题
  • 原文地址:https://www.cnblogs.com/user-sunli/p/13957600.html
Copyright © 2020-2023  润新知