forked from sanvu88/lempstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
187 lines (161 loc) · 5.8 KB
/
install
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
#!/bin/bash
######################################################################
# Auto Install & Optimize LEMP Stack on CentOS 7, 8 #
# #
# Author: Sanvv - HOSTVN Technical #
# Website: https://hostvn.vn #
# #
# Please do not remove copyright. Thank! #
# Please do not copy under any circumstance for commercial reason! #
######################################################################
# Set link
SCRIPT_LINK="https://scripts.hostvn.net"
# VPS Info
OS_VER=$(rpm -E %centos)
RAM_TOTAL=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
LOW_RAM='400000'
# Control Panel path
CPANEL="/usr/local/cpanel/cpanel"
DIRECTADMIN="/usr/local/directadmin/custombuild/build"
PLESK="/usr/local/psa/version"
WEBMIN="/etc/init.d/webmin"
SENTORA="/root/passwords.txt"
HOCVPS="/etc/hocvps/scripts.conf"
VPSSIM="/home/vpssim.conf"
EEV3="/usr/local/bin/ee"
WORDOPS="/usr/local/bin/wo"
KUSANAGI="/home/kusanagi"
CWP="/usr/local/cwpsrv"
VESTA="/usr/local/vesta/"
EEV4="/opt/easyengine"
LARVPS="/etc/larvps/.info.conf"
TINO="/opt/tinopanel"
# Set Lang
ROOT_ERR="Ban can chay script voi user root. Chay lenh \"sudo su\" de co quyen root!"
CANCEL_INSTALL="Huy cai dat..."
OS_WRONG="Script chi hoat dong tren \"CentOS 7\" va \"CentOS 8\"!"
RAM_NOT_ENOUGH="Canh bao: Dung luong RAM qua thap de cai Script. (it nhat 512MB)"
OTHER_CP_EXISTS="May chu cua ban da cai dat Control Panel khac. Vui long rebuild de cai dat Script."
HOSTVN_EXISTS="May chu cua ban da cai dat HOSTVN Script. Vui long rebuild neu muon cai dat lai."
# Set Color
RED='\033[0;31m'
NC='\033[0m'
welcome(){
clear
printf "========================================================\n"
echo " HOSTVN.VN Scripts "
echo " Auto Install & Optimize LEMP Stack on CentOS 7, 8 "
printf " Neu can ho tro vui long lien he %s\n" "[email protected]"
printf "========================================================\n"
echo ""
echo "Chuan bi cai dat..."
sleep 3
}
###################
#Check conditions #
###################
# Check if user not root
check_root(){
if [[ "$(id -u)" != "0" ]]; then
printf "${RED}%s${NC}\n" "${ROOT_ERR}"
printf "${RED}%s${NC}\n" "${CANCEL_INSTALL}"
exit
fi
}
# Check if not enough ram
check_low_ram(){
if [[ ${RAM_TOTAL} -lt ${LOW_RAM} ]]; then
printf "${RED}%s${NC}\n" "${RAM_NOT_ENOUGH}"
printf "${RED}%s${NC}\n" "${CANCEL_INSTALL}"
exit
fi
}
# Check if other Control Panel has installed before
check_control_panel(){
if [[ -f "${CPANEL}" || -f "${DIRECTADMIN}" || -f "${PLESK}" || -f "${WEBMIN}" || -f "${SENTORA}" || -f "${HOCVPS}" || -f "${LARVPS}" ]]; then
printf "${RED}%s${NC}\n" "${OTHER_CP_EXISTS}"
printf "${RED}%s${NC}\n" "${CANCEL_INSTALL}"
exit
fi
if [[ -f "${VPSSIM}" || -f "${WORDOPS}" || -f "${EEV3}" || -d "${EEV4}" || -d "${VESTA}" || -d "${CWP}" || -d "${KUSANAGI}" || -d "${TINO}" ]]; then
printf "${RED}%s${NC}\n" "${OTHER_CP_EXISTS}"
printf "${RED}%s${NC}\n" "${CANCEL_INSTALL}"
exit
fi
if [[ -f "/etc/hostvn.lock" ]]; then
printf "${RED}%s${NC}\n" "${HOSTVN_EXISTS}"
printf "${RED}%s${NC}\n" "${CANCEL_INSTALL}"
exit
fi
}
check_before_install(){
echo ""
check_root
check_low_ram
check_control_panel
}
###################
# Prepare Install #
###################
# Remove unnecessary services
remove_old_ervice(){
yum -y remove mysql* php* httpd* sendmail* postfix* rsyslog* nginx*
yum clean all
}
# Install requirement service
install_repo(){
if [[ "${OS_VER}" -eq 8 ]]; then
dnf -y install epel-release -y
dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
dnf -y install hostname libsepol boost-program-options libmemcached libmemcached-devel
elif [ "${OS_VER}" -eq 7 ]; then
yum -y install epel-release ntpdate libmemcached libmemcached-devel
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
else
printf "${RED}${OS_WRONG}${NC}\n"
sleep 2
exit
fi
}
install_requirement(){
yum -y install gawk bc wget tar gcc gcc-c++ flex bison make bind bind-libs bind-utils dos2unix openssl openssl-devel perl quota libaio \
libcom_err-devel libcurl-devel gd jpegoptim zlib-devel zip unzip libcap-devel cronie bzip2 cyrus-sasl-devel perl-ExtUtils-Embed logrotate \
autoconf automake libtool which patch mailx bzip2-devel lsof glibc-headers kernel-devel expat-devel nano htop git syslog-ng syslog-ng-libdbi \
psmisc net-tools systemd-devel libdb-devel perl-DBI pngquant libpng-devel xfsprogs rsyslog crontabs file kernel-headers
}
create_swap(){
swap="$(swapon -s)"
if [[ -z "${swap}" && ${RAM_TOTAL} -le 2099152 ]]; then
read -r -p "Ban co muon tao swap hay khong ? (y/n)" confirm_swap
fi
if [[ $confirm_swap == "y" || $confirm_swap == "Y" ]]; then
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile none swap sw 0 0" >> /etc/fstab
fi
}
disable_firewalld(){
systemctl stop firewalld
systemctl disable firewalld
}
set_locale(){
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
}
#########################
#Dowload primary Script #
#########################
dowload_script(){
curl -sO ${SCRIPT_LINK}/hostvn && dos2unix hostvn &> /dev/null && chmod +x hostvn && sh hostvn
}
welcome
check_before_install
remove_old_ervice
install_repo
install_requirement
create_swap
disable_firewalld
set_locale
dowload_script