当前位置:   article > 正文

Zabbix一键部署脚本+添加主机_zabbix批量添加主机

zabbix批量添加主机

1.脚本演示

  1. #!/bin/bash
  2. #function:zabbix
  3. #author:Mr.xie 20230824
  4. ##########################################
  5. if
  6. [ "$USER" != "root" ]
  7. then
  8. echo "错误:非root用户,权限不足!"
  9. exit 0
  10. fi
  11. ###############防火墙及SElinux############
  12. systemctl stop firewalld && systemctl disable firewalld && echo "防火墙已经关闭"
  13. sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config && echo "关闭selinux"
  14. ###############测试外网是否通常############
  15. ping -c 3 www.baidu.com
  16. if
  17. [ $? = 0 ]
  18. then
  19. echo "网络正常"
  20. else
  21. echo "网络异常"
  22. exit 1
  23. fi
  24. ############### 安装必要文件 ###############
  25. if rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7; then
  26. if yum install epel-release.noarch wget vim gcc gcc-c++ lsof chrony tree nmap unzip rsync -y; then
  27. if rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7; then
  28. echo "安装成功"
  29. else
  30. echo "导入CentOS 7的GPG密钥失败,退出脚本。"
  31. exit 1
  32. fi
  33. else
  34. echo "安装依赖包执行失败,退出脚本。"
  35. exit 1
  36. fi
  37. else
  38. echo "导入CentOS 7的GPG密钥失败,退出脚本。"
  39. exit 1
  40. fi
  41. ############### 搭建LAMP平台 ###############
  42. yum install -y httpd mariadb mariadb-server mariadb-client php php-mysql
  43. if [ $? -eq 0 ];then
  44. echo "LNMP平台安装成功"
  45. systemctl start mariadb.service
  46. mysqladmin -u root password 123456
  47. if [ $? -eq 0 ];then
  48. echo "MYSQL启动成功"
  49. else
  50. echo "MYSQL启动失败"
  51. exit 1
  52. fi
  53. else
  54. echo "LAMP安装失败"
  55. exit 1
  56. fi
  57. sleep 2
  58. ############### 安装zabbix服务 ###############
  59. if rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm; then
  60. if rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7; then
  61. if yum install -y zabbix-server-mysql zabbix-web-mysql zabbix-get zabbix-agent; then
  62. echo "安装成功"
  63. else
  64. echo "导入CentOS 7的GPG密钥失败,退出脚本。"
  65. exit 1
  66. fi
  67. else
  68. echo "安装zabbix失败,退出脚本。"
  69. exit 1
  70. fi
  71. else
  72. echo "安装zabbix失败,退出脚本。"
  73. exit 1
  74. fi
  75. ############### 创建zabbix库 ###############
  76. mysql -u root -p123456 -e "CREATE DATABASE zabbix DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;"
  77. if [ $? -eq 0 ];then
  78. echo "创建zabbix库成功"
  79. else
  80. echo "创建zabbix库失败"
  81. exit 1
  82. fi
  83. ############### 导入数据 ###############
  84. cd /usr/share/doc/zabbix-server-mysql-3.0.32/
  85. zcat create.sql.gz | mysql -u root -p123456 zabbix
  86. ############### 修改zabbix配置 ###############
  87. ipadd=$(ip a | grep "inet "|grep "ens33" | awk '{print $2}' | awk -F / '{print $1}')
  88. sed -i '81s/^# *//' /etc/zabbix/zabbix_server.conf
  89. sed -i '106s/DBUser=zabbix/DBUser=root/' /etc/zabbix/zabbix_server.conf
  90. sed -i '107iDBPassword=123456' /etc/zabbix/zabbix_server.conf
  91. sed -i '/<IfModule mod_php5.c>/a php_value date.timezone Asia/Shanghai' /etc/httpd/conf.d/zabbix.conf
  92. ############### 启动 ###############
  93. systemctl start httpd
  94. if [ $? -eq 0 ];then
  95. echo "http启动成功"
  96. systemctl start zabbix-server
  97. if [ $? -eq 0 ];then
  98. echo "zabbix-server启动成功"
  99. systemctl start zabbix-agent
  100. if [ $? -eq 0 ];then
  101. echo "zabbix-agent启动成功"
  102. else
  103. echo "zabbix-agent启动失败"
  104. exit 1
  105. fi
  106. else
  107. echo "zabbix-server启动失败"
  108. exit 1
  109. fi
  110. else
  111. echo "http启动失败"
  112. exit 1
  113. fi
  114. echo -e "\n\033[32m-----------------------------------------------\033[0m"
  115. echo "通过 http://$ipadd/zabbix/ 访问"
  116. echo "数据库用户:root 数据库密码:123456"
  117. echo "登入zabbix默认用户:Admin 密码:zabbix"

2.登入演示

1.通过ip访问zabbix的登入页面,点击下一步

 2.这里检查状态,继续点下一步

 3.这里根据脚本中mysql的用户密码填入,其他的不用改

用户名:root                       密码:123456

4.这里自己定义

5.最后一步install

6.登入

使用默认的用户名:admin                       密码:zabbix

3.设置汉化

 4.添加主机

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/424705
推荐阅读
相关标签
  

闽ICP备14008679号