当前位置:网站首页>LNMP部署
LNMP部署
2022-06-11 12:53:00 【我就要执行】
LNMP部署
简介
LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构
Nginx是一个高性能的HTTP和 反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。
Mysql是一个小型 关系型数据库管理系统。
PHP是一种在服务器端执行的嵌入HTML文档的 脚本语言。
这四种软件均为免费 开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。
Nginx是一个小巧而高效的Linux下的Web 服务器软件,是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler 站点开发的,已经在一些俄罗斯的大型网站上运行多年,相当的稳定。
Nginx性能稳定、功能丰富、运维简单、处理 静态文件速度快且消耗 系统资源极少。
作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的 并发连接,体现更高的效率。
作为 负载均衡服务器:Nginx 既可以在内部直接支持 Rails 和 PHP,也可以支持作为 HTTP 代理服务器对外进行服务。Nginx 用C编写,不论是系统资源开销还是CPU使用效率都比Perlbal要好的多。
作为邮件代理服务器:Nginx同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last/fm 描述了成功并且美妙的使用经验。
Nginx 安装非常的简单,配置文件非常简洁(还能够支持 perl语法)。Nginx支持平滑加载新的配置,还能够在不间断服务的情况下进行软件版本的升级。
环境说明:
| 使用的系统平台 | IP | 需要安装的服务 |
|---|---|---|
| CentOS8 | 192.168.220.9 | nginx-1.20.1.tar.gz mysql-5.7.34 php-8.0.10 |
nginx部署
安装依赖包和工具包
[[email protected] ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make wget
[[email protected] ~]# yum -y group mark install "Development Tools"
创建用户
[[email protected] ~]# useradd -r -M -s /sbin/nologin nginx
创建日志存放目录
[[email protected] ~]# mkdir /var/log/nginx -p
下载nginx,解压
[[email protected] ~]# cd /usr/src/soft/
[[email protected] soft]# wget http://nginx.org/download/nginx-1.20.1.tar.gz
[[email protected] soft]# ls
nginx-1.20.1.tar.gz
[[email protected] soft]# tar xf nginx-1.20.1.tar.gz -C /usr/local
[[email protected] soft]# cd /usr/local/
[[email protected] local]# ls
bin games lib libexec sbin src
etc include lib64 mysql nginx-1.20.1 share
编译安装
[[email protected] nginx-1.20.1]# ./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
.......
checking for OS
+ Linux 4.18.0-257.el8.x86_64 x86_64
checking for C compiler ... found
......
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
[[email protected] nginx-1.20.1]# make && make install
安装后配置
配置环境变量
[[email protected] local]# nginx
-bash: nginx: command not found
[[email protected] local]# echo "export PATH=/usr/local/nginx/sbin:$PATH" > /etc/profile.d/nginx.sh
[[email protected] local]# bash
[[email protected] local]# which nginx
/usr/local/nginx/sbin/nginx
启动nginx
[[email protected] ~]# /usr/local/nginx/sbin/nginx
[[email protected] ~]# 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 0.0.0.0:80(nginx端口) 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
给nginx配置开机自启
[[email protected] ~]# cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/nginxd.service
[[email protected] ~]# vim /usr/lib/systemd/system/nginxd.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
KillMode=process
[Install]
WantedBy=multi-user.target
[[email protected] ~]# systemctl daemon-reload # 重新加载
[[email protected] ~]# systemctl enable --now nginxd # 启动nginx并设置开机自启
Created symlink /etc/systemd/system/multi-user.target.wants/nginxd.service → /usr/lib/systemd/system/nginxd.service.
MySQL部署
下载mysql
https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
将其上传到/usr/src目录下
[[email protected] src]# ls
debug kernels mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
创建用户和组
[[email protected] src]# groupadd -r mysql
[[email protected] src]# useradd -M -s /sbin/nologin -g mysql mysql
将其解压到/usr/local/目录下
[[email protected] src]# tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[[email protected] ~]# cd /usr/local/
[[email protected] local]# ls
bin games lib libexec sbin src
etc include lib64 mysql-5.7.34-linux-glibc2.12-x86_64 share
创建软连接
[[email protected] local]# ln -s mysql-5.7.34-linux-glibc2.12-x86_64 mysql
[[email protected] local]# ll
total 0
......
lrwxrwxrwx. 1 root root 35 Aug 25 08:33 mysql -> mysql-5.7.34-linux-glibc2.12-x86_64
drwxr-xr-x. 9 root root 129 Aug 25 08:32 mysql-5.7.34-linux-glibc2.12-x86_64
修改目录/usr/local/mysql的属主属组
[[email protected] local]# chown -R mysql.mysql /usr/local/mysql*
[[email protected] local]# ll
total 0
.......
lrwxrwxrwx. 1 mysql mysql 35 Aug 25 08:33 mysql -> mysql-5.7.34-linux-glibc2.12-x86_64
drwxr-xr-x. 9 mysql mysql 129 Aug 25 08:32 mysql-5.7.34-linux-glibc2.12-x86_64
添加环境变量
[[email protected] ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[[email protected] ~]# source /etc/profile.d/mysql.sh
[[email protected] ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
建立数据存放目录
[[email protected] ~]# mkdir /opt/data
[[email protected] ~]# chown -R mysql.mysql /opt/data
[[email protected] ~]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 Aug 25 08:48 data
初始化数据库
[[email protected] ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
2021-10-26T15:50:24.131273Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-10-26T15:53:24.270072Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-10-26T15:53:25.295810Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-10-26T15:53:25.352039Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 03d19f26-05a3-11ec-bf6e-000c29bb4cb2.
2021-10-26T15:53:25.352561Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-10-26T15:53:25.039258Z 0 [Warning] CA certificate ca.pem is self signed.
2021-10-26T15:53:25.357745Z 1 [Note] A temporary password is generated for [email protected]: gr;JyBKJF3(u
//请注意,这个命令的最后会生成一个临时密码,此处密码是 gr;JyBKJF3(u
//再次注意,这个密码是随机的,每个人都不一样,一定要记住这个密码,因为一会登录时会用到
//将临时密码写入到一个文件里,等下会用到
[[email protected] ~]# echo "gr;JyBKJF3(u" > passwd
[[email protected] ~]# cat passwd
gr;JyBKJF3(u
查看是否缺少依赖包
[[email protected] ~]# ldd /usr/local/mysql/bin/mysql(ldd是看某一个程序文件它所依赖的包,如果没有,就不能用,就需要用yum安装,查找哪个包提供的(yum whatprovides pkgs_name))
linux-vdso.so.1 (0x00007ffdf09ea000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fdfeb8dd000)
librt.so.1 => /lib64/librt.so.1 (0x00007fdfeb6d4000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fdfeb4d0000)
libncurses.so.5 => /lib64/libncurses.so.5 (0x00007fdfeb2aa000)
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fdfeaf15000)
libm.so.6 => /lib64/libm.so.6 (0x00007fdfeab93000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fdfea97b000)
libc.so.6 => /lib64/libc.so.6 (0x00007fdfea5b9000)
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007fdfea38e000)
/lib64/ld-linux-x86-64.so.2 (0x00007fdfebafd000)
生成配置文件
[[email protected] ~]# 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
修改配置文件
[[email protected] support-files]# pwd
/usr/local/mysql/support-files
[[email protected] support-files]# vim mysql.server
44 # overwritten by settings in the MySQL configuration files.
45
46 basedir=/usr/local/mysql # 安装mysql的位置
47 datadir=/opt/data # 数据存放的位置
使用脚本控制服务启动
[[email protected] ~]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.Logging to '/opt/data/localhost.localdomain.err'.
SUCCESS!
[[email protected] ~]# 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 80 *:3306 *:*
尝试登录数据库
[[email protected] ~]# cat passwd
gr;JyBKJF3(u
[[email protected] ~]# mysql -uroot -p'gr;JyBKJF3(u'
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory # 提示没有 "libncurses.so.5"
[[email protected] ~]# yum whatprovides libncurses.so.5 # 查找并安装
Failed to set locale, defaulting to C.UTF-8
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.
Last metadata expiration check: 0:00:52 ago on Wed Aug 25 09:25:55 2021.
ncurses-compat-libs-6.1-7.20180224.el8.i686 : Ncurses compatibility libraries
Repo : baseos
Matched from:
Provide : libncurses.so.5
[[email protected] ~]# yum -y install ncurses-compat-libs # 安装
Failed to set locale, defaulting to C.UTF-8
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.
.....
再次登录并修改密码
# 登录
[[email protected] ~]# mysql -uroot -p'gr;JyBKJF3(u'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.34
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set password = password('redhat'); #修改密码
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> exit
Bye
[[email protected] ~]# mysql -uroot -predhat # 使用修改后的密码登录成功
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.34 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
配置启动脚本
# 找一个文件修改
[[email protected] system]# pwd
/usr/lib/systemd/system
[[email protected] system]# cp sshd.service mysqld.service # 复制一份内容sshd.service到mysqld.service
[[email protected] system]# cat mysqld.service # 修改完成后
[Unit]
Description=mysql server daemon # mysql服务器守护程序
After=network.target # 网络之后启动
[Service]
Type=forking # 类型为forking(分叉)
ExecStart=/usr/local/mysql/support-files/mysql.server start # 启动服务的脚本的绝对路径
ExecStop=/usr/local/mysql/support-files/mysql.server stop # 停止服务的脚本的绝对路径
ExecReload=/bin/kill -HUP $MAINPID # 重新加载,发送信号
[Install]
WantedBy=multi-user.target
重新加载后启动
[[email protected] system]# systemctl daemon-reload
[[email protected] system]# systemctl start mysqld
[[email protected] system]# 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 80 *:3306 *:*
LISTEN 0 128 [::]:22 [::]:*
[[email protected] system]# systemctl status mysqld
● mysqld.service - mysql server daemon
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2021-08-25 09:56:30 EDT; 12s ago
PHP部署
安装php
下载依托源
[[email protected] ~]# yum -y install epel-release
下载依赖包
yum -y install sqlite-devel libzip-devel libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg-turbo libjpeg-turbo-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
yum -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
下载php
官网是php.net
[[email protected] ~]# wget https://www.php.net/distributions/php-8.0.10.tar.gz
解压
[[email protected]]# ls
php-8.0.10.tar.gz
[[email protected]]# tar xf php-8.0.10.tar.gz
编译安装php
[[email protected] ~]# cd /usr/local/php-8.0.10/
[[email protected] php-8.0.10]# ./configure --prefix=/usr/local/php8 \
--with-config-file-path=/etc \
--enable-fpm \
--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-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
....
--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
[[email protected] php-8.0.10]# make
[[email protected] php-8.0.10]# make install
添加环境变量
[[email protected] ~]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php.sh
[[email protected] ~]# source /etc/profile.d/php.sh
配置php-fpm
[[email protected] ~]# cd php-8.0.10
[[email protected] php-8.0.10]# cp php.ini-production /etc/php.ini
cp: overwrite '/etc/php.ini'? y
[[email protected] php-8.0.10]# cd sapi/
[[email protected] sapi]# cd fpm/
[[email protected] fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[[email protected] fpm]# pwd
/root/php-8.0.10/sapi/fpm
[[email protected] fpm]# chmod +x /etc/init.d/php-fpm
[[email protected] ~]# cd /usr/local/php8/
[[email protected] php8]# ls
bin etc include lib php sbin var
[[email protected] php8]# cd etc/
[[email protected] etc]# cp php-fpm.conf.default php-fpm.conf
[[email protected] etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php-fpm.d
[[email protected] etc]# cd php-fpm.d
[[email protected] php-fpm.d]# ls
www.conf.default
[[email protected] php-fpm.d]# cp www.conf.default www.conf
[[email protected] php-fpm.d]# ls
www.conf www.conf.default
[[email protected] ~]# service php-fpm start # 启动PHP
Starting php-fpm done
[[email protected] ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
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 80 *:3306 *:*
LISTEN 0 128 [::]:22 [::]:*
nginx配置支持PHP
[[email protected] ~]# cd /usr/local/nginx/conf/
[[email protected] conf]# vim nginx.conf
........
46 location / {
47 root html;
48 index index.html index.php index.htm; # 添加index.php
49 }
.......
68 location ~ \.php$ {
69 root html;
70 fastcgi_pass 127.0.0.1:9000;
71 fastcgi_index index.php;
72 fastcgi_param SCRIPT_FILENAME $Document_Root$fastcgi_script_name; # 修改
73 include fastcgi_params;
74 }
.......
[[email protected] conf]# nginx -t # 检查配置文件/usr/local/nginx/conf/nginx.conf 修改是否正确
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
[[email protected] conf]# nginx -s reload # 重新加载配置文件/usr/local/nginx/conf/nginx.conf
添加php文件
[[email protected] ~]# cd /usr/local/nginx/html/
[[email protected] html]# ll
total 12
-rw-r--r--. 1 root root 494 Oct 26 00:49 50x.html
-rw-r--r--. 1 root root 612 Oct 26 00:49 index.html
[[email protected] html]# vim index.php
[[email protected] html]# cat index.php
<?php
phpinfo();
?>
[[email protected] ~]# nginx -s reload # 重新加载
[[email protected] ~]# service php-fpm restart # 重启php
Gracefully shutting down php-fpm . done
Starting php-fpm done
访问测试

边栏推荐
- [acwing 11. solution number of knapsack problem] 01 knapsack + 01 knapsack + understand the specific meaning of 01 knapsack
- 室内场馆现代化的三大要点
- 【后台交互】select 绑定后台传递的数据
- Adobe Premiere基础-批量素材导入序列-变速和倒放(回忆)-连续动作镜头切换-字幕要求(十三)
- [noip1998] spelling
- TeaTalk·Online 演讲实录 | 圆满完结!安全上云,选对数据迁移策略很重要
- Does it affect children to wear Bluetooth headsets? How to protect children's ear health
- Add function drop-down multiple selections to display the selected personnel
- Record a JVM GC process
- 微软再曝“丑闻”:在办公室看 VR 黄片,“HoloLens 之父”即将离职!
猜你喜欢

Application of pip2pi, pypiserver and Apache in PIP local source configuration

How can mechanical equipment manufacturing enterprises manage outsourcing with the help of ERP system?

PADS使用之繪制原理圖

经营养生理疗馆要注意什么问题?

Does it affect children to wear Bluetooth headsets? How to protect children's ear health

live share使用体验

Is Zhima Z1 projector really easy to use? How about the actual effect?

Tawang food industry insight | China's dairy market analysis, competition pattern, development trend and thinking

openharmony标准系统之app手动签名

Quel projecteur 4K est le meilleur rapport qualité - prix, quand bex3 pro met en évidence 128g Storage 618 vaut la peine de voir
随机推荐
逆向学习入门-优秀的汇编调试工具OllyDbg
启牛商学院给的券商账户是安全的吗?开户收费吗
How can mechanical equipment manufacturing enterprises manage outsourcing with the help of ERP system?
QUIC的阻力
Quic resistance
Deep learning and CV tutorial (14) | image segmentation (FCN, segnet, u-net, pspnet, deeplab, refinenet)
.net core 抛异常对性能影响的求证之路
Node creates a template file with the art template template template engine
Adobe Premiere基础-批量素材导入序列-变速和倒放(回忆)-连续动作镜头切换-字幕要求(十三)
[acwing 11. solution number of knapsack problem] 01 knapsack + 01 knapsack + understand the specific meaning of 01 knapsack
Is Zhima Z1 projector really easy to use? How about the actual effect?
Another way to achieve family reunion, 2022 flagship projection nut j10s is planted with grass
Is it safe to open an account online in 2022?
Record a JVM GC process
Evolution of e-commerce development
苹果将造搜索引擎?
. 5 string
Stone technology: R & D strength and excellent quality help upgrade the sweeping robot industry
综合场馆的优势有哪些?
Application of pip2pi, pypiserver and Apache in PIP local source configuration