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

lamp分离部署

环境:

应用 IP 操作系统
Nginx 192.168.23.148 centos8
MysqL 192.168.23.142 centos8
PHP 192.168.23.143 centos8

准备工作

//关闭防火墙与selinux
Nginx
[root@Nginx ]# systemctl stop firewalld
[root@Nginx ]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@Nginx ]# setenforce 0
[root@Nginx ]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config

MysqL
[root@MysqL ]# systemctl stop firewalld
[root@MysqL ]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@MysqL ]# setenforce 0
[root@MysqL ]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config

PHP
[root@PHP ]# systemctl stop firewalld
[root@PHP ]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@PHP ]# setenforce 0
[root@PHP ]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config

安装Nginx

//创建系统用户Nginx
[root@Nginx ~]# useradd -r -M -s /sbin/nologin 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'
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Marked install: Development Tools

//创建日志存放目录
[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 http://Nginx.org/download/Nginx-1.12.0.tar.gz
--2021-05-24 23:01:08--  http://Nginx.org/download/Nginx-1.12.0.tar.gz
Resolving Nginx.org (Nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5704::6, ...
Connecting to Nginx.org (Nginx.org)|52.58.199.22|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 980831 (958K) [application/octet-stream]
Saving to: ‘Nginx-1.12.0.tar.gz’

Nginx-1.12.0.tar.gz          100%[============================================>] 957.84K  11.9KB/s    in 76s     

2021-05-24 23:02:25 (12.5 KB/s) - ‘Nginx-1.12.0.tar.gz’ saved [980831/980831]

//编译安装
[root@Nginx src]# ls
debug  kernels  Nginx-1.12.0.tar.gz
[root@Nginx src]# tar xf Nginx-1.12.0.tar.gz
[root@Nginx src]# cd Nginx-1.12.0
[root@Nginx Nginx-1.12.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.12.0]# make && make install

修改配置文件

//修改配置文件
[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.248.17: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
[root@Nginx html]# ss -antl
State          Recv-Q         Send-Q                 Local Address:Port                 Peer Address:Port         
LISTEN         0              128                          0.0.0.0:80                        0.0.0.0:*            
LISTEN         0              128                          0.0.0.0:22                        0.0.0.0:*            
LISTEN         0              128                             [::]:22                           [::]:*        

安装MysqL

//wget安装
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 ~]# ss -antl
State          Recv-Q         Send-Q                 Local Address:Port                 Peer Address:Port         
LISTEN         0              128                          0.0.0.0:22                        0.0.0.0:*            
LISTEN         0              128                             [::]:22                           [::]:*            
LISTEN         0              80                                 *:3306                            *:*            

//修改配置
//更改配置文件
[root@MysqL ~]# vim /etc/man_db.conf

#
# Lines beginning with `#' are comments and are ignored. Any combination of
# tabs or spaces may be used as `whitespace' separators.
#
# There are three mappings allowed in this file:
# --------------------------------------------------------
# MANDATORY_MANPATH                     manpath_element
# MANPATH_MAP           path_element    manpath_element
# MANDB_MAP             global_manpath  [relative_catpath]
#---------------------------------------------------------
# every automatically generated MANPATH includes these fields
#
#MANDATORY_MANPATH                      /usr/src/pvm3/man
#
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/MysqL/man //添加这一行内容

[root@MysqL ~]# vim /etc/ld.so.conf.d/MysqL.conf
/usr/local/MysqL/lib

//设置密码
[root@MysqL local]# MysqL -e "set password = password('yanchuang')"

安装PHP

//安装开发工具包
[root@yc4 ~]# yum -y groups mark install 'Development Tools'

//安装依赖包
[root@PHP ~]# 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 libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel PHP-MysqLnd

//安装PHP
[root@PHP ~]# yum -y install PHP-*
    
//启动PHP
[root@PHP ~]# systemctl start PHP-fpm
[root@PHP html]# ss -antl
State          Recv-Q         Send-Q                 Local Address:Port                 Peer Address:Port         
LISTEN         0              128                          0.0.0.0:9000                      0.0.0.0:*            
LISTEN         0              128                          0.0.0.0:22                        0.0.0.0:*            
LISTEN         0              128                             [::]:22                           [::]:*        

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

相关推荐