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
|
#!/bin/bash # mysqld install scripts # display Progress Progress () { b= ''
i=0
while [ $i - le 100 ]
do
printf "$*:[ %-50s ]%d%%\r" $b $i
sleep 0.001
i=` expr 2 + $i`
b= #$b
done
echo
} # if Centos Version Centos_version=$( cat /etc/redhat-release | awk '{print $4}' | cut -b1)
wget -o /dev/null -O /etc/yum .repos.d /Centos-Base .repo /http : //mirrors .aliyun.com /repo/Centos- ${Centos_version}.repo
yum makecache Progress Centos Download sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config ;iptables -F
setenforce 0 rpm -e --nodeps mysql* CPU_NUMBERS=` cat /proc/cpuinfo | grep processor| wc -l`
COMPUTER_MEM=` free -m| grep Mem| awk '{print $2}' `
MYSQL_MEM=` expr $COMPUTER_MEM - $COMPUTER_MEM / 4`
COLOR_GREEN= "\033[32m"
COLOR_RED= "\033[31m"
COLOR_BULE= "\033[34m"
COLOR_YELLOW= "\033[33m"
COLOR_PURPLE= "\033[35m"
COLOR_END= "\033[0m"
sleep 0.05; echo "==================================================" ; echo ; echo
sleep 0.05; echo -e "Mysql 5.7.16 on $COLOR_GREEN Centos7_`uname -m` $COLOR_END"
sleep 0.05; echo -e "Your computer is $COLOR_GREEN $CPU_NUMBERS $COLOR_END processes,Mysql Memory is ${COLOR_GREEN}${MYSQL_MEM}M${COLOR_END}"
sleep 0.05; echo -e "${COLOR_RED}Your will input mysql's root password and mysql's memory${COLOR_END}" ; echo ; echo
sleep 0.05; echo "=================================================="
# are you sure install read -n1 -t30 -p "Are you sure setup[y/n]?: " answer
case $answer in
"y" | "Y" )
echo ; echo "Start setup....." ; sleep 2;;
"n" | "N" )
echo ; echo -e "${COLOR_RED}Cancel setup......${COLOR_END}"
exit 0 ;;
"" )
echo ; echo -e "${COLOR_PURPLE}Over time!!!!!${COLOR_END}"
exit 0 ;;
*)
echo ; echo -e "${COLOR_RED}Error input parameter......${COLOR_END}"
exit 1 ;;
esac # check if user is root if [ $( id -u) != "0" ]; then
echo "$COLOR_RED Sorry:You must be root to run this script!${COLOR_END}"
exit 1
fi # useradd mysql GROUP_NAME=mysql USER_NAME=mysql if [ -z $( cat /etc/passwd | awk -F: "{print $1}" | grep -w "$USER_NAME" ) -a -z $( cat /etc/group | awk -F: "{print $1}" | grep -w "$GROUP_NAME" ) ]
then useradd -s /sbin/nologin -M -U $USER_NAME 2> /dev/null
if (( $? == "0" ))
then
echo -e "$COLOR_GREEN group $GROUP_NAME add sucessfully!${COLOR_END}"
fi
else
echo -e "${COLOR_PURPLE}User $USER_NAME is exsits! ${COLOR_END}"
fi for i in make gcc gcc-c++ bison-devel ncurses-devel perl perl-devel wget
do yum -y -q install $i > /dev/null
echo -e "${COLOR_PURPLE}$i ${COLOR_GREEN}Install ok${COLOR_END}"
done # download cmake >= 2.8 CMAKE_VERSION=cmake-3.4.3 rm -rf /tmp/cmake *
if [ -z $( which cmake) ]
then wget -c --no-check-certificate -q https: //cmake .org /files/v3 .4/${CMAKE_VERSION}. tar .gz -P /tmp
if [ $? == "0" ]
then
Progress Cmake Download
echo -e "${COLOR_GREEN}Cmake Download sucessfully!${COLOR_END}"
else
echo -e "${COLOR_RED}Cmake Download failed!${COLOR_END}"
exit 0
fi
tar -zxf /tmp/ ${CMAKE_VERSION}. tar .gz -C /tmp/ > /dev/null
cd /tmp/ ${CMAKE_VERSION}
. /bootstrap > /dev/null
make && make install
echo $?
else echo -e "${COLOR_PURPLE}Cmake is exsits ${COLOR_END}"
fi # download boost_1.61 BOOST_VERSION=1.61.0 BOOST_VER= "boost_1_61_0"
for i in bzip2 gcc bzip2 -devel bzip2 -libs python-devel perl-Data-Dumper
do yum install -q -y $i > /dev/null
echo -e "${COLOR_PURPLE}$i ${COLOR_GREEN}install OK${COLOR_END}"
done wget -c --no-check-certificate -q https: //nchc .dl.sourceforge.net /project/boost/boost/ ${BOOST_VERSION}/${BOOST_VER}. tar .bz2 -P /tmp
if [ $? == "0" ]
then Progress Boost Download
echo -e "${COLOR_GREEN}Boost Download sucessfully!${COLOR_END}"
echo -e "${COLOR_GREEN}Decompression ${BOOST_VER}.tar.bz2${COLOR_END}"
cd /tmp ; tar -jxf ${BOOST_VER}. tar .bz2
cd ${BOOST_VER}
echo ` pwd `
. /bootstrap .sh 2> /dev/null
. /b2 install 2> /dev/null
else echo -e "${COLOR_RED}Boost Download failed!${COLOR_END}"
exit 0
fi # Download mysql rm -rf /tmp/mysql-5 .*
MYSQL_VERSION=5.6.35 wget -c http: //mirrors .sohu.com /mysql/MySQL-5 .6 /mysql- ${MYSQL_VERSION}. tar .gz -P /tmp
if [ $? == "0" ]
then echo -e "${COLOR_PURPLE}Mysql ${MYSQL_VERSION}${COLOR_GRENN}Download sucessfully!${COLOR_END}"
else echo -e "${COLOR_PURPLE}Mysql ${MYSQL_VERSION}${COLOR_RED}Download failed!${COLOR_END}"
fi cd /tmp/
tar -zxf /tmp/mysql- ${MYSQL_VERSION}. tar .gz
cd mysql-${MYSQL_VERSION}
if [ -f /etc/my .cnf ]
then mv /etc/my .cnf /etc/my .cnf__$( date +%Y%m%d).bak
fi echo "======================================================"
echo -e "Please input the root password of mysql: "
read -p "(Default password:root):" MYSQL_PASSWD
if [ $mysqlrootpw == "" ]; then
MYSQL_PASSWD= "root"
fi echo "Mysql root's password is ${mysqlrootpw}"
echo -e "${COLOR_PURPLE}Please input Mysql Basedir: ${COLOR_END}"
read -p "(Default Mysql Basedir:/usr/local/mysql/)" MYSQL_HOME
if [ -z $MYSQL_HOME ]; then
MYSQL_HOME= "/usr/local/mysql"
fi read -p "(Default Mysql Datadir:/usr/local/mysql/data)" MYSQLDB_HOME
if [ -z $MYSQLDB_HOME ]; then
MYSQLDB_HOME= "/usr/local/mysql/data"
fi echo "======================================================="
cmake \ -DCMAKE_INSTALL_PREFIX=${MYSQL_HOME}-${MYSQL_VERSION} \ -DMYSQL_DATADIR=${MYSQLDB_HOME} \ -DSYSCONFDIR= /etc \
-DWITH_BOOST= /usr/local/include/boost \
-DWITH_MYISAM_STORAGE_ENGINE=1 \ -DMYSQL_TCP_PORT=3306 \ -DDEFAULT_CHARSET=utf8 \ -DMYSQL_USER=mysql \ -DEXTRA_CHARSETS=all \ -DENABLED_LOCAL_INFILE=1 \ -DDEFAULT_COLLATION=utf8_general_ci make -j${CPU_NUMBERS} && make install
ln -s ${MYSQL_HOME}-${MYSQL_VERSION} ${MYSQL_HOME}
cp ${MYSQL_HOME} /support-files/my-default .cnf /etc/my .cnf
mkdir -p ${MYSQLDB_HOME} /log
chown -R mysql:mysql ${MYSQL_HOME}
chown -R mysql:mysql ${MYSQLDB_HOME}
cd ${MYSQL_HOME}; chmod +x . /scripts/mysql_install_db
${MYSQL_HOME} /scripts/mysql_install_db --user=mysql --basedir=${MYSQL_HOME} --datadir=${MYSQLDB_HOME}
cat >> /etc/profile <<EOF
PATH=\$PATH:${MYSQL_HOME} /bin
export PATH
EOF source /etc/profile
${MYSQL_HOME} /support-files/mysql .server start
if [ $? == "0" ]
then echo "Setup successfully!enjoy it...."
source /etc/profile
else echo "Mysql start failed"
fi |
本文转自 运维小学生 51CTO博客,原文链接:http://blog.51cto.com/yasar/1913033,如需转载请自行联系原作者