lnmp 编译安装脚本

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
#!/bin/bash
#########################################################
#by:kingle #
#use: fast lnmp #
#version:1.0 #
#php:php-7.2.8 #
#nginx: 1.15.1 #
#mysql:5.6.41 #
#cenos: 2.6.32-754.2.1.el6.x86_64 #
#########################################################
dir=/root/opt
nginx_install_dir="/lnmp/nginx"
mysql_install_dir="/lnmp/mysql"
php_install_path="/lnmp/php"
nginx_name="nginx-1.15.1.tar.gz"
mysql_name="mysql-5.6.41.tar.gz"
php_name="php-7.2.8.tar.gz"
[ -f /etc/init.d/functions ] && . /etc/init.d/functions || exit 1
#安装nginx
install_nginx(){
#跟新源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
# 安装依赖包
yum install -y pcre pcre-devel openssl openssl-devel gcc make gcc-c++
[ -e $dir ] && cd $dir
if [ -f $nginx_name ]
then
echo 'nginx need have'
# t解压文件
tar zxf $nginx_name && cd nginx-1.15.1
# 添加僵尸用户
useradd nginx -s /sbin/nologin -M
# 编译安装
./configure --user=nginx --group=nginx --prefix=/lnmp/nginx-1.15.1/ --with-http_stub_status_module --with-http_ssl_module
[ $(echo $?) -eq 0 ] && make && make install
[ $(echo $?) -eq 0 ] && echo "nginx install success...."
#创建软链接
ln -s /lnmp/nginx-1.15.1 /lnmp/nginx
fi
}
#开启脚本
start_nginx(){
service iptables stop
setenforce 0
/lnmp/nginx/sbin/nginx -c /lnmp/nginx-1.15.1//conf/nginx.conf
$nginx_install_dir/sbin/nginx -t
if [ $(echo $?) -eq 0 ]
then
$nginx_install_dir/sbin/nginx -s reload
if [ $(netstat -lutnp|grep 80|wc -l) -eq 1 ]
then
action "nginx success..." /bin/true
else
echo "nginx error!"
fi
fi
}
install_mysql(){
yum install -y ncurses-devel automake autoconf bison libtool-ltdl-devel
[ -e $dir ] && cd $dir
if [ -f $mysql_name ]
then
yum install cmake -y
tar zxvf $mysql_name
if [ ! -d $mysql_install_dir ]
then
mkdir -p $mysql_install_dir
fi
groupadd mysql
useradd -s /sbin/nologin -g mysql -M mysql
mkdir -p /lnmp/mysql-5.6.41/data
cd $dir/mysql-5.6.41
cmake -DCMAKE_INSTALL_PREFIX=/lnmp/mysql-5.6.41 -DMYSQL_DATADIR=/lnmp/mysql-5.6.41/data -DMYSQL_UNIX_ADDR=/lnmp/mysql-5.6.41/tmp/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ZLIB=bundled -DWITH_SSL=bundled -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DOWNLOADS=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DMYSQL_TCP_PORT=3306 -DWITH_DEBUG=0
make && make install
ln -s /lnmp/mysql-5.6.41/ /lnmp/mysql
/lnmp/mysql-5.6.41/scripts/mysql_install_db --user=mysql --basedir=/lnmp/mysql-5.6.41 --datadir=/lnmp/mysql-5.6.41/data --user=mysql
#授权
chown -R mysql:mysql /lnmp/mysql-5.6.41/
#创建目录,默认不会创建,但是启动会报错
mkdir /lnmp/mysql/tmp
[ $(echo $?) -eq 0 ] && \cp -f /lnmp/mysql-5.6.41/support-files/my*.cnf /etc/my.cnf
cp /lnmp/mysql-5.6.41/support-files/mysql.server /etc/init.d/mysqld
# 加权限
chmod +x /etc/init.d/mysqld
# 自启
chkconfig --add mysqld
chkconfig mysqld on
# 加环境
PATH=$PATH:/lnmp/mysql-5.6.41/bin/
#添加环境
echo "export PATH=$PATH:/lnmp/mysql/bin/" >>/etc/profile
source /etc/profile
fi
}
#启动函数
start_mysql(){
/etc/init.d/mysqld start
if [ $(netstat -lutnp|grep 3306|wc -l) -eq 1 ]
then
action "mysql success" /bin/true
else
echo "mysql error!"
fi
}

# 安装php
install_php(){
yum install zlib-devel openssl-devel openssl libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel libmcrypt-devel mcrypt mhash -y
[ -e $dir ] && cd $dir
if [ -f $php_name ]
then
tar zxf $php_name && cd php-7.2.8

echo "Please witing loding................................................................"
#编译安装
./configure --prefix=/lnmp/php7.2.8 --with-mysql=/lnmp/mysql --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --enable-gd-native-ttf --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-zend-multibyte --enable-static --with-xsl --with-fpm-user=nginx --with-fpm-group=nginx --enable-ftp
[ $(echo $?) -eq 0 ] && ln -s /lnmp/mysql/lib/libmysqlclient.so.18 /usr/lib64/ && touch ext/phar/phar.phar
make >> /dev/null 2>&1
make install
ln -s /lnmp/php7.2.8 /lnmp/php
cp ./php.ini-production /lnmp/php/lib/php.ini
cp /lnmp/php/etc/php-fpm.conf.default /lnmp/php/etc/php-fpm.conf
cp /lnmp/php/etc/php-fpm.d/www.conf.default /lnmp/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
#授予权限最好是700
chmod +x /etc/init.d/php-fpm
PATH=$PATH:/lnmp/php/bin/
echo "export PATH=$PATH:/lnmp/php/bin/" >>/etc/profile
source /etc/profile
chkconfig --add php-fpm
chkconfig php-fpm on
fi
}

# 启动函数
start_phpfpm(){
/etc/init.d/php-fpm start
if [ $(netstat -lutnp|grep 9000|wc -l) -eq 1 ]
then
action "php-fpm success" /bin/true
else
echo "php-fpm error"
fi

}

main(){
install_nginx
sleep 3
install_mysql
sleep 3
install_php
start_nginx
sleep 2
start_mysql
sleep 2
start_phpfpm
}
main