-
Notifications
You must be signed in to change notification settings - Fork 14
/
install.sh
321 lines (245 loc) · 8.24 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
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
#!/bin/sh
# centos安装,若有/home/html目录,请先备份。
# mkfs -t ext3 /dev/sdb1; mount /dev/sdb1 /home; echo '/dev/sdb1 /home ext4 defaults 1 2' >> /etc/fstab
# http://dev.mysql.com/downloads/repo/yum/
# /usr/sbin/ntpdate -u pool.ntp.org && /sbin/hwclock -w
. "/root/centos/fun.sh"
if [ $(id -u) != "0" ]; then
red "Error: You must be root to run this script."
exit 1
fi
green '查看已安装WEB环境'
rpm -q php php-fpm mysql nginx httpd pure-ftpd redis memcache memcached
if [ "$1" = 'un' ]; then
read -p "是否卸载httpd,php,mysql pure-ftpd nginx [y] " uninstall
if [ "$uninstall" = 'y' ]; then
green "开始卸载httpd,php,mysql pure-ftpd nginx redis------------------------------"
service mysqld stop;
service nginx stop;
service pure-ftpd stop;
service php-fpm stop;
service redis stop;
service memcached stop;
yum remove "php*" mysql "httpd*" pure-ftpd nginx "redis*" "memcache*"
rm -rf /var/log/mysqld.log /var/log/mysqld.log.rpmsave /etc/my.cnf.rpmsave /etc/php.ini.rpmsave
rm -rf /etc/nginx /etc/pure-ftpd
cp -a /var/lib/mysql /root
fi
exit;
fi
issue='/etc/redhat-release'
if [ ! -f "$issue" ]; then
red '${issue}不存在'
exit;
fi
iscent=$(egrep -io 'centos' $issue)
if [ -z "$iscent" ]; then
red '你的操作系统不是CentOS'
exit;
fi
version=$(grep -Eo 'release [0-9]' $issue | cut -d' ' -f2)
bit=$(getconf LONG_BIT)
purple "你的CentOS版本是${version}, ${bit}位"
read -p "是否退出 [Y/N] " answer
if [ "$answer" = 'y' -o "$answer" = 'Y' ]; then
exit
fi
cd /root
if [ ! -f '1.bashrc' ]; then
mv .bashrc 1.bashrc &> /dev/null
cp centos/0.bashrc .bashrc
chmod 0644 /root/.bashrc
source /root/.bashrc
fi
check_disk
setenforce 0
sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config
chmod +x /root/centos/*.sh
which wget &> /dev/null || yum install wget
which curl &> /dev/null || yum install curl
id www &> /dev/null
if [ $? != 0 ]; then
yellow "添加www用户"
useradd -s /sbin/nologin www
[ -d '/home/www/' ] || mkdir /home/www/
chmod 755 /home/www
rm -f /home/www/.bash*
fi
#################################### yum源配置
/root/centos/0yum.sh
#################################### 删除原来的/home/html
if [ ! -d /home/html ]; then
green "创建目录/home/html"
mkdir -p /home/html
cd /home/html
cp /root/centos/010pinfo.php .
cp /root/centos/ocp22.php .
unzip /root/centos/phpmyadmin.zip -d . > /dev/null
mv phpmyadmin pan113
chown -R www.www /home/html
find /home/html -type f -exec chmod 644 {} \;
mkdir 0aa
cd 0aa
cp ../010pinfo.php .
echo 123 > test.html;
fi
if [ "${version}" -gt 6 -a ! -e /root/iptables ]; then
yellow "关闭firewall"
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state
yellow "启动iptables"
systemctl start iptables.service
systemctl enable iptables.service
fi
curl ip.cn
IP=`curl -s ipv4.icanhazip.com`
[ -z "$IP" ] && IP=$(ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}')
mysql_root_password=$(egrep '^pwd=.+' /root/centos/dber.sh | cut -d= -f2)
Memtatol=`free -m | grep 'Mem:' | awk '{print $2}'`
Swap=`free -m | awk '/Swap:/{print $2}'`
cups=$(cat /proc/cpuinfo | grep "processor" | wc -l)
green "CPU个数是 $cups"
green "交换分区大小是 $Swap"
[ -f '/root/centos/swap.sh' ] && /root/centos/swap.sh
#################################### 更改ssh端口
/root/centos/0ssh_port.sh
read -p "是否配置rsync [Y/N] " rsyncyn
read -p "是否安装mysql [Y/N] " mysqlyn
read -p "是否安装pure-ftpd [Y/N] " ftpyn
read -p "是否安装nginx [Y/N] " nginxyn
yellow "1. php-5.3"
yellow "2. php-5.6"
yellow "3. php-7.2"
read -p "请选择要安装的php-fpm版本:" PHP_version
case $PHP_version in
1)
arepo=base
;;
2)
arepo=remi-php56
;;
3)
arepo=remi-php72
;;
*)
arepo=remi-php71
;;
esac
read -p "是否安装redis [Y/N] " redisyn
read -p "是否安装memcached [Y/N] " memcachedyn
read -p "是否优化sysctl.conf [Y/N] " sysanswer
##################################### php-fpm php5.3以上支持mysqlnd
if [ -n "$arepo" ]; then
/root/centos/0php.sh $arepo
fi
##################################### nginx
if [ "$nginxyn" = 'y' -o "$nginxyn" = 'Y' ]; then
/root/centos/0nginx.sh
fi
##################################### rsync
if [ "$rsyncyn" = 'y' -o "$rsyncyn" = 'Y' ]; then
/root/centos/0rsync.sh
fi
##################################### mysql
if [ "$mysqlyn" = 'y' -o "$mysqlyn" = 'Y' ]; then
/root/centos/0mysql57.sh
fi
##################################### pure-ftpd
if [ "$ftpyn" = 'y' -o "$ftpyn" = 'Y' ]; then
/root/centos/0pureftp.sh
fi
if [ "$redisyn" = 'y' -o "$redisyn" = 'Y' ]; then
/root/centos/0redis.sh $arepo
if [ ! -e "/home/html/prz22" ]; then
cd /home/html
unzip /root/centos/phpRedisAdmin.zip -d .
mv phpRedisAdmin prz22
chown -R www.www prz22
find prz22 -type f | xargs -i chmod 644 {}
fi
fi
if [ "$memcachedyn" = 'y' -o "$memcachedyn" = 'Y' ]; then
/root/centos/0memcache.sh $arepo
fi
if [ "$sysanswer" = 'y' -o "$sysanswer" = 'Y' ]; then
/root/centos/sysctl6.sh
fi
if [ -f '/etc/init.d/yum-updatesd' ]; then
service yum-updatesd stop
chkconfig yum-updatesd off
fi
if ! grep -q '* hard nofile 65535' /etc/security/limits.conf; then
ulimit -n 65535
cat >> /etc/security/limits.conf <<EOF
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF
fi
purple ++-----------------------------------------------------++
if [ "${version}" -gt 6 ]; then
systemctl list-unit-files|egrep -i 'php-fpm|mysqld|pure-ftpd|nginx|crond|iptables|redis|memcache'
else
chkconfig --list | egrep -i 'php-fpm|mysqld|pure-ftpd|nginx|crond|iptables|redis|memcache'
fi
[ -f '/usr/share/zoneinfo/Asia/Shanghai' ] && ln -svf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
red ++-----------------------------------------------------++
crontab -l
red ++-----------------------------------------------------++
echo "open files: `ulimit -n`, max user processes: `ulimit -u`"
red ++-----------------------------------------------------++
green "内存的使用率和剩余率"
free -m | grep "buffers/cache"
red ++-----------------------------------------------------++
blue "mysql root密码 $mysql_root_password"
echo "${IP}/pan113"
echo "${IP}/prz22"
echo "${IP}/010pinfo.php"
purple ++-----------------------------------------------------++
green "压力测试"
echo "ab -H 'Accept-Encoding: gzip' -n1000000 -kc10000 ${IP}/010pinfo.php"
purple ++-----------------------------------------------------++
green "检测nginx配置"
curl -A 'apachebench' -o /dev/null -s -w %{http_code} 127.0.0.1/010pinfo.php
curl -A 'java/' -o /dev/null -s -w %{http_code} 127.0.0.1/010pinfo.php
curl -o /dev/null -s -w %{http_code} -I 127.0.0.1/attachment/aa.php
curl -o /dev/null -s -w %{http_code} -I 127.0.0.1/aaaa/upload/aa.php
curl -o /dev/null -s -w %{http_code} -I 127.0.0.1/00/aa.sql
curl -o /dev/null -s -w %{http_code} -I 127.0.0.1/123.conf
echo;
purple ++-----------------------------------------------------++
yellow "nginx错误日志 /var/log/nginx/error.log"
yellow "php-fpm错误日志 /var/log/php-fpm/phperror.log"
yellow "php-fpm慢日志 /var/log/php-fpm/phpslow.log"
yellow "mysql慢日志 /var/log/mysqlslow.log"
yellow "mysql错误日志 /var/log/mysqld.log"
purple ++-----------------------------------------------------++
green "正在更新locate数据库"
updatedb
sync
purple "别忘了reboot,删除安装文件"
# curl 127.0.0.1/nginx_status; curl 127.0.0.1/phpfpm_status
# ab -H 'Accept-Encoding: gzip' -n1000000 -kc10000 ${IP}/010pinfo.php
#echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
#echo "当前的mta是:"
#alternatives --display mta
# echo 'This is a test mail!' | mail -s 'text' [email protected]
#/usr/bin/mysql_secure_installation
# Set DNS 国内服务器用223.5.5.5和114.114.114.114
#cat > /etc/resolv.conf << EOF
#nameserver 223.5.5.5
#nameserver 114.114.114.114
#nameserver 8.8.8.8
#EOF
# Set timezone
# ln -svf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# ntpdate time.nist.gov
# 0 */2 * * * root /usr/sbin/ntpdate -u pool.ntp.org && /sbin/hwclock -w
# iftop -h 查看帮助
# iftop 进入界面按3可按流量大小排序
# > np3
# wget -qO- bench.sh | bash
# 列出前15个最耗内存的进程
# ps aux --sort -rss | head -n15