-
Notifications
You must be signed in to change notification settings - Fork 250
/
system.sh
276 lines (234 loc) · 5.6 KB
/
system.sh
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/bin/bash
#================================================================================
# CentOS 6 Installing script by Neo <[email protected]>
# http://netkiller.sourceforge.net/ , http://netkiller.github.com/
# $Id$
#================================================================================
SRC_DIR=$(pwd)
PREFIX_DIR=/srv
#================================================================================
BOND_IP=172.16.3.1
BOND_MASK=255.255.255.0
BOND_NETWORK=172.16.3.0
NTPDATE=172.16.3.51
#================================================================================
if [ ! -f /usr/bin/vim ] ; then
alias vim='vi'
fi
if [ -z "$( egrep "CentOS|Redhat" /etc/issue)" ]; then
echo 'Only for Redhat or CentOS'
exit
fi
function ntp(){
dnf install ntp -y
ntpdate $NTPDATE
vim /etc/ntp.conf <<VIM > /dev/null 2>&1
:22,24s/^/#/
:25,25s/^/\rserver 172.16.3.51\rserver 172.16.3.52\r/
:wq
VIM
service ntpd start
chkconfig ntpd on
}
function snmp (){
dnf install net-snmp -y
vim /etc/snmp/snmpd.conf <<VIM > /dev/null 2>&1
:62,62s/systemview/all/
:85,85s/^#//
:wq
VIM
service snmpd start
chkconfig snmpd on
}
function nagios(){
dnf install -y nagios
}
function nrpe(){
dnf install -y nrpe nagios-plugins
vim /etc/nagios/nrpe.cfg <<VIM > /dev/null 2>&1
:%s/allowed_hosts=127.0.0.1/allowed_hosts=172.16.1.2/
:wq
VIM
cat >> /etc/nagios/nrpe.cfg <<EOF
#command[check_http]=/usr/lib64/nagios/plugins/check_http -I 127.0.0.1 -p 80 -u http://www.example.com/index.html
command[check_swap]=/usr/lib64/nagios/plugins/check_swap -w 20% -c 10%
command[check_all_disks]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -e
EOF
chkconfig nrpe on
service nrpe start
}
function init(){
dnf update -y
dnf install -y telnet wget rsync
dnf install -y openssh-clients
dnf install -y system-config-network-tui
dnf install -y tcpdump nmap lsof
dnf remove dhclient -y
lokkit --disabled --selinux=disabled
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
rpm -K http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
rpm -i http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
}
function limits(){
cat >> /etc/security/limits.conf <<EOF
root soft nofile 20480
root hard nofile 65536
nobody soft nofile 20480
nobody hard nofile 65536
EOF
}
function sysctl(){
cat >> /etc/sysctl.conf <<EOF
net.ipv4.ip_local_port_range = 1024 65500
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_intvl = 60
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_max_tw_buckets = 4096
EOF
/sbin/sysctl -p
}
function profile(){
echo >> /etc/profile
echo "PATH=$PATH:/srv/php/bin:/srv/httpd/bin:/srv/mysql/bin" >> /etc/profile
#vim /etc/profile <<EOF > /dev/null 2>&1
#:31,31s:^:ulimit -SHn 20480 > /dev/null 2>&1\r:
#:wq
#EOF
#:54,88s/^/#/
#:57,57s/^#//
#:65,65s/^#//
#:68,68s/^#//
#:74,75s/^#//
#:80,80s/^#//
#:83,84s/^#//
#:85,87s/^#//
#:58,58s/^#//
}
ssh(){
vim /etc/ssh/sshd_config <<VIM > /dev/null 2>&1
:%s/#PermitRootLogin yes/PermitRootLogin no/
:%s/#AuthorizedKeysFile/AuthorizedKeysFile/
:wq
VIM
/etc/init.d/sshd restart
vim /etc/sudoers <<VIM > /dev/null 2>&1
:86,86s/^# //
:wq!
VIM
vim /etc/group <<VIM > /dev/null 2>&1
:11,11s/$/,neo/
:wq
VIM
}
function bond(){
cat >> /etc/modprobe.d/bonding.conf <<EOF
alias bond0 bonding
options bond0 mode=balance-alb miimon=1000
EOF
cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
EOF
cat > /etc/sysconfig/network-scripts/ifcfg-eth1 <<EOF
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
EOF
cat >> /etc/sysconfig/network-scripts/ifcfg-eth2 <<EOF
DEVICE=eth2
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
EOF
cat >> /etc/sysconfig/network-scripts/ifcfg-eth3 <<EOF
DEVICE=eth3
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
EOF
cat >> /etc/sysconfig/network-scripts/ifcfg-bond0 <<EOF
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=none
TYPE=Ethernet
IPADDR=192.168.80.65
NETMASK=255.255.255.0
NETWORK=192.168.80.0
USERCTL=no
EOF
ifconfig bond0 up
ifenslave bond0 eth0 eth1 eth2 eth3
}
# See how we were called.
case "$1" in
clean)
clean
;;
init)
init
;;
limits)
limits
;;
sysctl)
sysctl
;;
profile)
profile
;;
ntp)
ntp
;;
snmp)
snmp
;;
nagios)
nagios
;;
nrpe)
nrpe
;;
ssh)
ssh
;;
bond)
if [ ! -f /etc/sysconfig/network-scripts/ifcfg-bond0 ] ; then
bond
fi
;;
all)
init
echo ##################################################
echo # init Installing...
echo ##################################################
echo ##################################################
echo # limits and sysctl Installing...
echo ##################################################
limits
sysctl
echo ##################################################
echo # ntp,snmp and nrpe Installing...
echo ##################################################
ntp
snmp
nrpe
;;
bond)
bond
;;
*)
echo $"Usage: $0 {init}"
echo " {limits|sysctl}"
echo " {ntp|snmp|nagios|nrpe}"
RETVAL=2
;;
esac
exit $RETVAL