lnmp环境安装sh脚本

简介:

  闲来无事自己写了个LNMP环境的安装脚本。

  该脚本可以单独安装nginx,mysql,php,也可以一步到位直接安装所有软件。其中,nginx安装完,需根据具体环境修改配置文件,再启动服务。mysql,php安装完服务自动启动。

  

  环境:

     软件安装路径:/opt/apps/

     数据存放目录:/opt/data/

     安装包下载目录:/opt/src/


  具体软件版本如下:

             nginx-1.10.1

             mysql-5.6.32

             php-7.0.10

  脚本如下:

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
# more lnmp_install.sh
#!/bin/sh
##############################defind functions that install lnmp....######################
#######nginx##########################
Install_nginx ()
{
echo  -e  "\033[33m Install nginx....\033[0m"
if  [ -d  /opt/apps/nginx/  ];  then
   echo  -e  "\033[31m Nginx already exists in your system......\033[0m"
   exit
fi
   echo  -e  "\033[33m Install base environment of nginx......\033[0m" 
   yum -y  install  pcre* openssl*
   echo  -e  "\033[33m Download nginx(1.10.1)......\033[0m"
   if  [ ! -f  /opt/src/nginx-1 .10.1. tar .gz ];
   then
    wget http: //nginx .org /download/nginx-1 .10.1. tar .gz  -P  /opt/src
   fi
   cd  /opt/src/
   tar  -zxvf nginx-1.10.1. tar .gz
   cd  nginx-1.10.1
   echo  -e  "\033[33m Compose nginx......\033[0m" 
  . /configure  --prefix= /opt/apps/nginx   --conf-path= /opt/conf/nginx/nginx .conf  --error-log-path= /opt/logs/nginx/error .log --http-log-path= /opt/logs/nginx/access .log --with-http_stub_status_module --with-http_gzip_static_module --with-ht
tp_flv_module --with-http_ssl_module --with-http_realip_module --http-client-body-temp-path= /opt/apps/nginx/client_body_temp  --http-fastcgi-temp-path= /opt/apps/nginx/fastcgi_temp  --http-proxy-temp-path= /opt/apps/nginx/proxy_temp  --http-
uwsgi-temp-path= /opt/apps/nginx/uwsgi_temp  --http-scgi-temp-path= /opt/apps/nginx/scgi_temp
   make  &&  make  install
   if  [ $? - eq  "0"  ];  then
     echo  -e  "\033[32m Nginx is installed successfully......\033[0m"
     exit
   else
     echo  -e  "\033[31m Something was wrong during installing nginx,please check and try again......\033[0m"
     exit
   fi
}
######mysql############################
Install_mysql ()
{
#Removing default rpm packages of mysql if they have been installed....
if  [ -f  /usr/bin/mysqld_safe  ]; then
   echo  -e  "\033[33m Remove default mysql-server RPM packages......\033[0m" 
   yum -y remove mysql-server
fi
if  [ -f  /usr/bin/mysqldump  ]; then
   echo  -e  "\033[33m Remove default mysql-client RPM packages......\033[0m" 
   yum -y remove mysql 
fi
#Adding mysql's user and group..
if  [ ! -d  /opt/data/mysql ]; then
     mkdir  -p  /opt/data/mysql
fi
echo  -e  "\033[33m Setting Environment variables......\033[0m" 
userdel -r mysql
groupdel -r mysql
groupadd  mysql
useradd  -r -g mysql -s  /sbin/nologin  mysql
#setting the env of mysql......
base_dir= /opt/apps/mysql/
data_dir= /opt/data/mysql/
src_dir= /opt/src/
#Download mysql and install
if  [ ! -d  /opt/src/mysql-5 .6.32/ ]; then
   if  [ ! -f  /opt/src/mysql-5 .6.32. tar .gz ]; then
     wget http: //dev .mysql.com /get/Downloads/MySQL-5 .6 /mysql-5 .6.32. tar .gz -P  /opt/src/
   fi
   cd  /opt/src/
   tar  -zxvf  /opt/src/mysql-5 .6.32. tar .gz
fi 
cd  /opt/src/mysql-5 .6.32
cmake . -DCMAKE_INSTALL_PREFIX=${base_dir} -DMYSQL_DATADIR=${data_dir} -DMYSQL_UNIX_ADDR=${data_dir}mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_g
eneral_ci -DWITH_DEBUG=0
if  "$?"  - ne  "0"  ]; then
     echo  -e  'Configure mysql failure,Please check compile Environment...'
     exit  2
fi
make  -j 3 
if  "$?"  - ne  "0"  ]; then
     echo  'Error,please look config.log for more information...'
     exit  2
fi
make  install
if  "$?"  - eq  "0"  ]; then
     echo  -e  'Mysql install complete done...'
else
     echo  -e  'Something wrong between Installation...'
