zabbix一键安装脚本

释放双眼,带上耳机,听听看~!

#脚本和之前的说明都是从网上CP过来的,不过后面有些自己安装时遇到的问题,在网上的帖子并没有提到,在此描述下。

说明:此脚本只适用与RHEL6.x系列;Nginx版本为1.6最新稳定版;PHP为5.4最新版;Mysql为5.5最新稳定版;Zabbix暂时为2.4最新版。


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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
1#!/bin/bash
2# install Nginx 1.6.2 + mysql5.5.x + PHP-FPM 5.4.x + Zabbix 2.4.4 automatically.
3# Tested on CentOS 6.5
4##############################################
5# 变量
6##############################################
7err_echo(){
8  echo -e "\e[91m[Error]: $1 33[0m"
9  exit 1
10}
11info_echo(){
12  echo -e "\e[92m[Info]: $1 33[0m"
13}
14warn_echo(){
15  echo -e "\e[93m[Warning]: $1 33[0m"
16}
17check_exit(){
18  if [ $? -ne 0 ]; then
19    err_echo "$1"
20    exit1
21  fi
22}
23##############################################
24# check
25##############################################
26if [ $EUID -ne 0 ]; then
27  err_echo "please run this script as root user."
28  exit 1
29fi
30if [ "$(awk '{if ( $3 >= 6.0 ) print "CentOS 6.x"}' /etc/redhat-release 2>/dev/null)" != "CentOS 6.x" ];then
31  err_echo "This script is used for RHEL/CentOS 6.x only."
32fi
33##############################################
34# Useradd deploy nginx程序运行账号
35##############################################
36info_echo "Useradd deploy"
37useradd deploy
38##############################################
39# yum repo
40##############################################
41info_echo "配置yum源......"
42if [ ! -f LNMP+zabbix.repo ]; then
43cat> /etc/yum.repos.d/LNMP+zabbix.repo <<'EOF'
44[nginx]
45name=nginx repo
46baseurl=http://nginx.org/packages/centos/6/$basearch/
47gpgcheck=0
48enabled=1
49[webtatic]
50name=Webtatic Repository EL6 - $basearch
51#baseurl=http://repo.webtatic.com/yum/el6/$basearch/
52mirrorlist=http://mirror.webtatic.com/yum/el6/$basearch/mirrorlist
53failovermethod=priority
54enabled=0
55gpgcheck=0
56[remi]
57name=Les RPM de remi pour Enterprise Linux 6 - $basearch
58#baseurl=http://rpms.famillecollet.com/enterprise/6/remi/$basearch/
59mirrorlist=http://rpms.famillecollet.com/enterprise/6/remi/mirror
60enabled=1
61gpgcheck=0
62[zabbix]
63name=Zabbix Official Repository-$basearch
64baseurl=http://repo.zabbix.com/zabbix/2.4/rhel/6/$basearch/
65enabled=1
66gpgcheck=0
67[zabbix-non-supported]
68name=Zabbix Official Repository non-supported-$basearch
69baseurl=http://repo.zabbix.com/non-supported/rhel/6/$basearch/
70enabled=1
71gpgcheck=0
72EOF
73fi
74##############################################
75# Install nginx+Mysql+PHP+zabbix
76##############################################
77info_echo "Install nginx+Mysql+PHP+zabbix......"
78yum -y install nginx php php-fpm php-cli php-common php-gd php-mbstring php-mcrypt php-mysql php-pdo php-devel php-imagick php-xmlrpc php-xml php-bcmath php-dba php-enchant php-yaf  mysql mysql-server zabbix zabbix-get zabbix-agent zabbix-server-mysql zabbix-web-mysql zabbix-server
79check_exit "Failed to install Nginx/Mysql/PHP/Zabbix!"
80#########################################
81# Nginx
82#########################################
83info_echo "Nginx 配置文件更新 ...."
84if [ -f /etc/nginx/nginx.conf ]; then
85mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
86cat> /etc/nginx/nginx.conf <<'EOF'
87user deploy;
88worker_processes 2;
89pid /var/run/nginx.pid;
90worker_rlimit_nofile 65535;
91events {
92  worker_connections  65535;
93  use epoll;
94}
95http {
96   ##
97  # Basic Settings
98   ##
99   sendfile on;
100   tcp_nopush on;
101   tcp_nodelay on;
102   keepalive_timeout 65;
103   types_hash_max_size 2048;
104   server_tokens off;
105   client_header_buffer_size 4k;
106   open_file_cache max=65535 inactive=60s;
107   open_file_cache_valid 80s;
108   open_file_cache_min_uses 1;
109   server_names_hash_bucket_size 64;
110   server_name_in_redirect off;
111   include /etc/nginx/mime.types;
112   default_type application/octet-stream;
113   ##
114  # Logging Settings
115   ##
116   access_log /var/log/nginx/access.log;
117   error_log /var/log/nginx/error.log;
118  ##
119   # Gzip Settings
120  ##
121   gzip on;
122   gzip_disable "msie6";
123   gzip_min_length 1k;
124   gzip_buffers 4 16k;
125   gzip_comp_level 2;
126   gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
127   ##
128   # nginx-naxsi config
129   ##
130    # Uncomment it if you installed nginx-naxsi
131    ##
132    #include /etc/nginx/naxsi_core.rules;
133  ##
134  # nginx-passenger config
135  ##
136  # Uncomment it if you installed nginx-passenger
137  ##
138  #passenger_root /usr;
139  #passenger_ruby /usr/bin/ruby;
140  ##
141  # Virtual Host Configs
142  ##
143    log_format  main  '$server_name $remote_addr - $remote_user [$time_local] "$request" '
144            '$status $body_bytes_sent "$http_referer" '
145            '"$http_user_agent" "$http_x_forwarded_for" '
146            '$ssl_protocol $ssl_cipher $upstream_addr $request_time $upstream_response_time';
147  include /etc/nginx/conf.d/*.conf;
148  include /etc/nginx/sites-enabled/*.conf;
149}
150EOF
151fi
152sed -i "/worker_processes/cworker_processes $( grep "processor" /proc/cpuinfo| wc -l );" /etc/nginx/nginx.conf
153info_echo "zabbix 配置文件添加"
154cat> /etc/nginx/conf.d/zabbix.conf <<'EOF'
155server{
156   listen      80;
157   server_name  _;
158   index index.php;
159   root /data/web/zabbix;
160   location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
161     expires 30d;
162   }
163   location ~* \.php$ {
164     fastcgi_pass   127.0.0.1:9000;
165     fastcgi_index  index.php;
166     fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
167     include        fastcgi_params;
168   }
169}
170EOF
171mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
172/etc/init.d/nginx restart
173#########################################
174# Zabbix
175#########################################
176info_echo "Downloading zabbix Web...."
177info_echo "创建网站目录..."
178mkdir -p /data/web/zabbix
179info_echo "Downloading..."
180if [ ! -f /tmp/zabbix.tar.gz ]; then
181   cd /tmp && wget -O zabbix.tar.gz 'http://sourceforge.net/projects/zabbix/files/latest/download?source=files'
182fi
183info_echo "解压安装文件..."
184cd /tmp && tar -zxvf /tmp/zabbix.tar.gz
185check_exit "failed to extract zabbix frontend"
186ZABBIX_DIR=`ls /tmp/|grep zabbix-`
187mv /tmp/${ZABBIX_DIR}/frontends/php/* /data/web/zabbix/
188chown -R deploy.deploy /data/web/zabbix
189##############################################
190# Database
191##############################################
192info_echo "Mysql配置文件更新..."
193sed -i '/^socket/i\port         = 3306' /etc/my.cnf
194sed -i '/^socket/a\skip-external-locking\nkey_buffer_size = 256M\nmax_allowed_packet = 1M\ntable_open_cache = 256\nsort_buffer_size = 1M\nread_buffer_size = 1M\nread_rnd_buffer_size = 4M\nmyisam_sort_buffer_size = 64M\nthread_cache_size = 8\nquery_cache_size= 16M\nthread_concurrency = 4\ncharacter-set-server=utf8\ninnodb_file_per_table=1' /etc/my.cnf
195info_echo "Restart mysql ..."
196/etc/init.d/mysqld start
197info_echo "Create Databases..."
198mysql -e 'CREATE DATABASE `zabbix` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;'
199mysql -e "GRANT ALL PRIVILEGES on *.* to zabbix@'localhost' IDENTIFIED BY 'zabbix';"
200mysql -e "flush privileges"
201info_echo "配置zabbix的数据库项"
202sed -i '/DBPassword=/a\DBPassword=zabbix' /etc/zabbix/zabbix_server.conf
203info_echo "importing schema.sql"
204mysql -uzabbix -pzabbix zabbix < $(rpm -ql zabbix-server-mysql|grep schema.sql)
205check_exit "failed to import schema.sql"
206info_echo "importing images.sql"
207mysql -uzabbix -pzabbix zabbix < $(rpm -ql zabbix-server-mysql| grep images.sql)
208check_exit "failed to import images.sql"
209info_echo "importing data.sql"
210mysql -uzabbix -pzabbix zabbix < $(rpm -ql zabbix-server-mysql|grep data.sql)
211check_exit "failed to import data.sql"
212#########################################
213# PHP-FPM
214#########################################
215info_echo "更新/etc/php.ini,www.conf ..."
216sed -i '/^;default_charset/a\default_charset = "UTF-8"' /etc/php.ini
217sed -i '/^expose_php/cexpose_php = Off' /etc/php.ini
218sed -i '/^max_execution_time/cmax_execution_time = 300' /etc/php.ini
219sed -i '/^max_input_time/cmax_input_time = 300' /etc/php.ini
220sed -i '/^memory_limit/cmemory_limit = 256M'  /etc/php.ini
221sed -i '/^post_max_size/cpost_max_size = 32M' /etc/php.ini
222sed -i '/^upload_max_filesize/cupload_max_filesize = 300M' /etc/php.ini
223sed -i '/^max_file_uploads/cmax_file_uploads = 30' /etc/php.ini
224sed -i '/^;date.timezone/cdate.timezone = "PRC"' /etc/php.ini
225sed -i 's/apache/deploy/g' /etc/php-fpm.d/www.conf
226chown deploy.deploy -R /var/lib/php
227info_echo "Checking php-fpm configuration file..."
228/etc/init.d/php-fpm configtest
229check_exit "PHP-FPM configuration syntax error"
230info_echo "Restart PHP-FPM ..."
231/etc/init.d/php-fpm restart
232info_echo "Restart Zabbix Server ..."
233/etc/init.d/zabbix-server restart
234info_echo "Restart Zabbix Agent ..."
235/etc/init.d/zabbix-agent restart
236#########################################
237# 开机启动项
238#########################################
239chkconfig nginx on
240chkconfig php-fpm on
241chkconfig mysql on
242chkconfig zabbix-agent on
243chkconfig zabbix-server on
244

脚本运行结束后查看端口是否打开,否则还是无法登陆页面。


1
2
3
4
5
6
7
1[root@localhost zabbix]# lsof -i:80
2COMMAND    PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
3clock-app 2488   root   22w  IPv4  17293      0t0  TCP 192.168.230.148:46616->a184-25-205-26.deploy.static.akamaitechnologi
4nginx     2776   root    6u  IPv4  21898      0t0  TCP *:http (LISTEN)
5nginx     2777 deploy    6u  IPv4  21898      0t0  TCP *:http (LISTEN)
6nginx     2778 deploy    6u  IPv4  21898      0t0  TCP *:http (LISTEN)
7

我这为了方便,直接将防火墙关闭,如有需要,打开80即可


1
2
3
4
5
6
1[root@localhost zabbix]# service iptables stop
2iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
3iptables: Flushing firewall rules:                         [  OK  ]
4iptables: Unloading modules:                               [  OK  ]
5
6

给TA打赏
共{{data.count}}人
人已打赏
安全技术安全运维

Windows服务器如何发现被黑

2018-5-20 12:24:31

安全技术

详解Node.js API系列 Crypto加密模块(2) Hmac

2021-12-21 16:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索