释放双眼,带上耳机,听听看~!
入职新公司的第一天,带我的哥们就分配给我一个任务,让我装一个lnmp,并且写成脚本,这不是so easy 吗,于是我马上就开搞了,现在把我的脚本分享一下给大家。
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 1#lnmp安装脚本
2#Email:1445675350@qq.com
3#autor:fujinzhou
4#create time: 2016-11-29
5
6yum -y install vim-enhanced ncurses-devel elinks gcc gcc-c++ flex bison autoconf automake gzip net-snmp-devel net-snmp ncurses-devel pcre pcre-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel libXpm-devel gettext-devel pam-devel libtool libtool-ltdl openssl openssl-devel fontconfig-devel libxml2-devel curl-devel libicu libicu-devel libmcrypt libmcrypt-devel libmhash libmhash-devel
7
8#添加nginx用户
9user='nginx'
10group='nginx'
11user_exists=$(id -nu $user)
12if [ ! $user_exists ]; then
13 /usr/sbin/groupadd -f $group
14 /usr/sbin/useradd -g $group $user -s /sbin/nologin -M
15fi
16
17#安装nginx
18wget http://nginx.org/download/nginx-1.8.1.tar.gz
19tar -zxf nginx-1.8.1.tar.gz && cd nginx-1.8.1
20./configure --prefix=/usr/local/nginx --pid-path=/usr/local/nginx/nginx.pid --user=nginx --group=nginx \
21--with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/usr/local/nginx/client \
22--http-proxy-temp-path=/usr/local/nginx/proxy --http-fastcgi-temp-path=/usr/local/nginx/fcgi --http-uwsgi-temp-path=/usr/local/nginx/uwsgi --http-scgi-temp-path=/usr/local/nginx/scgi --with-pcre
23
24make && make install
25
26#启动nginx
27/usr/local/nginx/sbin/nginx
28
29#配置nginx
30sed -i '56a\location ~ \.php$ {\n\ root html;\n\ fastcgi_pass 127.0.0.1:9000;\n\ fastcgi_index index.php;\n\ fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;\n\ include fastcgi_params;\n\}\n' /usr/local/nginx/conf/nginx.conf
31/usr/local/nginx/sbin/nginx -s reload
32echo -e '<?php\n echo "nginx and PHP is OK";\n?>\n' >/usr/local/nginx/html/index.php
33
34#添加mysql用户
35user='mysql'
36group='mysql'
37user_exists=$(id -nu $user)
38if [ ! $user_exists ]; then
39 /usr/sbin/groupadd -f $group
40 /usr/sbin/useradd -g $group $user -s /sbin/nologin -M
41fi
42
43#安装Mysql
44wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz
45tar -xf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz && mv mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/mysql
46
47#配置mysql
48mkdir -p /data/mysql
49chown -R mysql:mysql /data/mysql/
50chown -R mysql:mysql /usr/local/mysql/
51/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql >>/dev/null
52cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
53cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
54sed -i 's#^datadir=#datadir=/data/mysql#' /etc/init.d/mysqld
55sed -i 's#^basedir=#basedir=/usr/local/mysql#' /etc/init.d/mysqld
56
57#启动mysql
58service mysqld start
59chkconfig mysqld on
60
61#添加php用户
62#添加mysql用户
63user='www'
64group='www'
65user_exists=$(id -nu $user)
66if [ ! $user_exists ]; then
67 /usr/sbin/groupadd -f $group
68 /usr/sbin/useradd -g $group $user -s /sbin/nologin -M
69fi
70
71#安装php
72yum install -y libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel
73wget http://mirrors.sohu.com/php/php-5.6.12.tar.gz
74tar -xf php-5.6.12.tar.gz && cd php-5.6.12
75./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc\
76 --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config\
77 --enable-fpm\
78 --enable-mbstring=all\
79 --enable-soap\
80 --enable-zip\
81 --enable-calendar\
82 --enable-bcmath\
83 --enable-exif\
84 --enable-ftp\
85 --enable-intl\
86 --with-openssl\
87 --with-zlib\
88 --with-curl\
89 --with-gd\
90 --with-zlib-dir=/usr/lib\
91 --with-png-dir=/usr/lib\
92 --with-jpeg-dir=/usr/lib\
93 --with-gettext\
94 --with-mhash\
95 --with-fpm-user=www\
96 --with-fpm-group=www
97
98make && make install
99
100#配置php
101cp php.ini-development /usr/local/php/etc/php.ini
102sed -i 's#^;date.timezone =#date.timezone=Asia/Shanghai#' /usr/local/php/etc/php.ini
103cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
104cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
105chmod +x /etc/init.d/php-fpm
106
107#启动php-fpm
108service php-fpm start
109chkconfig php-fpm on
110
111#删除解压目录
112rm /root/lnmp/php-5.6.12 -rf
113rm /root/lnmp/nginx-1.8.1 -rf
114