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
|
#!/bin/bash
#date:2014-8-31
#blog:lizhenliang.blog.51cto.com
########## function ##########
depend_pkg ()
{
yum install gcc gcc-c++ make cmake ncurses-devel libxml2-devel \
perl-devel libcurl-devel libgcrypt libgcrypt-devel libxslt \
libxslt-devel pcre-devel openssl-devel wget -y
}
cat <<END
1.[ install apache2.4]
2.[ install mysql5.5]
3.[ install php5.4]
END
read -p "Please input number : " NUM
case $NUM in
1)
########## Install Depend Pkg ##########
depend_pkg;
WorkDIR= /usr/local/src
cd $WorkDIR
[ -f "apr-1.5.1.tar.gz" ] || wget http: //mirror .bit.edu.cn /apache/apr/apr-1 .5.1. tar .gz
[ -f "apr-util-1.5.3.tar.gz" ] || wget http: //mirror .bit.edu.cn /apache/apr/apr-util-1 .5.3. tar .gz
[ -f "httpd-2.4.10.tar.gz" ] || wget http: //mirror .bit.edu.cn /apache/httpd/httpd-2 .4.10. tar .gz
ls | xargs -I file tar zxvf file -C $WorkDIR
cd apr-1.5.1
. /configure --prefix= /usr/local/apr
make && make install
if [ $? - eq 0 ]; then
cd $WorkDIR
cd apr-util-1.5.3
. /configure --prefix= /usr/local/apr-util --with-apr= /usr/local/apr
make && make install
else
echo "------ apr make failed. ------"
exit 1
fi
########## Install Apache ##########
HTTPDIR= /usr/local/apache2 .4
if [ $? - eq 0 ]; then
cd $WorkDIR
cd httpd-2.4.10
. /configure -prefix=$HTTPDIR - enable -so - enable -rewrite - enable -modules=all \
--with-apr= /usr/local/apr --with-apr-util= /usr/local/apr-util
make && make install
else
echo "------ apr-util make failed. ------"
exit 1
fi
if [ $? - eq 0 ]; then
CONF=$HTTPDIR /conf/httpd .conf
cp $HTTPDIR /bin/apachectl /etc/init .d /httpd
chmod +x /etc/init .d /httpd
sed -i "s/#ServerName www.example.com:80/ServerName ${IP}:80/g" $CONF
sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/g' $CONF
sed -i "391 s/^/AddType application\/x-httpd-php .php/" $CONF
/etc/init .d /httpd start
IP=` ifconfig eth0 | grep "inet addr" | cut -d: -f2 | awk '{print $1}' `
Urlcode=`curl -o /dev/null -s -w "%{http_code}" $IP /index .html`
[ $Urlcode - eq 200 ] && echo "Apache install success." || echo "Apache install failed."
else
echo "------ apache make failed. ------"
exit 1
fi
;;
2)
########## Install Depend Pkg ##########
depend_pkg;
########## Install Mysql ##########
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql -s /sbin/nologin mysql
WorkDIR= /usr/local/src
MYSQLDIR= /usr/local/mysql5 .5
cd $WorkDIR
[ -f "mysql-5.5.39.tar.gz" ] || wget http: //cdn .mysql.com /Downloads/MySQL-5 .5 /mysql-5 .5.39. tar .gz
tar zxvf mysql-5.5.39. tar .gz
cd mysql-5.5.39
cmake -DCMAKE_INSTALL_PREFIX=$MYSQLDIR \
-DSYSCONFDIR=$MYSQLDIR /etc \
-DMYSQL_DATADIR=$MYSQLDIR /data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make && make install
if [ $? - eq 0 ]; then
$MYSQLDIR /scripts/mysql_install_db \
--basedir=$MYSQLDIR --datadir=$MYSQLDIR /data/ --user=mysql 1> /dev/null
mkdir $MYSQLDIR /etc
cp support-files /my-medium .cnf $MYSQLDIR /etc/my .cnf
cp support-files /mysql .server /etc/init .d /mysqld
rm -rf /etc/my .cnf
#echo "PATH=$PATH:$MYSQLDIR/bin" >> /etc/profile
#. /etc/profile
chmod +x /etc/init .d /mysqld
chown -R root.mysql $MYSQLDIR
chown -R mysql.mysql $MYSQLDIR /data/
$MYSQLDIR /bin/mysqld_safe --user=mysql&
$MYSQLDIR /bin/mysqladmin -u root password '123.com'
$MYSQLDIR /bin/mysql -uroot -p '123.com' -e "show databases;"
[ $? - eq 0 ] && echo "MySQL install success." || echo "MySQL install failed."
else
echo "------mysql cmake failed.------"
exit 1
fi
;;
3)
########## Install Depend Pkg ##########
depend_pkg;
########## Install GD ##########
yum install gd freetype freetype-devel libpng libpng-devel zlib zlib-devel libjpeg* -y
########## Install PHP ##########
WorkDIR= /usr/local/src
PHPDIR= /usr/local/php5 .4
PHPCONF=$PHPDIR /etc/php .ini
cd $WorkDIR
[ -f "php-5.4.31.tar.gz" ] || wget http: //cn2 .php.net /distributions/php-5 .4.31. tar .gz
tar zxvf php-5.4.31. tar .gz
cd php-5.4.31
. /configure -prefix=$PHPDIR \
--with-config- file -path=$PHPDIR /etc \
--with-apxs2= /usr/local/apache2 .4 /bin/apxs \
--with-mysql= /usr/local/mysql5 .5 \
--with-mysqli= /usr/local/mysql5 .5 /bin/mysql_config \
-- enable -soap -- enable -bcmath -- enable -zip -- enable - ftp \
-- enable -mbstring --with-gd --with-libxml- dir --with-jpeg- dir \
--with-png- dir --with-freetype- dir --with-zlib \
--with-libxml- dir = /usr --with-curl --with-xsl --with-openssl
make && make install
if [ $? - eq 0 ]; then
cp php.ini-production $PHPCONF
echo "data.timezone = Asia\Shanghai" >> $PHPCONF
sed -i 's/upload_max_filesize = 2M/ upload_max_filesize = 50M/g' $PHPCONF
sed -i 's/display_errors = Off/display_errors = On/g' $PHPCONF
echo "<?php phpinfo();?>" > /usr/local/apache2 .4 /htdocs/index .php
/etc/init .d /httpd restart
/etc/init .d /mysqld restart &> /dev/null
IP=` ifconfig eth0 | grep "inet addr" | cut -d: -f2 | awk '{print $1}' `
Urlcode=`curl -o /dev/null -s -w "%{http_code}" $IP /index .php`
[ $Urlcode - eq 200 ] && echo "PHP install success." || echo "PHP install failed."
echo "/usr/local/apache/bin/apachectl start" >> /etc/rc . local
chkconfig mysqld on
else
echo "------ php make failed. ------"
exit 1
fi
;;
*)
echo "Please input number 1 2 3."
esac
|
使用方法:
Shell脚本能力薄弱,有错误之处,还望指正。谢谢!
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/109039.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...