IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> LNMP部署 -> 正文阅读

[系统运维]LNMP部署

LNMP部署

环境

系统ip部署服务
centos8-stream192.168.245.128nginx
centos8-stream192.168.245.131php
centos8-stream192.168.245.129mysql

lnmp由linux,nginx,mysql,php构成

作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率。

作为负载均衡服务器:Nginx 既可以在内部直接支持RailsPHP,也可以支持作为 HTTP代理服务器对外进行服务。Nginx 用C编写,不论是系统资源开销还是CPU使用效率都比Perlbal要好的多。

作为邮件代理服务器:Nginx同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last/fm 描述了成功并且美妙的使用经验。

Nginx 安装非常的简单,配置文件非常简洁(还能够支持perl语法)。Nginx支持平滑加载新的配置,还能够在不间断服务的情况下进行软件版本的升级。具体的优点或者配置文件详解可以看之前的nginx基础

#关闭三台服务器防火墙
[root@localhost nginx-1.20.2]# systemctl stop firewalld.service 
[root@localhost nginx-1.20.2]# systemctl disable firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost nginx-1.20.2]# setenforce 0

部署nginx:

#创建系统用户nginx
[root@localhost ~]# useradd -r -M -s /sbin/nologin nginx
#安装依赖
[root@localhost ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++
[root@localhost ~]#  yum -y groups mark install 'Development Tools'
#存放目录创建
[root@localhost ~]# mkdir -p /var/log/nginx
[root@localhost ~]# chown -R nginx.nginx /var/log/nginx
#下载源码包
[root@localhost src]# pwd
/usr/src
[root@localhost src]# wget https://nginx.org/download/nginx-1.20.2.tar.gz
[root@localhost src]# tar xf nginx-1.20.2.tar.gz 
#编译安装
[root@localhost src]# cd nginx-1.20.2/
[root@localhost nginx-1.20.2]# ./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

#nginx配置,服务控制方式,使用nginx命令
[root@localhost nginx-1.20.2]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install

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

#使用 nginx -t 检查配置文件语法
[root@localhost nginx-1.20.2]# 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
[root@localhost nginx-1.20.2]# nginx -v
nginx version: nginx/1.20.2
[root@localhost nginx-1.20.2]# 

#写service文件
[root@localhost nginx-1.20.2]# vim /usr/lib/systemd/system/nginx.service
[root@localhost nginx-1.20.2]# 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@localhost nginx-1.20.2]# systemctl daemon-reload 
[root@localhost nginx-1.20.2]# systemctl restart nginx.service 
[root@localhost nginx-1.20.2]# ss -antl
State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port      Process      
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                     [::]:*     
[root@localhost nginx-1.20.2]# curl 192.168.245.128
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

部署php

[root@localhost ~]# ls
anaconda-ks.cfg  php-8.1.11.tar.gz  to.sh
#先装依赖
[root@localhost ~]# dnf -y install make wget 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 --allowerasing oniguruma  --skip-broken --nobest

[root@localhost ~]# dnf -y install libsqlite3x-devel libxml2-devel libzip-devel
[root@localhost ~]# dnf -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
[root@localhost php-8.1.11]# yum localinstall oniguruma-6.8.2-2.el8.x86_64.rpm 
[root@localhost php-8.1.11]# dnf --enablerepo=PowerTools install oniguruma-devel

[root@localhost ~]# tar xf php-8.1.11.tar.gz 
[root@localhost ~]# cd php-8.1.11/
./configure --prefix=/usr/local/php8 \
 --with-config-file-path=/etc \
 --enable-fpm \
 --enable-inline-optimization \
 --disable-debug \
 --disable-rpath \
 --enable-shared \
 --enable-soap \
 --with-openssl \
--enable-bcmath \
 --with-iconv \
 --with-bz2 \
 --enable-calendar \
 --with-curl \
 --enable-exif  \
 --enable-ftp \
 --enable-gd \
 --with-jpeg \
 --with-zlib-dir \
 --with-freetype \
 --with-gettext \
 --enable-json \
 --enable-mbstring \
 --enable-pdo \
 --with-mysqli=mysqlnd \
 --with-pdo-mysql=mysqlnd \
 --with-readline \
 --enable-shmop \
 --enable-simplexml \
 --enable-sockets \
 --with-zip \
 --enable-mysqlnd-compression-support \
 --with-pear \
 --enable-pcntl \
 --enable-posix
[root@localhost php-8.1.11]# make install
[root@localhost php-8.1.11]# make installecho 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php8.sh
make: *** No rule to make target 'installecho'.  Stop.
[root@localhost php-8.1.11]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php8.sh[root@localhost php-8.1.11]# source /etc/profile.d/php8.sh 
[root@localhost php-8.1.11]# which php
/usr/local/php8/bin/php
[root@localhost php-8.1.11]# php -v
PHP 8.1.11 (cli) (built: Oct 11 2022 15:56:45) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.11, Copyright (c) Zend Technologies


#配置php-fpm
[root@localhost php-8.1.11]# cp php.ini-production  /etc/php.ini
cp: overwrite '/etc/php.ini'? y
[root@localhost php-8.1.11]# cd sapi/
[root@localhost sapi]#  ls
apache2handler  cgi  cli  embed  fpm  fuzzer  litespeed  phpdbg
[root@localhost sapi]# cd fpm/
[root@localhost fpm]# file init.d.php-fpm
init.d.php-fpm: POSIX shell script, ASCII text executable
[root@localhost /]# cd /usr/local/php8/
[root@localhost /]# cd etc
[root@localhost etc]#  cd fpm/启动php-fpm并设为开机自启
[root@localhost php-fpm.d]# service php-fpm start
Starting php-fpm  done
[root@localhost php-fpm.d]# ss -antl
State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port      Process      
LISTEN      0           128                    0.0.0.0:22                  0.0.0.0:*                      
LISTEN      0           128                  127.0.0.1:9000                0.0.0.0:*                      
LISTEN      0           128                       [::]:22                     [::]:*                      
[root@localhost php-fpm.d]# chkconfig --add php-fpm

[root@localhost fpm]#  cp init.d.php-fpm /etc/init.d/php-fpm
[root@localhost fpm]# chmod +x /etc/init.d/php-fpm
[root@localhost fpm]# cd /usr/local/php7/
[root@localhost php8]# cd /etc/
[root@localhost etc]# cp php-fpm.conf.default  php-fpm.conf
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default  www.conf

/启动php-fpm并设为开机自启
[root@localhost php-fpm.d]# service php-fpm start
Starting php-fpm  done
[root@localhost php-fpm.d]# ss -antl
State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port      Process      
LISTEN      0           128                    0.0.0.0:22                  0.0.0.0:*                      
LISTEN      0           128                  127.0.0.1:9000                0.0.0.0:*                      
LISTEN      0           128                       [::]:22                     [::]:*                      


[root@localhost php-fpm.d]# vim /usr/local/php8/etc/php-fpm.d/www.conf

listen = 127.0.0.1:9000  #找到这一行 127.0.0.1修改为自己的ip
;listen.allowed_clients = 192.168.245.128 #允许访问ip

[root@localhost ~]# mkdir -p /usr/local/nginx/html
[root@localhost ~]#  groupadd -r -g 955 nginx
[root@localhost ~]# useradd -M -s /sbin/nologin -g 955 -u 955 nginx
[root@localhost ~]# chown -R nginx.nginx /usr/local/nginx/html/
[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost html]# vim index.php
[root@localhost html]# cat index.php
<?php
    phpinfo();
?>

[root@localhost php-fpm.d]# chkconfig --add php-fpm

部署mysql

 #安装依赖包
 [root@master ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
 #下载二进制格式的mysql软件包:https://downloads.mysql.com/archives/community/
 网页访问上地址下载
 ?
 [root@master ~]# tar xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
 [root@master ~]# cd /usr/local/
 [root@master local]# ls
 apache     apr       bin  games  include  lib64    mysql-5.7.38-linux-glibc2.12-x86_64  share
 apache2.4  apr-util  etc  httpd  lib      libexec  sbin                                 src
 [root@master local]# mv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
 [root@master local]# 
 #修改属组
 [root@master local]# ls
 apache     apr       bin  games  include  lib64    mysql  share
 apache2.4  apr-util  etc  httpd  lib      libexec  sbin   src
 [root@master local]# chown -R mysql.mysql /usr/local/mysql
 [root@master local]# ll /usr/local/mysql -d
 drwxr-xr-x. 9 mysql mysql 129 Aug  2 21:03 /usr/local/mysql
 [root@master local]# 
 ?
 #添加环境变量
 [root@master ~]# ls /usr/local/mysql/
 LICENSE  README  bin  docs  include  lib  man  share  support-files
 [root@master ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
 [root@master ~]# . /etc/profile.d/mysql.sh
 [root@master ~]# echo $PATH
 /usr/local/mysql/bin:/usr/local/httpd/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
 [root@master ~]# 
 ?
 #建立数据存放目录
 [root@master ~]# mkdir /opt/data
 [root@master ~]# chown -R mysql.mysql /opt/data/
 [root@master ~]#  ll /opt/
 total 468
 drwxr-xr-x. 2 mysql mysql      6 Aug  2 21:06 data
 -rw-r--r--. 1 root  root  478044 Aug  2 10:55 tang.sql
 [root@master ~]# 
 ?
 ?
 #初始化数据库
 [root@master ~]#  /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
 ------------------
  root@localhost: s!a<7i5!DoLa
 #这里有随机生成的密码需要记住
 [root@master ~]# echo 's!a<7i5!DoLa' >> passwrd
 [root@master ~]# cat passwrd 
 s!a<7i5!DoLa
 [root@master ~]# 
 ?
 #配置mysql
 [root@master ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
 '/usr/local/include/mysql' -> '/usr/local/mysql/include/'
 [root@master ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
 [root@master ~]# ldconfig
 [root@master ~]# 
 ?
 #生成配置文件
 [root@master ~]# cat > /etc/my.cnf <<EOF
 > [mysqld]
 > basedir = /usr/local/mysql
 > datadir = /opt/data
 > socket = /tmp/mysql.sock
 > port = 3306
 > pid-file = /opt/data/mysql.pid
 > user = mysql
 > skip-name-resolve
 > EOF
 [root@master ~]# 
 ?
 #配置服务启动脚本
 [root@master ~]#  cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
 [root@master ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
 [root@master ~]#  sed -ri 's#^(datadir=).*#\1/opt/data#g' /etc/init.d/mysqld
 [root@master ~]# 
 ?
 #启动mysql
 [root@master ~]# service mysqld start
 Starting MySQL.Logging to '/opt/data/master.err'.
  SUCCESS! 
 [root@master ~]# ss -antl
 State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process    
 LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*                  
 LISTEN     0          80                         *:3306                    *:*                  
 LISTEN     0          128                     [::]:22                   [::]:*                  
 [root@master ~]# 
 ?
 #修改密码
 #使用临时密码登录
 [root@master ~]# mysql -uroot -p's!a<7i5!DoLa'
 ?
 mysql> set password = password('1');
 Query OK, 0 rows affected, 1 warning (0.00 sec)
 ?
 mysql> 
————————————————

修改nginx配置文件

[root@localhost ~]# cd /usr/local/nginx/
[root@localhost nginx]# ls
client_body_temp  conf  fastcgi_temp  html  logs  proxy_temp  sbin  scgi_temp  uwsgi_temp
[root@localhost nginx]# cd conf/
[root@localhost conf]# vim nginx.conf
       location / {
           root   html;
            index  index.php index.html index.htm;
        }

        location ~ \.php$ {
            root           html;
            fastcgi_pass   192.168.245.131:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
                }


[root@localhost conf]# cd ..
[root@localhost nginx]# cd html/
[root@localhost html]# vim index.html 
[root@localhost html]# cat index.html
<?php phpinfo(); ?>

image-20221011170535749

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2022-10-17 13:11:56  更:2022-10-17 13:16:12 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 6:14:34-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码