-
Notifications
You must be signed in to change notification settings - Fork 37
/
install.sh
151 lines (135 loc) · 4.26 KB
/
install.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
#!/bin/bash
#
# @ Dshield for Python
##############################################################################
# Author: YWJT / Sunshine Koo #
# Modify: 2016-12-10 #
##############################################################################
# This program is distributed under the "Artistic License" Agreement #
# The LICENSE file is located in the same directory as this program. Please #
# read the LICENSE file before you make copies or distribute this program #
##############################################################################
#
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, use sudo sh $0"
exit 1
fi
SHELL_DIR=$(cd "$(dirname "$0")"; pwd)
BASEDIR=$(dirname $SHELL_DIR)
if [ `cat ~/.bash_profile|grep 'Dshield'|wc -l` -eq 0 ];then
echo "PATH="$PATH:$SHELL_DIR >> ~/.bash_profile
echo "export PATH" >> ~/.bash_profile
export PATH=$PATH:$SHELL_DIR
fi
cd $SHELL_DIR
function header()
{
echo
echo "==========================================================================="
echo "| Dshield v4.0.0 For Python"
echo "| Copyright (C)2016,YWJT.org."
echo "| Author: YWJT / Sunshine Koo"
echo "| Github: https://github.com/ywjt/Dshield"
echo "| AuBlog: http://www.ywjt.org"
echo "==========================================================================="
echo
echo "[$(date)] Setup Begin >>>"
}
function option_irq() {
if [ ! -f /var/log/irq_tmp ]
then
if [ ! -z ${MONT_INTERFACE} ]
then
/etc/init.d/irqbalance stop 1>/dev/null 2>&1
IrqID=$(cat /proc/interrupts |grep ${MONT_INTERFACE}|awk -F ':' '{print $1}'|xargs)
Nx=0
for Cid in ${IrqID}
do
Mex=$(echo $((2**${Nx})))
Hex=$(printf "%x" ${Mex})
echo ${Hex} > /proc/irq/${Cid}/smp_affinity
Nx=$((${Nx}+1))
done
echo 1 >> /var/log/irq_tmp
fi
fi
}
function chk_iptables() {
echo "| Check iptables env ... "
if ! rpm -qa iptables|grep 'iptables' >/dev/null
then
yum -y install iptables
else
/sbin/service iptables status 1>/dev/null 2>&1
if [ $? -ne 0 ]; then
#/etc/init.d/iptables start
echo "你的iptables没有启动,请手工执行启动后再跑一次!"
echo "/etc/init.d/iptables start"
read -p "跳过请按'y', 退出按'n':" act
if [[ "${act}" == "n" || "${act}" == "N" ]]
then
exit 1
fi
fi
fi
}
function chk_tcpdump() {
echo "| Check tcpdump env ... "
if [ ! -x /usr/sbin/tcpdump ]
then
yum -y install tcpdump
fi
}
function chk_pyenv() {
echo "| Check python env ... "
i=1
for dir in $(find / -name "site-packages" -type d|grep -E '*/lib/python2.[0-9]/site-packages$')
do
echo "Python Env ($i):" $dir
/bin/cp -rf site-packages/* $dir/
let i=$i+1
done
}
function grafana_init() {
echo "| Install grafana ..."
if ! rpm -qa grafana|grep 'grafana' >/dev/null
then
yum -y install https://grafanarel.s3.amazonaws.com/builds/grafana-4.0.2-1481203731.x86_64.rpm
fi
service grafana-server start
}
function dshield_init() {
echo "| Install dshield ..."
#if [ ! -f Dshield.zip ]
#then
# wget https://github.com/ywjt/Dshield/archive/master.zip -O Dshield.zip
# [ -d Dshield ] && rm -rf Dshield
# unzip Dshield.zip
# cd Dshield
#fi
/bin/cp -rf src /usr/local/Dshield
[ -f /var/lib/grafana/grafana.db ] && mv /var/lib/grafana/grafana.db /var/lib/grafana/grafana.db_
/bin/cp -f grafana.db /var/lib/grafana/
chown grafana:grafana /var/lib/grafana/grafana.db
chmod 775 /var/lib/grafana/grafana.db
chk_pyenv
chown root:root /usr/local/Dshield
chmod 775 -R /usr/local/Dshield
}
####### >>>>>>>>>>>>>>>>>>>
header
chk_iptables
chk_tcpdump
option_irq
grafana_init
dshield_init
####### >>>>>>>>>>>>>>>>>>>
echo
echo "==========================================================================="
echo "| 首先: service grafana-server restart"
echo "| 然后: /usr/local/Dshield/sbin/dshield all start"
echo "| 现在: 打开 http://your_ip:3000/ 输入用户名/密码: admin /admin"
echo "| 尽情: Enjoy!"
echo "==========================================================================="
echo