-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathinstall
More file actions
executable file
·350 lines (280 loc) · 9.72 KB
/
install
File metadata and controls
executable file
·350 lines (280 loc) · 9.72 KB
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/bin/bash
# Hello boys and girls, Welcome to OpenCDN!
# OpenCDN a open-source management platform, which can help you build node-hosts in 5 minutes.
# The system consists of the Control Center(CC) and Node Host(NH). The CC can monitor a basic
# system information on each node, such as cpu usage and health status. CC also can collect logs
# of nginx from all node-hosts. You'd better reference to source code
# author : firefoxbug
# E-Mail : wanghuafire@gmail.com
# Blog : blog.csdn.net/firefoxbug
## Check user permissions ##
if [ $(id -u) != "0" ]; then
echo "Error: NO PERMISSION! Please login as root to install MAPn."
exit 1
fi
function killd_server()
{
kill -9 `ps aux | grep "httpd" | awk "{print $2}"` > /dev/null 2>&1
kill -9 `ps aux | grep "mysqld" | awk "{print $2}"` > /dev/null 2>&1
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yum install -y ntp
ntpdate -u pool.ntp.org
date
rpm -qa|grep httpd
rpm -e httpd
rpm -qa|grep mysql
rpm -e mysql
rpm -qa|grep php
rpm -e php
yum -y remove httpd*
yum -y remove php*
yum -y remove mysql-server mysql
yum -y remove php-mysql
yum -y install yum-fastestmirror
yum -y remove httpd
}
get_char()
{
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
function get_system_basic_info()
{
echo "==========================OpenCDN===================================="
echo "* *"
echo "* *"
echo "* Welcome To OpenCDN *"
echo "* *"
echo "* *"
echo "==========================OpenCDN===================================="
echo ""
echo "Press any key to start install opencdn , please wait ......"
char=`get_char`
OpenCDN_Manage_IP=""
echo ""
echo -n "Now input IP of CDN Management : "
read OpenCDN_Manage_IP
IS_64=`uname -a | grep "x86_64"`
if [ -z "${IS_64}" ]
then
CPU_ARC="i386"
else
CPU_ARC="x86_64"
fi
IS_5=`cat /etc/redhat-release | grep "5.[0-9]"`
if [ -z "${IS_5}" ]
then
VER="6"
rpm_ver="epel-release-6-8.noarch.rpm"
sed -i "1 i\@version:3.2" syslog-ng.conf
else
VER="5"
rpm_ver="epel-release-5-4.noarch.rpm"
fi
setenforce 0
rpm -ivh "http://dl.fedoraproject.org/pub/epel/${VER}/${CPU_ARC}/${rpm_ver}"
}
get_system_basic_info
killd_server
OPENCDN_LOG_PATH="/var/log/opencdn"
OPENCDN_EXEC_PATH="/usr/local/opencdn/sbin"
OPENCDN_CONF_PATH="/usr/local/opencdn/conf"
OPENCDN_PIPE_PATH="/usr/local/opencdn/pipe"
OPENCDN_CONF_FILE="/usr/local/opencdn/conf/opencdn.conf"
mkdir -p ${OPENCDN_LOG_PATH}
mkdir -p ${OPENCDN_EXEC_PATH}
mkdir -p ${OPENCDN_CONF_PATH}
mkdir -p ${OPENCDN_PIPE_PATH}
access_log="${OPENCDN_PIPE_PATH}/access.pipe"
rm -f $access_log
mkfifo ${access_log}
if [ ! -p "${access_log}" ]
then
echo "create ${access_log} failured!!!"
exit 1;
fi
sys_fifo="${OPENCDN_PIPE_PATH}/sys_info.pipe"
rm -f $sys_fifo
mkfifo $sys_fifo
if [ ! -p "${sys_fifo}" ]
then
echo "create ${sys_fifo} failured!!!"
exit 1;
fi
mv ${OLD_DIR}/opencdn.conf ${OPENCDN_CONF_PATH}
OLD_DIR=`pwd`
sed -i "s/localhost/$OpenCDN_Manage_IP/g" ${OPENCDN_CONF_PATH}/opencdn.conf
echo "===========================nginx install start===================================="
sed -i 's/^exclude/#exclude/' /etc/yum.conf && yum -y install gcc && sed -i 's/^#exclude/exclude/' /etc/yum.conf
yum -y install gcc gcc-c++ autoconf automake make
yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel
yum -y install bc
mv ${OLD_DIR}/nginx.txt /tmp/
mv -f ${OLD_DIR}/conf /tmp/
cd /tmp
wget http://nginx.org/download/nginx-1.2.0.tar.gz
if [ $? -eq 0 ]
then
tar -zxvf nginx-1.2.0.tar.gz
rm -f nginx-1.2.0.tar.gz
else
echo "Downloading http://nginx.org/download/nginx-1.2.0.tar.gz failured !!!"
exit 1
fi
wget http://labs.frickle.com/files/ngx_cache_purge-1.6.tar.gz
if [ $? -eq 0 ]
then
tar -zxvf ngx_cache_purge-1.6.tar.gz
rm -f ngx_cache_purge-1.6.tar.gz
else
echo "Downloading http://labs.frickle.com/files/ngx_cache_purge-1.3.tar.gz failured !!!"
exit 1
fi
wget http://webserver.googlecode.com/files/pcre-8.10.tar.gz
if [ $? -eq 0 ]
then
tar -zxvf pcre-8.10.tar.gz
rm -f pcre-8.10.tar.gz
else
echo "Downloading http://webserver.googlecode.com/files/pcre-8.10.tar.gz failured !!!"
exit 1
fi
wget http://mingw-lib.googlecode.com/files/openssl-1.0.0c.tar.gz
if [ $? -eq 0 ]
then
tar -zxvf openssl-1.0.0c.tar.gz
rm -f openssl-1.0.0c.tar.gz
else
echo "Downloading http://mingw-lib.googlecode.com/files/openssl-1.0.0c.tar.gz failured !!!"
exit 1
fi
if [ "${CPU_ARC}" == "x86_64" ]
then
wget http://fastlnmp.googlecode.com/files/libunwind-0.99-alpha.tar.gz
tar zxvf libunwind-0.99-alpha.tar.gz
cd libunwind-0.99-alpha/
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install
fi
wget http://gperftools.googlecode.com/files/gperftools-2.0.tar.gz
if [ $? -eq 0 ]
then
tar -zxvf gperftools-2.0.tar.gz
rm -f gperftools-2.0.tar.gz
else
echo "https://gperftools.googlecode.com/files/gperftools-2.0.tar.gz failured !!!"
exit 1
fi
pushd gperftools-2.0
./configure --prefix=/usr
make&&make install
popd
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig
mkdir /tmp/tcmalloc
chmod 0777 /tmp/tcmalloc
mkdir /usr/local/nginx
cd /usr/local/nginx
## change file before compile
sed -i 's/\"nginx/\"OpenCDN Beta/i' /tmp/nginx-1.2.0/src/core/nginx.hi
sed 's/>nginx</>OpenCDN Beta</' -i /tmp/nginx-1.2.0/src/http/ngx_http_special_response.c
sed -i 's/\" NGINX_VER \"/OpenCDN beta/' /tmp/ngx_cache_purge-1.6/ngx_cache_purge_module.c
## complie nginx with new args
groupadd www
useradd -g www -s /bin/false -M www
pushd /tmp/nginx-1.2.0
./configure --user=www --group=www --prefix=/usr/local/nginx --with-pcre=../pcre-8.10 --with-openssl=../openssl-1.0.0c --add-module=../ngx_cache_purge-1.6 --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --without-mail_pop3_module --without-mail_smtp_module --without-mail_imap_module --without-http_uwsgi_module --without-http_scgi_module --with-google_perftools_module
make && make install
if [ $? -ne 0 ];then
echo "error"
exit 1
fi
popd
#set auto start scripts
mv /tmp/nginx.txt /etc/init.d/nginx
chmod u+x /etc/init.d/nginx
rm -rf /usr/local/nginx/conf
mv -f /tmp/conf /usr/local/nginx/
chkconfig --add nginx
chkconfig --level 345 nginx on
chkconfig --list nginx
#service nginx start
## Create cache and temp
mkdir /home/cache/
#mkdir /home/logs/
mkdir /home/temp/
## Set the provilige of cache
chown www.www -R /home/cache /home/temp
chmod -R 777 /home/cache /home/temp
echo "===========================nginx install completed===================================="
echo "===========================rsync install start========================================"
yum -y remove rsync
yum -y install rsync
cd ${OLD_DIR}
if [ ! -f "./inotify-tools-3.14.tar.gz" ]
then
wget http://pkgs.fedoraproject.org/repo/pkgs/inotify-tools/inotify-tools-3.14.tar.gz/b43d95a0fa8c45f8bab3aec9672cf30c/inotify-tools-3.14.tar.gz
fi
tar zxvf inotify-tools-3.14.tar.gz
rm -rf inotify-tools-3.14.tar.gz
pushd inotify-tools-3.14
./configure && make && make install
popd
ln -sv /usr/local/lib/libinotify* /usr/lib/
ln -s /usr/local/lib/libinotifytools.so.0 /usr/lib64/libinotifytools.so.0
echo "ocdn:ocdn.me" >/etc/rsyncd.pwd
chmod 600 /etc/rsyncd.pwd
USER=ocdn
PASSWD=ocdn.me
cd ${OLD_DIR}
mv -f ${OLD_DIR}/rsyncd.conf /etc/rsyncd.conf
sed "s/0\.0\.0\.0/$OpenCDN_Manage_IP/g" -i /etc/rsyncd.conf
#echo "/usr/bin/rsync --daemon" >> /etc/rc.d/rc.local
echo "===========================rsync install completed===================================="
mv /etc/init.d/iptables /etc/init.d/iptables.bak
rm -f /etc/sysconfig/iptables
rm -f /etc/init.d/iptables
mv -f ${OLD_DIR}/iptables_start /etc/init.d/iptables
chmod u+x /etc/init.d/iptables
mv -f ${OLD_DIR}/iptables.conf /etc/sysconfig/iptables
service iptables restart
mv -f ${OLD_DIR}/nginxmon /usr/local/nginx/sbin/ -f
chmod u+x /usr/local/nginx/sbin/nginxmon
echo "nohup /bin/bash /usr/local/nginx/sbin/nginxmon > ${OPENCDN_LOG_PATH}/nginxmon.log 2>&1 &" >> /etc/rc.d/rc.local
nohup /bin/bash /usr/local/nginx/sbin/nginxmon &> ${OPENCDN_LOG_PATH}/nginxmon.log 2>&1 &
mv -f ${OLD_DIR}/send_info ${OPENCDN_EXEC_PATH}
chmod u+x ${OPENCDN_EXEC_PATH}/send_info
echo "===========================syslog install start===================================="
yum -y remove syslog-ng
yum -y remove syslog*
yum -y install syslog-ng
cd ${OLD_DIR}
mv /etc/syslog-ng/syslog-ng.conf /etc/syslog-ng/syslog-ng.conf.bak
sed -i "s/0\.0\.0\.0/$OpenCDN_Manage_IP/g" syslog-ng.conf
mv -f ${OLD_DIR}/syslog-ng.conf /etc/syslog-ng/syslog-ng.conf
chkconfig syslog-ng on
service syslog-ng start > /dev/null 2>&1
service nginx start
echo "===========================syslog install completed===================================="
chmod 777 ${OLD_DIR}/opencdn
mv -f ${OLD_DIR}/opencdn /etc/init.d/
chkconfig --add opencdn
service opencdn restart
echo "==========================OpenCDN===================================="
echo "* *"
echo "*service opencdn [start|stop|restart|status] *"
echo "*sys_info log path : /var/log/opencdn/send_info.log *"
echo "* *"
echo "==========================OpenCDN===================================="
## Clean source file
cd /tmp
rm -rf gperftools-2.0 nginx-1.2.0 ngx_cache_purge-1.6 openssl-1.0.0c pcre-8.10 nginx.txt *.tar.gz inotify-tools-3.14 ${OLD_DIR}/ocdn_node/
cd ${OLD_DIR}
rm -rf inotify-tools* iptables install.sh