设为首页 加入收藏

TOP

三台虚拟主机搭建lnmp(一)
2023-07-23 13:35:48 】 浏览:85
Tags:台虚拟 lnmp

三台虚拟主机搭建lnmp


环境说明:

主机说明 ip 安装服务 系统
nginx 192.168.222.137 nginx centos7,redhat7/centos8,redhat8
mysql 192.168.222.138 mysql centos7,redhat7/centos8,redhat8
php 192.168.222.139 php centos7,redhat7/centos8,redhat8

阿里云官网
nginx官网
此处我使用的是nginx-1.22.0
mysql官网
此处我使用的是mysql-5.7.38
php官网
此处我使用的是php-8.1.11
此处我使用的系统是centos8.5

部署nginx

[root@localhost ~]# hostnamectl set-hostname nginx
[root@localhost ~]# bash
[root@nginx ~]# systemctl stop firewalld.service  //关闭防火墙
[root@nginx ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@nginx ~]# setenforce 0
[root@nginx ~]# systemctl disable --now firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@nginx ~]# dnf -y install wget
[root@nginx ~]# cd /etc/yum.repos.d/        //配置阿里源
[root@nginx yum.repos.d]#wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@nginx yum.repos.d]#sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@nginx yum.repos.d]# ls
CentOS-Base.repo
[root@nginx yum.repos.d]# cd
[root@nginx ~]# useradd -rMs /sbin/nologin nginx   //创建用户
[root@nginx ~]# dnf -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make vim    //安装依赖包
[root@nginx ~]# mkdir -p /var/log/nginx  //创建日志存放目录
[root@nginx ~]# chown -R nginx.nginx /var/log/nginx
[root@nginx ~]# wget http://nginx.org/download/nginx-1.22.0.tar.gz   //下载nginx包
[root@nginx ~]# tar xf nginx-1.22.0.tar.gz   //解压
[root@nginx ~]# ls
anaconda-ks.cfg  nginx-1.22.0  nginx-1.22.0.tar.gz
[root@nginx ~]# cd nginx-1.22.0/
[root@nginx nginx-1.22.0]# ls
CHANGES  CHANGES.ru  LICENSE  README  auto  conf  configure  contrib  html  man  src
[root@nginx nginx-1.22.0]# ./configure \   //进行编译
 --prefix=/usr/local/nginx \
 --user=nginx \
 --group=nginx \
 --with-debug \
 --with-http_ssl_module \
 --with-http_realip_module \
 --with-http_gunzip_module \
 --with-http_gzip_static_module \
 --with-http_stub_status_module
[root@nginx nginx-1.22.0]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install   //安装
[root@nginx nginx-1.22.0]# cd
[root@nginx ~]# echo "export PATH=$PATH:/usr/local/nginx/sbin" > /etc/profile.d/nginx.sh    //配置环境变量
[root@nginx ~]# source /etc/profile.d/nginx.sh  //使其生效
[root@nginx ~]# cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/nginx.service   
[root@nginx ~]# vim /usr/lib/systemd/system/nginx.service  //将其加入systemd服务中
[root@nginx ~]# cat /usr/lib/systemd/system/nginx.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
 
[Install]
WantedBy=multi-user.target
[root@nginx ~]# systemctl daemon-reload  //加载一下配置
[root@nginx ~]# systemctl enable --now nginx.service 
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.   //设置开机自启
[root@nginx ~]# ss -antl   //查看端口
State      Recv-Q     Send-Q          Local Address:Port           Peer Address:Por
首页 上一页 1 2 3 4 5 6 下一页 尾页 1/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇VMware vSphere 8.0 正式版下载 下一篇DNS域名解析服务

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目