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
| #!/bin/bash
#--变量
err_echo(){
echo -e "\\033[31m[Error]: $1 \\033[0m"
exit 1
}
info_echo(){
echo -e "\\033[32m [Info]: $1 \\033[0m"
}
warn_echo(){
echo -e "\\033[33m [Warning]: $1 \\033[0m"
}
check_exit(){
if [ $? -ne 0 ]; then
err_echo "$1"
exit 1
fi
}
#配置yum源
info_echo "config yum source....."
rpm -Uvh http://apt.sw.be/redhat/el6/en/x ... 1.el6.rf.x86_64.rpm 1>/dev/null
info_echo "setup tool pakeages...."
yum -y install wget 1>/dev/null
yum -y install perl perl-Net-Telnet perl-Net-DNS perl-LDAP perl-libwww-perl perl-RadiusPerl perl-IO-Socket-SSL perl-Socket6 perl-CGI-SpeedyCGI perl-FCGI perl-CGI-SpeedCGI perl-Time-HiRes perl-ExtUtils-MakeMaker perl-RRD-Simple rrdtool rrdtool-perl curl fping echoping httpd httpd-devel gcc make wget libxml2-devel libpng-devel glib pango pango-devel freetype freetype-devel fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel mod_fastcgi 1>/dev/null
if [ -f /root/smokeping-2.6.9.tar.gz ]; then
warn_echo "/root/smokeping-2.6.9.tar.gz is exist"
else
info_echo "download smokeping...."
wget http://oss.oetiker.ch/smokeping/pub/smokeping-2.6.9.tar.gz 1>/dev/null
fi
check_exit
if [ -f /usr/local/src/smokeping-2.6.9 ]; then
rm -rf /usr/local/src/smokeping-2.6.9
fi
info_echo "tar smokeping to /usr/local/src"
tar -xvf smokeping-2.6.9.tar.gz -C /usr/local/src 1>/dev/null
if [ -f /usr/local/smokeping ]; then
mv /usr/local/smokeping smokeping_back
fi
cd /usr/local/src/smokeping-2.6.9
info_echo "set up smokeping....."
./configure -prefix=/usr/local/smokeping 1>/dev/null
if [ $? -ne 0 ];then
echo -e "\\033[33m first setup faild \\033[0m"
info_echo " per handle symbiosis......"
./setup/build-perl-modules.sh /usr/local/smokeping/thirdparty 1>/dev/null
info_echo "full install smokeping....."
./configure -prefix=/usr/local/smokeping 1>/dev/null
/usr/bin/gmake install 1>/dev/null
else
/usr/bin/gmake install 1>/dev/null
check_exit
fi
cd /usr/local/smokeping
mkdir cache data var 1>/dev/null
check_exit
info_echo "chomod dir permission"
#修改目录权限
chown -R apache:apache cache data var
chown -R apache:apache /var/log/smokeping.log
mv /usr/local/smokeping/htdocs/smokeping.fcgi.dist /usr/local/smokeping/htdocs/smokeping.fcgi
mv /usr/local/smokeping/etc/config.dist /usr/local/smokeping/etc/config
cp -f /usr/local/smokeping/etc/config /usr/local/smokeping/etc/config.back
info_echo "edit smokeping config....."
#修改smokeping配置文件
IP=`/sbin/ifconfig|sed -n '/inet addr/s/^[^:]*:\([0-9.]\{7,15\}\) .*/\1/1p'|sed -n '1p'`
sed -i "/cgiurl/c cgiurl = http:\/\/$IP/smokeping.cgi" /root/config
sed -i "/imgurl/c imgurl = http:\/\/$IP/cache" /root/config
chmod 600 /usr/local/smokeping/etc/smokeping_secrets.dist
info_echo "edit httpd config....."
#修改apache配置文件
cp -rf /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.back
cat >> /etc/httpd/conf/httpd.conf <<'EOF'
Alias /cache "/usr/local/smokeping/cache/"
Alias /cropper "/usr/local/smokeping/htdocs/cropper/"
Alias /smokeping "/usr/local/smokeping/htdocs/smokeping.fcgi"
<Directory "/usr/local/smokeping">
AllowOverride None
Options All
AddHandler cgi-script .fcgi .cgi
Order allow,deny
Allow from all
DirectoryIndex smokeping.fcgi
</Directory>
EOF
#提供启动脚本
info_echo "edit auto manger script"
if [ -f /etc/init.d/smokeping ];then
warn_echo "/etc/init.d/smokeping is exist"
else
touch /etc/init.d/smokeping
cat > /etc/init.d/smokeping <<'EOF'
#!/bin/bash
#chkconfig: 2345 80 05
# Description: Smokeping init.d script
# Create by : Mox
# Get function from functions library
. /etc/init.d/functions
# Start the service Smokeping
smokeping=/usr/local/smokeping/bin/smokeping
prog=smokeping
pidfile=${PIDFILE-/usr/local/smokeping/var/smokeping.pid}
lockfile=${LOCKFILE-/var/lock/subsys/smokeping}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
LOG=/var/log/smokeping.log
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $smokeping $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
# Restart the service Smokeping
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d ${STOP_TIMEOUT} $smokeping
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart|status}"
RETVAL=2
esac
EOF
chmod +x /etc/init.d/smokeping
chkconfig smokeping on
fi
if [ $? -ne 0 ];then
echo -e "\\033[32m smokeping setup successfull \\033[0m"
fi
|