zabbix install distributed
基础环境安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135//系统信息
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core)
//修改主机名
zabbix-server-company:
[root@localhost ~]# hostname zabbix-server-company && echo zabbix-server-company | tee /etc/hostname
[root@localhost ~]# $SHELL
[root@zabbix-server-company ~]#
zabbix-server-mysql:
[root@localhost ~]# hostname zabbix-server-mysql && echo zabbix-server-mysql | tee /etc/hostname
[root@localhost ~]# $SHELL
[root@zabbix-server-mysql ~]#
//格式化磁盘(ALL)
[root@[ALL] ~]# mkfs.xfs /dev/vdb
[root@[ALL] ~]# echo '/dev/vdb /mnt xfs defaults 0 0' | tee -a /etc/fstab
[root@[ALL] ~]# mount -a
//修改最大文件数(ALL)
[root@[ALL] ~]# echo '* - nproc 65535' | tee -a /etc/security/limits.conf
[root@[ALL] ~]# echo '* - nofile 65535' | tee -a /etc/security/limits.conf
[root@[ALL] ~]# ls /etc/security/limits.d/|xargs rm -f
//YUM源设置(ALL)
[root@[ALL] ~]# mkdir /etc/yum.repos.d/backup && mv /etc/yum.repos.d/{*,backup}
[root@[ALL] ~]# curl -o /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@[ALL] ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@[ALL] ~]# curl -O https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[root@[ALL] ~]# rpm --import RPM-GPG-KEY-CentOS-7
[root@[ALL] ~]# rm -f RPM-GPG-KEY-CentOS-7
[root@[ALL] ~]# yum clean all
[root@[ALL] ~]# yum makecache
//安装基础软件包(ALL)
[root@[ALL] ~]# yum -y groupinstall "Development Tools"
[root@[ALL] ~]# yum -y install \
make cmake \
bison-devel \
bzip2-devel \
zlib zlib-devel \
openssl openssl-devel openssl-libs \
pcre pcre-devel pcre-static \
ncurses ncurses-devel ncurses-libs \
bzip2-devel\
openldap openldap-devel \
readline readline-devel readline-static \
libssh2 libssh2-devel \
unixODBC unixODBC-devel \
sqlite sqlite-devel \
tcl tcl-devel \
perl-Digest-SHA1 \
python-libs python-devel python2-pip python-crypto \
perl-libs \
GeoIP GeoIP-devel \
gperftools gperftools-devel gperftools-libs \
libatomic_ops-devel \
gtest gtest-devel \
gdk-pixbuf2 gdk-pixbuf2-deve \
libffi libffi-devel \
libcurl libcurl-devel \
http-parser http-parser-devel
[root@[ALL] ~]# yum -y install fop lftp ntp ntpdate vim wget telnet dstat tree lrzsz net-tools nmap-ncat nmap sysstat
//关闭selinux(ALL)
[root@[ALL] ~]# setenforce 0
[root@[ALL] ~]# sed -i s/'SELINUX=enforcing'/'SELINUX=disabled'/g /etc/selinux/config
//关闭防火墙(ALL)
[root@[ALL] ~]# systemctl stop firewalld && systemctl disable firewalld
//设置时区和时间(ALL)
[root@[ALL] ~]# [ -f /etc/localtime ] && cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[root@[ALL] ~]# [ -f /etc/sysconfig/clock ] && echo 'ZONE="Asia/Shanghai"' | tee /etc/sysconfig/clock
[root@[ALL] ~]# [ -f /etc/timezone ] && echo 'Asia/Shanghai' | tee /etc/timezone
[root@[ALL] ~]# [ -f /etc/sysconfig/ntpd ] && echo 'SYNC_HWCLOCK=yes' | tee -a /etc/sysconfig/ntpd
[root@[ALL] ~]# ntpdate cn.pool.ntp.org
[root@[ALL] ~]# cp -f /etc/{ntp.conf,ntp.conf.bak}
[root@[ALL] ~]# cat > /etc/ntp.conf <<EOF
> driftfile /var/lib/ntp/drift
> restrict default nomodify notrap nopeer noquery
> restrict 127.0.0.1
> restrict ::1
> server cn.pool.ntp.org prefer
> server 0.centos.pool.ntp.org iburst
> server 1.centos.pool.ntp.org iburst
> server 2.centos.pool.ntp.org iburst
> server 3.centos.pool.ntp.org iburst
> includefile /etc/ntp/crypto/pw
> keys /etc/ntp/keys
> disable monitor
> EOF
[root@[ALL] ~]# cp -f /etc/ntp/{step-tickers,step-tickers.bak}
[root@[ALL] ~]# cat > /etc/ntp/step-tickers <<EOF
> cn.pool.ntp.org
> 0.centos.pool.ntp.org
> 1.centos.pool.ntp.org
> 2.centos.pool.ntp.org
> 3.centos.pool.ntp.org
> EOF
[root@[ALL] ~]# systemctl start ntpd && systemctl enable ntpd
//设置PIP源(ALL)
[root@[ALL] ~]# mkdir ~/.pip
[root@[ALL] ~]# cat > ~/.pip/pip.conf <<EOF
> [global]
> trusted-host=mirrors.aliyun.com
> index-url=http://mirrors.aliyun.com/pypi/simple/
> [list]
> format=columns
> EOF
//python安装(ALL)
[root@[ALL] ~]# git clone https://github.com/yyuu/pyenv.git /usr/local/pyenv
[root@[ALL] ~]# echo 'export PYENV_ROOT=/usr/local/pyenv' | tee /etc/profile.d/pyenv.sh
[root@[ALL] ~]# echo 'export PATH="$PYENV_ROOT/bin:$PATH"' | tee -a /etc/profile.d/pyenv.sh
[root@[ALL] ~]# echo 'eval "$(pyenv init -)"' | tee -a /etc/profile.d/pyenv.sh
[root@[ALL] ~]# source /etc/profile
[root@[ALL] ~]# exec $SHELL
[root@[ALL] ~]# mkdir -p ${PYENV_ROOT}/cache
[root@[ALL] ~]# v=2.7.13;wget -P /usr/local/pyenv/cache/ http://mirrors.sohu.com/python/$v/Python-$v.tar.xz
[root@[ALL] ~]# pyenv install 2.7.13
[root@[ALL] ~]# pyenv rehash
[root@[ALL] ~]# pyenv local 2.7.13
[root@ALL Python-2.7.13]# python -V
Python 2.7.13
[root@ALL Python-2.7.13]# pip -V
pip 9.0.1 from /usr/local/python27/lib/python2.7/site-packages (python 2.7)
//设置开机启动文件权限
[root@[ALL] ~]# chmod +x /etc/rc.d/rc.local
//创建基础目录(ALL)
[root@[ALL] ~]# mkdir -p /mnt/{app,data,log,web,ops/{app,data,cron}}修改内核
1
2
3
4
5
6
7[root@[ALL] ~]# cat >> /etc/sysctl.conf <<EOF
kernel.shmmax=30000000000
kernel.shmall=7000000
kernel.msgmax=65535
kernel.msgmnb=65535
EOF
[root@[ALL] ~]# sysctl -pzabbix-server-mysql 数据库安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138[root@zabbix-server-mysql app]# useradd -s /sbin/nologin mysql
[root@zabbix-server-mysql app]# tar xzf mysql-5.6.35.tar.gz
[root@zabbix-server-mysql app]# cd mysql-5.6.35
[root@zabbix-server-mysql mysql-5.6.35]# cmake \
> -DCMAKE_INSTALL_PREFIX=/mnt/app/mysql \
> -DWITH_MYISAM_STORAGE_ENGINE=1 \
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \
> -DENABLED_LOCAL_INFILE=1 \
> -DWITH_PARTITION_STORAGE_ENGINE=1 \
> -DEXTRA_CHARSETS=all \
> -DDEFAULT_CHARSET=utf8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DENABLE_DOWNLOADS=1
[root@zabbix-server-mysql mysql-5.6.35]# make
[root@zabbix-server-mysql mysql-5.6.35]# make install
[root@zabbix-server-mysql mysql-5.6.35]# echo 'export MYSQL_BASE=/mnt/app/mysql' |tee /etc/profile.d/mysql.sh
[root@zabbix-server-mysql mysql-5.6.35]# echo 'export MYSQL_BIN=$MYSQL_BASE/bin' |tee -a /etc/profile.d/mysql.sh
[root@zabbix-server-mysql mysql-5.6.35]# echo 'export PATH=$MYSQL_BIN:$PATH' |tee -a /etc/profile.d/mysql.sh
[root@zabbix-server-mysql mysql-5.6.35]# source /etc/profile
[root@zabbix-server-mysql mysql-5.6.35]# mkdir -p /mnt/{data,log}/mysql/3306
[root@zabbix-server-mysql mysql-5.6.35]# touch /mnt/log/mysql/3306/mysqld.log
[root@zabbix-server-mysql mysql-5.6.35]# chown -R mysql.mysql /mnt/{data,log}/mysql
[root@zabbix-server-mysql mysql-5.6.35]# chmod +x scripts/*
[root@zabbix-server-mysql mysql-5.6.35]# ./scripts/mysql_install_db --basedir=/mnt/app/mysql/ --datadir=/mnt/data/mysql/3306/ --user=mysql
[root@zabbix-server-mysql mysql-5.6.35]# mkdir -p /mnt/app/mysql/conf
[root@zabbix-server-mysql mysql-5.6.35]# cat > /mnt/app/mysql/conf/3306.M.cnf <<EOF
[mysqld]
user = mysql
port = 3306
basedir = /mnt/app/mysql
datadir = /mnt/data/mysql/3306
socket = /mnt/data/mysql/3306/mysql.sock
default-storage-engine = InnoDB
character_set_server = utf8
max_connections = 100000
skip-name-resolve
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
server-id = 82
max_allowed_packet = 32m
max_heap_table_size = 256m
read_rnd_buffer_size = 16m
sort_buffer_size = 8m
join_buffer_size = 8m
query_cache_type = 1
query_cache_size = 1024m
query_cache_limit = 8m
innodb_open_files = 30000
innodb_buffer_pool_size = 24G
innodb_file_per_table = 1
[mysqld_safe]
log-error=/mnt/log/mysql/3306/mysqld.log
pid-file =/mnt/app/mysql/mysqld.3306.pid
[client]
default-character-set=utf8
socket=/mnt/data/mysql/3306/mysql.sock
[mysql]
default-character-set=utf8
socket=/mnt/data/mysql/3306/mysql.sock
EOF
[root@zabbix-server-mysql mysql-5.6.35]# cat > /etc/init.d/mysql.3306M <<EOF
if [ $# != 1 ];then
echo "Please input:
/etc/init.d/$0 start
/etc/init.d/$0 stop
/etc/init.d/$0 status
"
exit 0
fi
STATUS=$1
ROLE='mysql'
PORT=3306
SQLAPP="/mnt/app/${ROLE}/bin/mysqld_safe"
SQLSHT="/mnt/app/${ROLE}/bin/mysqladmin"
SOCKET="/mnt/data/${ROLE}/${PORT}/mysql.sock"
COFIG="/mnt/app/${ROLE}/conf/${PORT}.M.cnf"
if [ $STATUS == "start" ];then
${SQLAPP} --defaults-file=${COFIG} &
if [ $? == 0 ];then
echo "$ROLE $PORT start success."
else
echo "$ROLE $PORT start fail."
fi
fi
if [ $STATUS == "stop" ];then
${SQLSHT} -S ${SOCKET} shutdown
if [ $? == 0 ];then
echo "$ROLE $PORT stoped success."
else
echo "$ROLE $PORT stoped fail."
fi
fi
if [ $STATUS == "kill" ];then
PID=$(ps -ef|grep -w ${ROLE}|grep ${PORT}|grep -v grep|grep -v bash|awk '{print $2}'|tr '\n' ' ')
kill -9 $PID
if [ $? == 0 ];then
echo "$ROLE $PORT killed success."
else
echo "$ROLE $PORT killed fail."
fi
fi
if [ $STATUS == "status" ];then
NUM=$(ps -ef|grep -w ${ROLE}|grep ${PORT}|grep root|grep -v grep|grep -v bash|awk '{print $2}'|wc -l)
if [ $NUM == 0 ];then
echo "$ROLE $PORT is stopped."
exit 0
fi
if [ $NUM != 1 ];then
echo "Please check $ROLE, There are $NUM processes."
fi
PID=$(ps -ef|grep -w ${ROLE}|grep ${PORT}|grep -v grep|grep -v bash|awk '{print $2}'|tr '\n' ' ')
echo "$ROLE $PORT is running. PID: $PID"
fi
EOF
[root@zabbix-server-mysql ~]# chmod +x /etc/init.d/mysql.3306M
[root@zabbix-server-mysql ~]# chown -R mysql.mysql /mnt/app/mysql
[root@zabbix-server-mysql ~]# /etc/init.d/mysql.3306M start
[root@zabbix-server-mysql ~]# echo '/etc/init.d/mysql.3306M start' | tee -a /etc/rc.localzabbix-server-company zabbix安装
1
2
3
4[root@zabbix-server-company ~]# rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
[root@zabbix-server-company ~]# yum -y install zabbix-server-mysql zabbix-web-mysql httpd
[root@zabbix-server-company ~]# yum -y install zabbix-java-gateway zabbix-sender zabbix-get创建zabbix-server数据库
1
2
3
4
5
6
7
8//安装完zabbix-server-mysql后,将数据库表结构拷贝到zabbix-server-mysql上
[root@zabbix-server-company ~]# scp /usr/share/doc/zabbix-server-mysql-3.2.7/create.sql.gz root@zabbix-server-mysql:/mnt/ops/app/
[root@zabbix-server-mysql app]# mysql -S /mnt/data/mysql/3306/mysql.sock
mysql> create database zabbix_server character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix_server.* to zabbix@192.168.10.81 identified by 'zabbix';
mysql> flush privileges;
[root@zabbix-server-mysql app]# zcat create.sql.gz | mysql -S /mnt/data/mysql/3306/mysql.sock -B zabbix_server修改zabbix-server配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47[root@zabbix-server-company ~]# vim /etc/zabbix/zabbix_server.conf
ListenPort=10051
LogType=file
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=512
DebugLevel=3
PidFile=/var/run/zabbix/zabbix_server.pid
DBHost=192.168.10.82
DBName=zabbix_server
DBUser=zabbix
DBPassword=UPCLfTHSj72a
DBPort=3306
StartPollers=500
StartIPMIPollers=0
StartPollersUnreachable=50
StartTrappers=50
StartPingers=30
StartDiscoverers=80
StartHTTPPollers=30
StartTimers=100
StartEscalators=30
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
StartSNMPTrapper=0
HousekeepingFrequency=1
MaxHousekeeperDelete=500000
SenderFrequency=60
CacheSize=2G
CacheUpdateFrequency=300
StartDBSyncers=50
HistoryCacheSize=2G
HistoryIndexCacheSize=2G
TrendCacheSize=2G
ValueCacheSize=5G
Timeout=20
TrapperTimeout=300
UnreachablePeriod=300
UnavailableDelay=300
UnreachableDelay=30
AlertScriptsPath=/etc/zabbix/zabbix_alert
ExternalScripts=/usr/lib/zabbix/zabbix_exec
FpingLocation=/usr/sbin/fping
LogSlowQueries=1000
StartProxyPollers=50
ProxyConfigFrequency=300
ProxyDataFrequency=30
[root@zabbix-server-company ~]# systemctl start zabbix-server
[root@zabbix-server-company ~]# systemctl enable zabbix-server设置 httpd zabbix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41[root@zabbix-server-company ~]# cat > /etc/httpd/conf.d/zabbix.conf <<EOF
#
# Zabbix monitoring system php web frontend
#
Alias /zabbix /usr/share/zabbix
<Directory "/usr/share/zabbix">
Options FollowSymLinks
AllowOverride None
Require all granted
<IfModule mod_php5.c>
php_value max_execution_time 300
php_value memory_limit 2048M
php_value post_max_size 512M
php_value upload_max_filesize 200M
php_value max_input_time 300
php_value always_populate_raw_post_data -1
php_value date.timezone Asia/Shanghai
</IfModule>
</Directory>
<Directory "/usr/share/zabbix/conf">
Require all denied
</Directory>
<Directory "/usr/share/zabbix/app">
Require all denied
</Directory>
<Directory "/usr/share/zabbix/include">
Require all denied
</Directory>
<Directory "/usr/share/zabbix/local">
Require all denied
</Directory>
EOF
[root@zabbix-server-company ~]# systemctl start httpd
[root@zabbix-server-company ~]# systemctl enable httpd打开浏览器进行设置
1
URL: http://192.168.10.81/zabbix/ 默认账号/密码:Admin/zabbix