centos7脚本安装zabbix

环境

  • CentOS 7 Minimal x64
  • zabbix 2.2 LST
  • httpd 2.4
  • php 5.4
  • mariadb 5.5

默认的版本比较老,如果使用新的,PHP使用remi,MariaDB可以使用官方源

#mariadb官方源,10.3版本;yum下载比较慢
https://downloads.mariadb.com/MariaDB/mariadb-10.3.9/yum/rhel/mariadb-10.3.9-rhel-7-x86_64-rpms.tar
tar xvf mariadb-10.3.9-rhel-7-x86_64-rpms.tar
cd mariadb-10.3.9-rhel-7-x86_64-rpms

sudo yum localinstall \
MariaDB-10.3.9-centos73-x86_64-server.rpm \
MariaDB-10.3.9-centos73-x86_64-client.rpm \
galera-25.3.23-1.rhel7.el7.centos.x86_64.rpm \
MariaDB-10.3.9-centos73-x86_64-common.rpm \
MariaDB-10.3.9-centos73-x86_64-compat.rpm ;
#php7.x
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
[remi-php7x]
enabled=1
#根据依赖会自动安装epel

一键安装脚本

for zabbix 2.2 lst and other default

#! /bin/bash

# disable selinux
sudo sed -i s/SELINUX\=enforcing/SELINUX\=disabled/g /etc/selinux/config
sudo setenforce 0

# install zabbix repositories
sudo yum install http://repo.zabbix.com/zabbix/2.2/rhel/7/x86_64/zabbix-release-2.2-1.el7.noarch.rpm -y
#https可能会下载失败,使用前先wget一下,在选http还是https
# 3.4的配置也是相同,替换上面的版本即可
sudo yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent mariadb-server mariadb expect -y

# modify php.ini
sudo sed -i s/post_max_size\ =\ 8M/post_max_size\ =\ 16M/g /etc/php.ini
sudo sed -i s/max_execution_time\ =\ 30/max_execution_time\ =\ 300/g /etc/php.ini
sudo sed -i s/max_input_time\ =\ 60/max_input_time\ =\ 600/g /etc/php.ini
sudo sed -i s:\;date.timezone\ =:date.timezone\ =\ Asia/Shanghai:g /etc/php.ini

# modify
sudo sed -i s/DBName=zabbix/DBName=zabbix_db/g /etc/zabbix/zabbix_server.conf
sudo sed -i s/DBUser=zabbix/DBUser=zabbix_user/g /etc/zabbix/zabbix_server.conf
sudo sed -i s/\#\ DBPassword=/DBPassword=123456/g /etc/zabbix/zabbix_server.conf

# add firewall rules
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-port=10051/tcp --permanent
sudo firewall-cmd --add-port=10050/tcp --permanent
sudo firewall-cmd --reload

# enable service and starting service
sudo systemctl enable mariadb httpd zabbix-server zabbix-agent
sudo systemctl start mariadb httpd zabbix-server zabbix-agent

#initialize MariaDB
#第一步的输入空密码坑了2天,expect也真是麻烦,得输入它看见的内容,然后在做出反应
expect << EOF

spawn mysql_secure_installation
expect "Enter current password for root (enter for none):"
send "\r"

expect "Set root password"
send "y\r"

expect "New password:"
send "123456\r"

expect "Re-enter new password:"
send "123456\r"

expect "Remove anonymous users? "
send "\r"

expect "Disallow root login remotely?"
send "\r"

expect "Remove test database and access to it?"
send "\r"

expect "Reload privilege tables now?"
send "\r"

expect eof
EOF

# import initial data
#最后那个exit或quit不能带分号";"否则会报错;use database也不用带,不然也报在附近有语法错误
#line 4: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'quit' at line 1

mysql -uroot -p123456 -e "
create database zabbix_db character set utf8 collate utf8_bin;
grant all privileges on zabbix_db.* to zabbix_user@localhost identified by '123456';
exit
"
cd /usr/share/doc/zabbix-server-mysql-2.2.23/create #如果换成3.4版本了,这里需要修改路径
mysql -uzabbix_user -p123456 zabbix_db < schema.sql;
mysql -uzabbix_user -p123456 zabbix_db < images.sql;
mysql -uzabbix_user -p123456 zabbix_db < data.sql;

echo "zabbix deploy completed"

You may also like...

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据