其他分享
首页 > 其他分享> > lamp-lnmp选择性部署架构服务脚本

lamp-lnmp选择性部署架构服务脚本

作者:互联网

Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。
Mysql是一个小型关系型数据库管理系统。
PHP是一种在服务器端执行的嵌入HTML文档的脚本语言
lnmp是linux+nginx+mysql+php是针对于访问量很大的web构架,成为一个免费、高效、扩展性强的网站服务系统

lnmp脚本

准备环境
系统 主机名 ip 服务 centos8 nginx 192.168.136.239 lnmp
1.nginx编译安装
#安装环境工具包
[root@nginx ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
[root@nginx ~]# yum -y groups mark install Development Tools
#创建系统用户
[root@nginx ~]# useradd -r -M -s /sbin/nologin nginx
#创建日志存放目录
[root@nginx ~]# mkdir -p /var/log/nginx
[root@nginx ~]# chown -R nginx.nginx /var/log/nginx
#下载nginx
[root@nginx ~]# cd /usr/src/
[root@nginx src]# wget https://nginx.org/download/nginx-1.20.1.tar.gz

#编译安装nginx
[root@nginx src]# tar -xf nginx-1.20.1.tar.gz 
[root@nginx src]# cd nginx-1.20.1/
[root@nginx nginx-1.20.1]# ./configure 
--prefix=/usr/local/nginx 
--user=nginx 
--group=nginx 
--with-debug 
--with-http_ssl_module 
--with-http_realip_module 
--with-http_image_filter_module 
--with-http_gunzip_module 
--with-http_gzip_static_module 
--with-http_stub_status_module 
--http-log-path=/var/log/nginx/access.log 
--error-log-path=/var/log/nginx/error.log
[root@nginx nginx-1.20.1]# make -j $(grep processor /proc/cpuinfo |wc -l) && make install

#环境变量配置
[root@nginx ~]# echo export PATH=/usr/local/nginx/sbin:$PATH > /etc/profile.d/nginx.sh
[root@nginx ~]# source /etc/profile.d/nginx.sh 
[root@nginx ~]# which nginx
/usr/local/nginx/sbin/nginx

#开机自启
[root@nginx ~]# cat /usr/lib/systemd/system/nginxd.service 
[Unit]
Description=Nginx server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx 
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process

[Install]
WantedBy=multi-user.target
[root@nginx ~]# systemctl daemon-reload

nginx命令语法

#查看版本
[root@nginx ~]# nginx -v
nginx version: nginx/1.20.1
#查看配置文件语法错误
[root@nginx ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

-c:指定配置文件路径
-s:发送控制服务信号,可选值:{stop|quit|reopen|reload}

启动|关闭|重新加载nginx

[root@nginx ~]# nginx    //启动
[root@nginx ~]# nginx -s stop   //关闭
[root@nginx ~]# nginx -s reload   //重启
[root@nginx ~]# ss -antl
State       Recv-Q      Send-Q            Local Address:Port             Peer Address:Port      Process                           
LISTEN      0           128                     0.0.0.0:80
2.mysql编译安装略
3.php7.4.24编译安装略

4.综合配置

nginx配置

[root@nginx ~]# cat /usr/local/nginx/html/index.php
<?php
        phpinfo();
?>

[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
    location / {
          
   
            root   html;
            index  index.php index.html index.htm;   #添加在开头index.php格式
        }

        location ~ .php$ {
          
   
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;    #scripts修改成web访问路径
            include        fastcgi_params;
        }

php配置

[root@nginx ~]# vim /usr/local/php7/etc/php-fpm.d/www.conf
;       will be used.
user = nginx
group = nginx

重启所有服务

[root@nginx ~]# systemctl restart nginxd
[root@nginx ~]# service php-fpm reload 
[root@nginx ~]# systemctl restart mysqld.service
5.web访问页面

lamp/lnmp选择性安装服务脚本

脚本目录
[root@localhost ~]# tree /tmp/lanmp/
/tmp/lanmp/
├── install_lanmp.sh
└── soft
    ├── apr-1.7.0.tar.bz2
    ├── apr-util-1.6.1.tar.bz2
    ├── httpd-2.4.48.tar.bz2
    ├── mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
    ├── nginx-1.20.1.tar.gz
    ├── nginx.conf
    └── php-8.0.10.tar.xz

脚本内容

[root@localhost ~]# cat /tmp/lanmp/install_lanmp.sh 
#!/bin/bash
if [ $UID -ne 0 ];then
        echo -e "e[1;31m 请使用管理员身份运行脚本 e[0m"
fi

#variables
makedir=/usr/local
tardir=/usr/src
packdir=/tmp/lanmp
datadir=/opt/data

read -p "请输入要安装的版本:(默认是lamp,输入其它的字符是lnmp)" count
if [ -z $count ];then
        count=1
else
        count=2
fi

#安装依赖包
echo -e "e[1;31m 正在安装依赖包 e[0m"
yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ make epel-release  "@Development Tools" ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs gd-devel &>/dev/null
sleep 2
yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  pcre-devel freetype freetype-devel gmp gmp-devel &>/dev/null
yum -y install libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel  epel-release php-mysqlnd.x86_64 libsqlite3x-devel oniguruma  &>/dev/null
yum -y install Http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm  libzip-devel &>/dev/null



#创建用户
id mysql &>/dev/null
if [ $? -ne 0 ];then
        useradd -r -M -s /sbin/nologin mysql
fi

#解压包
cd $packdir/soft/
tar -xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz -C $makedir
tar -xf php-8.0.10.tar.xz -C $tardir

#创建软链接和环境配置
if [ ! -d $makedir/mysql ];then
        ln -s $makedir/mysql-5.7.33-linux-glibc2.12-x86_64/ $makedir/mysql
fi
echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
chown -R mysql.mysql $makedir/mysql*

#创建数据目录
if [ ! -d $datadir ];then
        mkdir $datadir
fi
chown -R mysql.mysql $datadir

标签:Nginx,高性能,服务器,代理,安装环境,工具包,系统用户
来源: