运维实例-LNMP一键安装脚本
| 资源名称 | 下载 |
|---|---|
| nginx源码包 | nginx-1.26.2.tar.gz |
| 一键安装脚本 | install_lnmp.sh |
| php解析测试页面 | test.php |
| 数据库解析测试页面 | mysql.php |
注意:
- 需要把nginx源码包和一键安装脚本放到相同的目录下
- 把测试页面放到 /usr/local/nginx/html 目录下
#!/bin/bash
#这是一个一键部署lnmp环境的脚步
echo "解压nginx"
tar zxvf nginx-1.26.2.tar.gz -C /opt/
echo "进入nginx解压目录"
cd /opt/nginx-1.26.2
echo "安装编译需要的相关依赖包"
yum install -y make gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel
echo "生成makefile文件"
./configure --prefix=/usr/local/nginx --user=nginx --with-http_ssl_module --with-http_stub_status_module
echo "开始编译安装"
make
make install
echo "添加nginx用户"
useradd -M -s /sbin/nologin nginx
echo "安装数据库及其相关包"
yum -y install mariadb mariadb-server mariadb-devel
echo "开启数据库服务"
systemctl restart mariadb
echo "安装php及其相关包"
yum -y install php php-fpm php-mysqlnd
echo "修改php-fpm配置,并开启php-fpm服务"
sed -i '/www.sock$/s!/run/php-fpm/www.sock!127.0.0.1:9000!' /etc/php-fpm.d/www.conf
systemctl restart php-fpm
echo "修改nginx的配置文件"
echo "
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
" > /usr/local/nginx/conf/nginx.conf
echo "启动nginx服务"
/usr/local/nginx/sbin/nginx