fi
#Initialization mysql..
echo  -e  'Initialization mysql...'
cd  ${src_dir}mysql-5.6.32
cp  support-files /my-default .cnf ${data_dir} /my .cnf
cp  support-files /mysql .server  /etc/init .d /mysqld
sed  -i -e  '46s/basedir=/basedir=${base_dir}/'  -e  '47s/datadir=/datadir=${data_dir}/'   /etc/init .d /mysqld
chmod  a+x  /etc/init .d /mysqld
chkconfig --add mysqld
sed  -i -e  "s#@HOSTNAME@#hostname#"   . /scripts/mysql_install_db .sh
sh . /scripts/mysql_install_db .sh --user=mysql --basedir=${base_dir} --datadir=${data_dir}   >  /dev/null  2>&1
chown  -R mysql.mysql  /opt/apps/mysql/
chown  -R mysql.mysql  /opt/data/mysql/
#Start mysql...
ulimit  -s unlimited
service mysqld start
}
#######php###########################################################
Install_php ()
{
if  [ ! -f  /opt/src/php-7 .0.10. tar .gz ]; then
   echo  -e  "\033[33m Download php-7.0.10.tar.gz......\033[0m" 
   wget http: //cn2 .php.net /get/php-7 .0.10. tar .gz /from/this/mirror  -P  /opt/src
   cd  /opt/src  &&   mv  mirror php-7.0.10. tar .gz
fi
echo  -e  "\033[33m Complising and installing php-7.0.10 ......\033[0m" 
tar  -zxvf php-7.0.10. tar .gz
cd  php-7.0.10
yum  install  -y php-mcrypt libmcrypt libmcrypt-devel libjpeg-turbo-devel.x86_64   
. /configure  --prefix= /opt/apps/php  --with-config- file -path= /opt/apps/php/etc  --with-mcrypt= /usr/include  --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd --with-iconv --with-zlib -- enable -xml -- enable -bcmath 
-- enable -shmop -- enable -sysvsem -- enable -inline-optimization -- enable -mbregex -- enable -fpm -- enable -mbstring -- enable - ftp  -- enable -gd-native-ttf --with-openssl -- enable -pcntl -- enable -sockets --with-xmlrpc -- enable -zip -- enable -soap --w
ithout-pear --with-gettext -- enable -session --with-curl --with-jpeg- dir  --with-freetype- dir  -- enable -opcache
if  [ $? - eq  "0" ]; then
   echo  -e  "\033[31m Php install faild....Please check and try again....\033[0m"
   exit
fi
make  &&  make  install
cp  php.ini-production  /opt/apps/php/etc/php .ini
cp  sapi /fpm/init .d.php-fpm  /etc/init .d /php7-fpm   
cp  /opt/apps/php/etc/php-fpm .conf.default  /opt/apps/php/etc/php-fpm .conf     
cp  /opt/apps/php/etc/php-fpm .d /www .conf.default  /opt/apps/php/etc/php-fpm .d /www .conf
echo  "zend_extension=/opt/apps/php/lib/php/extensions/no-debug-non-zts-20151012/opcache.so"  >>  /opt/apps/php/etc/php .ini
chmod  775  /etc/init .d /php7-fpm
echo  -e  "\033[33m Starting php7-frm service......\033[0m" 
/etc/init .d /php7-fpm  start
if  [ $? - eq  "0"  ]; then
   echo  -e  "\032[33m PHP installed and started successfully......\033[0m" 
else :
   echo  -e  "\033[31m PHP installed successfully,but start failed,please check the configuration of php......\033[0m" 
fi
}
 
 
###############################Main program######################################
mkdir  -p  /opt/ {apps,conf,src,data}
read  -p  "Which part of lnmp you want to install?(nginx|mysql|php|all):"  softwar
case  ${softwar}  in 
nginx)
  Install_nginx
;;
mysql)
  Install_mysql
;;
php)
Install_php
;;
all)
if  [ -d  /opt/apps/nginx  ]; then
  echo  -e  "\033[33m Nginx was already installed in your system...\033[0m"
else
   Install_nginx
fi
if  [ -d  /opt/apps/mysql  ]; then
  echo  -e  "\033[33m Mysql was already installed in your system...\033[0m"
else
   Install_mysql
fi
if  [ -d  /opt/apps/php  ]; then
  echo  -e  "\033[33m PHP was already installed in your system...\033[0m"
else
  Install_php
fi
;;
*)
echo  -e  "\033[33m Sorry,please input a right choice\033[0m"
esac









本文转自 icenycmh 51CTO博客,原文链接:http://blog.51cto.com/icenycmh/1841585,如需转载请自行联系原作者
相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
目录
相关文章
|
关系型数据库 MySQL 应用服务中间件
|
关系型数据库 MySQL 应用服务中间件
|
应用服务中间件 Shell nginx
Linux centos下编译安装Lnmp shell脚本
自动安装 lnmp web环境
2424 0
|
Web App开发 关系型数据库 MySQL
|
关系型数据库 MySQL 应用服务中间件
|
Web App开发 关系型数据库 应用服务中间件
|
关系型数据库 MySQL 应用服务中间件
|
关系型数据库 Shell 应用服务中间件
|
关系型数据库 应用服务中间件 Linux