微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

分离部署lnmp

环境

应用 IP 操作系统
Nginx 192.168.122.131 centos8
MysqL 192.168.122.132 centos8
PHP 192.168.122.133 centos8

准备工作

//关闭防火墙
# systemctl disable --Now firewalld
# setenforce 0
# vim /etc/selinux/config
SELINUX=disabled

安装Nginx

//安装依赖环境
[root@Nginx ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make wget
[root@Nginx ~]# yum -y groups mark install 'Development Tools'

//下载Nginx包
[root@Nginx ~]# wget http://Nginx.org/download/Nginx-1.20.0.tar.gz

//创建Nginx系统用户
[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 ~]# tar -xf Nginx-1.20.0.tar.gz
[root@Nginx ~]# cd Nginx-1.20.0
[root@Nginx Nginx-1.20.0]# ./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.0]# make && make install

//配置环境变量
[root@Nginx Nginx-1.20.0]# echo 'export PATH=/usr/local/Nginx/sbin:$PATH' > /etc/profile.d/Nginx.sh
[root@Nginx Nginx-1.20.0]# . /etc/profile.d/Nginx.sh

//修改配置文件
[root@Nginx ~]# vim  /usr/local/Nginx/conf/Nginx.conf
        location / {
            root   html;
            //添加index.PHP
            index index.PHP  index.html index.htm;
        }
 
        location ~ \.PHP$ {
          // 设置监听端口
            fastcgi_pass   192.168.122.133:9000;
           // 设置Nginx首页文件
            fastcgi_index  index.PHP;
          // 设置脚本文件请求的路径
            fastcgi_param  SCRIPT_FILENAME  /var/www/html/$fastcgi_script_name; 将$scripts修改PHP根网站目录
         //引入fastcgi的配置文件
            include        fastcgi_params;
        }

[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

//创建ndex.PHP
[root@Nginx ~]# cat > /usr/local/Nginx/html/index.PHP <<EOF
> <?PHP
>     PHPinfo();
> ?>
> EOF
 
//启动服务
[root@Nginx ~]# Nginx

 

安装配置MysqL

//安装
wget https://downloads.MysqL.com/archives/get/p/23/file/MysqL-5.7.31-linux-glibc2.12-x86_64.tar.gz

//安装依赖环境
[root@MysqL ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs

//创建用户
[root@MysqL ~]# useradd  -r -M -s /sbin/nologin  MysqL

//安装MysqL
[root@MysqL ~]#  tar  -xf MysqL-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@MysqL ~]# ln -sv /usr/local/MysqL-5.7.31-linux-glibc2.12-x86_64/  /usr/local/MysqL
[root@MysqL ~]# cd /usr/local/
[root@MysqL local]# chown -R MysqL.MysqL MysqL*

//添加环境变量
[root@MysqL local]# echo 'export PATH=/usr/local/MysqL/bin:$PATH' > /etc/profile.d/myslq.sh
[root@MysqL local]# source /etc/profile.d/myslq.sh
[root@MysqL local]# ln -s /usr/local/MysqL/include/  /usr/include/MysqL
[root@MysqL local]# echo '/usr/local/MysqL/lib' >/etc/ld.so.conf.d/MysqL.conf
[root@MysqL local]# ldconfig

//创建数据存放目录
[root@MysqL local]# mkdir /opt/mydata
[root@MysqL local]# chown  -R MysqL.MysqL /opt/mydata/

[root@MysqL local]# MysqLd --initialize-insecure --user=MysqL --datadir=/opt/mydata

//生成配置文件
[root@MysqL local]# cat > /etc/my.cnf <<EOF
[MysqLd]
basedir=/usr/local/MysqL
datadir=/opt/mydata
socket=/tmp/MysqL.sock
port=3306
pid-file=/opt/mydata/MysqL.pid
user=MysqL
skip-name-resolve
EOF

//配置服务启动脚本
[root@MysqL local]# cp /usr/local/MysqL/support-files/MysqL.server  /etc/init.d/MysqLd
[root@MysqL local]# sed -ri 's#^(basedir=).*#\1/usr/local/MysqL#g' /etc/init.d/MysqLd
[root@MysqL local]# sed -ri 's#^(datadir=).*#\1/opt/mydata#g' /etc/init.d/MysqLd

//启动MysqL
[root@MysqL local]# service MysqLd start
 
//设置密码
[root@MysqL local]# MysqL -e "set password = password('123456')"

安装PHP

[root@localhost tmp]# yum -y install PHP*
[root@localhost tmp]# vim /etc/PHP-fpm.d/www.conf

;listen = /run/PHP-fpm/www.sock //注释此行
listen = 0.0.0.0:9000  //添加监听端口

; accepted from any ip address.
; Default Value: any
listen.allowed_clients = 192.168.122.131  //Nginx主机的ip

[root@localhost tmp]# cat /var/www/html/index.PHP
<?PHP
    PHPinfo();
?>
 
[root@localhost tmp]# chown -R Nginx.Nginx /var/www/html/
[root@localhost tmp]# systemctl  start PHP-fpm

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