分离部署lamp

环境介绍

RHEL8 nginx 192.168.92.129
RHEL8 myxql 192.168.92.130
RHEL8 php 192.168.92.131

 

 

 

 

nginx配置

//关闭服务器和selinux
[root@nginx ~]# systemctl disable --now firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@nginx ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@nginx ~]#  setenforce 0

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

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

//下载nginx并解压
[root@nginx ~]# cd /usr/src/
[root@nginx src]#  wget http://nginx.org/download/nginx-1.20.0.tar.gz
[root@nginx src]# tar xf nginx-1.20.0.tar.gz
[root@nginx src]# 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 nginx-1.20.0]# vim /usr/local/nginx/conf/nginx.conf
。。。。。。
location / {
            root   html;
            index  index.html index.htm;
        }
        location ~ \.php$ {
           fastcgi_pass    192.168.92.131:9000;
           fastcgi_index   index.php;
           fastcgi_param   SCRIPT_FILENAME   /var/www/html/$fastcgi_script_name;
           include         fastcgi_params;
        }

。。。。。。

//检查文件是否有误
[root@nginx nginx-1.20.0]# 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

//创建测试页面index.php
[root@nginx nginx-1.20.0]#  cat > /usr/local/nginx/html/index.php <<EOF
> 
> <?php
>     phpinfo();
> ?>
> EOF

//启动nginx
[root@nginx ~]# nginx
[root@nginx ~]# 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               0.0.0.0:80             0.0.0.0:*      
LISTEN  0        128                  [::]:22                [::]:*

 

mysql配置

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

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

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

//下载mysql并解压
[root@mysql src]# wget https://downloads.mysql.com/archives/get/p//mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz

[root@mysql src]# 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
'/usr/local/mysql' -> '/usr/local/mysql-5.7.31-linux-glibc2.12-x86_64/'
[root@mysql ~]# chown -R mysql.mysql /usr/local/mysql*

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

//建立数据存放目录
[root@mysql ~]# mkdir /opt/mydata
[root@mysql ~]# chown  -R mysql.mysql /opt/mydata/

//初始化数据库
[root@mysql ~]# mysqld --initialize-insecure --user=mysql --datadir=/opt/mydata

//生成配置文件
[root@mysql ~]# 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 ~]# cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
[root@mysql ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@mysql ~]# sed -ri 's#^(datadir=).*#\1/opt/mydata#g' /etc/init.d/mysqld

//启动MySQL
[root@mysql ~]# service mysqld start
Starting MySQL.Logging to '/opt/mydata/mysql.err'.
..... SUCCESS!

//设置密码
[root@mysql ~]# mysql -e "set password = password('123456')"

 

安装php

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

//配置yum源
[root@php ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
[root@php ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@php ~]# sed -i 's#\$releasever#8#g' /etc/yum.repos.d/CentOS-Base.repo
[root@php ~]# yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
[root@php ~]# sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
[root@php ~]# sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
[root@php ~]# sed -i 's|$releasever|8|' /etc/yum.repos.d/epel*
[root@php ~]# yum clean all
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
34 files removed
[root@php ~]# yum makeache

//安装配置php
[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
[root@php ~]# yum -y install php*
[root@php ~]# vim /etc/php-fpm.d/www.conf 
。。。。。。
;listen = /run/php-fpm/www.sock     //注释此行
listen = 0.0.0.0:9000                      //添加监听端口
。。。。。。
; must be separated by a comma. If this value is left blank, connections will be
; accepted from any ip address.
; Default Value: any
listen.allowed_clients = 192.168.92.129 //修改成nginx主机的ip

//创建测试页面index.php
[root@php ~]# cat > /var/www/html/index.php <<EOF
> <?php
>      phpinfo();
> ?>
> EOF

[root@php ~]# chown -R nginx.nginx /var/www/html/

[root@php ~]# systemctl enable --now php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
[root@php ~]# 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             0.0.0.0:9000        0.0.0.0:*     
LISTEN 0       128                [::]:22             [::]:*

 

网页访问测试

 

posted @ 2021-06-01 09:02  Raygussie  阅读(78)  评论(0编辑  收藏  举报