LNMP分布式搭建

一、准备三台主机

192.168.100.11 mysql

192.168.100.12 nginx

192.168.100.13 php

二、关闭防火墙及安全策略

systemctl stop firewalld

setenforce 0

三、安装nginx(192.168.100.11)

1、添加nginx源

vim /etc/yum.repos.d/nginx.repo

[nginx-stable]

name=nginx stable repo

baseurl=http://nginx.org/packages/centos/$releasever/$basearch/

gpgcheck=0

enabled=1

2、yum下载nginx

yum install nginx -y #--安装nginx

nginx -v #--查看nginx版本

3、启动nginx

systemctl start nginx.service

systemctl enable nginx.service

四、安装mysql(192.168.100.12)

1、安装mysql

yum remove mariadb* -y

2、配置

cd /etc/yum.repos.d

wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

#---解析主机地址,使用阿里源

yum -y install mysql57-community-release-el7-10.noarch.rpm

#--下载mysql源

sed -i 's/gpgcheck=1/gpgcheck=0/' mysql-community.repo

#--修改源文件

yum -y install mysql-community-server

#--安装mysql

3、启动mysql

systemctl start mysqld.service

systemctl enable mysqld.service

4、获取mysql初始密码

grep "password" /var/log/mysqld.log | awk '{print $NF}'

#--在日志文件中找出root用户的初始密码

5、登录mysql

mysql -uroot -p

Enter password: #输入初始密码 Q3ua.n-36/-R

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin@123'; #更改密码

yum -y remove mysql57-community-release-el7-10.noarch #--卸载mysql自动更新

五、安装php

1、安装php

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

#--失败就多试几次

yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache

2、启动php

systemctl start php-fpm

systemctl enable php-fpm

3、配置php

useradd -M -s /sbin/nologin php #--创建php用户

vim /etc/php.ini

date.timezone = Asia/Shanghai

vim /etc/php-fpm.d/www.conf

user = php

group = php

listen = 192.168.80.12:9000

listen.allowed_clients = 192.168.80.10

六、配置nginx支持php

cd /etc/nginx/conf.d

vim default.conf

......

location ~ \.php$ {

root /www;

fastcgi_pass 192.168.80.12:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME document_rootfastcgi_script_name; # $document_root 和 root 属性一样

include fastcgi_params;

}

systemctl restart nginx

vim /www/index.php

<?php

phpinfo();

?>

vim /www/test.php

<?php

$link=mysqli_connect('192.168.80.11','root','Admin@123');

if($link) echo "<h1>Success!!</h1>";

else echo "Fail!!";

?>

相关推荐
筱源源3 分钟前
Kafka-linux环境部署
linux·kafka
算法与编程之美42 分钟前
文件的写入与读取
linux·运维·服务器
xianwu5431 小时前
反向代理模块
linux·开发语言·网络·git
Amelio_Ming1 小时前
Permissions 0755 for ‘/etc/ssh/ssh_host_rsa_key‘ are too open.问题解决
linux·运维·ssh
Ven%2 小时前
centos查看硬盘资源使用情况命令大全
linux·运维·centos
TeYiToKu3 小时前
笔记整理—linux驱动开发部分(9)framebuffer驱动框架
linux·c语言·arm开发·驱动开发·笔记·嵌入式硬件·arm
dsywws3 小时前
Linux学习笔记之时间日期和查找和解压缩指令
linux·笔记·学习
yeyuningzi3 小时前
Debian 12环境里部署nginx步骤记录
linux·运维·服务器
上辈子杀猪这辈子学IT3 小时前
【Zookeeper集群搭建】安装zookeeper、zookeeper集群配置、zookeeper启动与关闭、zookeeper的shell命令操作
linux·hadoop·zookeeper·centos·debian
minihuabei3 小时前
linux centos 安装redis
linux·redis·centos