帮我写一个编译安装lnmp架构的shell脚本,给我提供一个案例
时间: 2024-05-11 09:13:45 浏览: 119
以下是一个编译安装lnmp架构的shell脚本案例:
```
#!/bin/bash
# 定义变量
NGINX_VERSION="1.18.0"
MYSQL_VERSION="5.7.31"
PHP_VERSION="7.4.9"
# 安装依赖
yum -y install gcc gcc-c++ autoconf automake make wget
# 下载nginx源码
wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
tar -zxvf nginx-${NGINX_VERSION}.tar.gz
# 下载mysql源码
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-${MYSQL_VERSION}.tar.gz
tar -zxvf mysql-${MYSQL_VERSION}.tar.gz
# 下载php源码
wget https://www.php.net/distributions/php-${PHP_VERSION}.tar.gz
tar -zxvf php-${PHP_VERSION}.tar.gz
# 编译安装nginx
cd nginx-${NGINX_VERSION}
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make && make install
cd ..
# 编译安装mysql
cd mysql-${MYSQL_VERSION}
cmake .
make && make install
cd ..
# 编译安装php
cd php-${PHP_VERSION}
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-fpm-user=www --with-fpm-group=www --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-zlib --with-iconv --with-openssl --with-mcrypt --with-curl --with-bz2 --with-mhash --enable-fpm --enable-mbstring --enable-sockets --enable-pcntl --enable-pdo --enable-mysqlnd --enable-zip --enable-bcmath
make && make install
cp php.ini-production /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cd ..
# 配置php-fpm
echo "[www]" >> /usr/local/php/etc/php-fpm.conf
echo "user = www" >> /usr/local/php/etc/php-fpm.conf
echo "group = www" >> /usr/local/php/etc/php-fpm.conf
echo "listen = 127.0.0.1:9000" >> /usr/local/php/etc/php-fpm.conf
echo "pm = dynamic" >> /usr/local/php/etc/php-fpm.conf
echo "pm.max_children = 50" >> /usr/local/php/etc/php-fpm.conf
echo "pm.start_servers = 20" >> /usr/local/php/etc/php-fpm.conf
echo "pm.min_spare_servers = 5" >> /usr/local/php/etc/php-fpm.conf
echo "pm.max_spare_servers = 35" >> /usr/local/php/etc/php-fpm.conf
# 启动lnmp
/usr/local/nginx/sbin/nginx
/usr/local/mysql/bin/mysqld_safe --user=mysql &
/usr/local/php/sbin/php-fpm
echo "lnmp已成功安装!"
```
该脚本会自动下载nginx、mysql、php的源码,并进行编译安装。安装完成后,会自动配置php-fpm并启动lnmp服务。
阅读全文