-
Notifications
You must be signed in to change notification settings - Fork 31
/
wp_manual.sh
271 lines (248 loc) · 7.17 KB
/
wp_manual.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
#!/bin/bash
function blue(){
echo -e "\033[34m\033[01m$1\033[0m"
}
function green(){
echo -e "\033[32m\033[01m$1\033[0m"
}
function red(){
echo -e "\033[31m\033[01m$1\033[0m"
}
function yellow(){
echo -e "\033[33m\033[01m$1\033[0m"
}
function bred(){
echo -e "\033[31m\033[01m\033[05m$1\033[0m"
}
function byellow(){
echo -e "\033[33m\033[01m\033[05m$1\033[0m"
}
#判断系统
check_os(){
if [ ! -e '/etc/redhat-release' ]; then
red "==============="
red " 仅支持CentOS7"
red "==============="
exit
fi
if [ -n "$(grep ' 6\.' /etc/redhat-release)" ] ;then
red "==============="
red " 仅支持CentOS7"
red "==============="
exit
fi
if [ -n "$(grep ' 8\.' /etc/redhat-release)" ] ;then
red "==============="
red " 仅支持CentOS7"
red "==============="
exit
fi
}
disable_selinux(){
yum -y install net-tools socat
Port80=`netstat -tlpn | awk -F '[: ]+' '$1=="tcp"{print $5}' | grep -w 80`
Port443=`netstat -tlpn | awk -F '[: ]+' '$1=="tcp"{print $5}' | grep -w 443`
if [ -n "$Port80" ]; then
process80=`netstat -tlpn | awk -F '[: ]+' '$5=="80"{print $9}'`
red "==========================================================="
red "检测到80端口被占用,占用进程为:${process80},本次安装结束"
red "==========================================================="
exit 1
fi
if [ -n "$Port443" ]; then
process443=`netstat -tlpn | awk -F '[: ]+' '$5=="443"{print $9}'`
red "============================================================="
red "检测到443端口被占用,占用进程为:${process443},本次安装结束"
red "============================================================="
exit 1
fi
if [ -f "/etc/selinux/config" ]; then
CHECK=$(grep SELINUX= /etc/selinux/config | grep -v "#")
if [ "$CHECK" != "SELINUX=disabled" ]; then
green "检测到SELinux开启状态,添加放行80/443端口规则"
yum install -y policycoreutils-python >/dev/null 2>&1
semanage port -m -t http_port_t -p tcp 80
semanage port -m -t http_port_t -p tcp 443
fi
fi
firewall_status=`systemctl status firewalld | grep "Active: active"`
if [ -n "$firewall_status" ]; then
green "检测到firewalld开启状态,添加放行80/443端口规则"
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload
fi
}
check_domain(){
download_wp
install_php7
install_mysql
install_nginx
config_php
install_wp
}
install_php7(){
green "==============="
green " 1.安装必要软件"
green "==============="
sleep 1
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget https://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm epel-release-latest-7.noarch.rpm --force --nodeps
#sed -i "0,/enabled=0/s//enabled=1/" /etc/yum.repos.d/epel.repo
yum -y install unzip vim tcl expect curl socat
echo
echo
green "============"
green "2.安装PHP7.4"
green "============"
sleep 1
yum -y install php74 php74-php-gd php74-php-pdo php74-php-mbstring php74-php-cli php74-php-fpm php74-php-mysqlnd
service php74-php-fpm start
chkconfig php74-php-fpm on
if [ `yum list installed | grep php74 | wc -l` -ne 0 ]; then
echo
green "【checked】 PHP7安装成功"
echo
echo
sleep 2
php_status=1
fi
}
install_mysql(){
green "==============="
green " 3.安装MySQL"
green "==============="
sleep 1
#wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
wget https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm --force --nodeps
yum -y install mysql-server
systemctl enable mysqld.service
systemctl start mysqld.service
if [ `yum list installed | grep mysql-community | wc -l` -ne 0 ]; then
green "【checked】 MySQL安装成功"
echo
echo
sleep 2
mysql_status=1
fi
echo
echo
green "==============="
green " 4.配置MySQL"
green "==============="
sleep 2
originpasswd=`cat /var/log/mysqld.log | grep password | head -1 | rev | cut -d ' ' -f 1 | rev`
mysqlpasswd=`mkpasswd -l 18 -d 2 -c 3 -C 4 -s 5 | sed $'s/[\'\"]//g'`
cat > ~/.my.cnf <<EOT
[mysql]
user=root
password="$originpasswd"
EOT
mysql --connect-expired-password -e "alter user 'root'@'localhost' identified by '$mysqlpasswd';"
cat > ~/.my.cnf <<EOT
[mysql]
user=root
password="$mysqlpasswd"
EOT
mysql --connect-expired-password -e "create database wordpress_db;"
}
install_nginx(){
echo
echo
green "==============="
green " 5.安装nginx"
green "==============="
sleep 1
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm --force --nodeps
yum install -y nginx
systemctl enable nginx.service
systemctl stop nginx.service
rm -f /etc/nginx/conf.d/default.conf
rm -f /etc/nginx/nginx.conf
mkdir /etc/nginx/ssl
if [ `yum list installed | grep nginx | wc -l` -ne 0 ]; then
echo
green "【checked】 nginx安装成功"
echo
echo
sleep 1
mysql_status=1
fi
cat > /etc/nginx/nginx.conf <<-EOF
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
'\$status \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 120;
client_max_body_size 20m;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
EOF
}
config_php(){
echo
green "===================="
green " 6.配置php和php-fpm"
green "===================="
echo
echo
sleep 1
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 20M/;" /etc/opt/remi/php74/php.ini
sed -i "s/pm.start_servers = 5/pm.start_servers = 3/;s/pm.min_spare_servers = 5/pm.min_spare_servers = 3/;s/pm.max_spare_servers = 35/pm.max_spare_servers = 8/;" /etc/opt/remi/php74/php-fpm.d/www.conf
systemctl restart php74-php-fpm.service
systemctl restart nginx.service
}
download_wp(){
yum -y install wget
}
install_wp(){
green "==========================="
green " WordPress环境已经安装完成"
green " 数据库密码: $mysqlpasswd"
green "==========================="
}
start_menu(){
clear
green "==============================="
green " 介绍:一键安装wordpress环境"
green " 作者:atrandys"
green " 网站:www.atrandys.com"
green " Youtube:Randy's 堡垒"
green "==============================="
green "1. 一键安装wordpress环境"
yellow "0. 退出脚本"
echo
read -p "请输入数字:" num
case "$num" in
1)
check_os
disable_selinux
check_domain
;;
0)
exit 1
;;
*)
clear
echo "请输入正确数字"
sleep 2s
start_menu
;;
esac
}
start_menu