今天为大家搭建一下基于CentOS7.9服务器部署LNMP,方便未来基于lnmp部署应用程序。
1.CentOS7.9基础配置
为了实现基于CentOS7.9服务器部署LNMP,CentOS7.9服务器需要满足一定的基础需要。具体参考:Linux常规基础配置_linux操作系统配置_小黑要上天的博客-CSDN博客
2.服务器信息
HostName | IpAddress | OSVersion | Note |
lnmp | 192.168.10.250 | CentOS Linux release 7.9.2009 (Core) |
3.lnmp实施部署
3.1.nginx1.24.0安装部署
-->更新网络yum源
命令:
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@lnmp yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
--2023-11-20 18:11:16-- https://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 111.32.209.196, 2409:8c04:1110:a:3::3ae, 2409:8c04:1110:a:3::3ad
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|111.32.209.196|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’
100%[====================================================================>] 2,523 --.-K/s in 0s
2023-11-20 18:11:17 (210 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523]
-->设置nginx yum存储库,使用以下内容创建名为/etc/yum.repos.d/nginx.repo的文件,并保存
命令:
vim /etc/yum.repos.d/nginx.repo
[root@lnmp yum.repos.d]# cat /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@lnmp yum.repos.d]#
-->安装nginx
命令:
yum install nginx -y
rpm -qa | grep nginx
[root@lnmp ~]# yum install nginx -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
nginx-stable | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/3): extras/7/x86_64/primary_db | 250 kB 00:00:02
(2/3): nginx-stable/7/x86_64/primary_db | 87 kB 00:00:04
(3/3): updates/7/x86_64/primary_db | 24 MB 00:02:41
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.24.0-1.el7.ngx will be installed
--> Processing Dependency: libpcre2-8.so.0()(64bit) for package: 1:nginx-1.24.0-1.el7.ngx.x86_64
--> Running transaction check
---> Package pcre2.x86_64 0:10.23-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================
Package Arch Version Repository Size
==============================================================================================================
Installing:
nginx x86_64 1:1.24.0-1.el7.ngx nginx-stable 804 k
Installing for dependencies:
pcre2 x86_64 10.23-2.el7 CentOS7 201 k
Transaction Summary
==============================================================================================================
Install 1 Package (+1 Dependent package)
Total download size: 1.0 M
Installed size: 3.3 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/nginx-stable/packages/nginx-1.24.0-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 7bd9bf62: NOKEY
Public key for nginx-1.24.0-1.el7.ngx.x86_64.rpm is not installed
nginx-1.24.0-1.el7.ngx.x86_64.rpm | 804 kB 00:00:06
--------------------------------------------------------------------------------------------------------------
Total 145 kB/s | 1.0 MB 00:00:06
Retrieving key from https://nginx.org/keys/nginx_signing.key
Importing GPG key 0x7BD9BF62:
Userid : "nginx signing key <signing-key@nginx.com>"
Fingerprint: 573b fd6b 3d8f bc64 1079 a6ab abf5 bd82 7bd9 bf62
From : https://nginx.org/keys/nginx_signing.key
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : pcre2-10.23-2.el7.x86_64 1/2
Installing : 1:nginx-1.24.0-1.el7.ngx.x86_64 2/2
----------------------------------------------------------------------
Thanks for using nginx!
Please find the official documentation for nginx here:
* https://nginx.org/en/docs/
Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* https://nginx.org/en/support.html
Commercial subscriptions for nginx are available on:
* https://nginx.com/products/
----------------------------------------------------------------------
Verifying : pcre2-10.23-2.el7.x86_64 1/2
Verifying : 1:nginx-1.24.0-1.el7.ngx.x86_64 2/2
Installed:
nginx.x86_64 1:1.24.0-1.el7.ngx
Dependency Installed:
pcre2.x86_64 0:10.23-2.el7
Complete!
[root@lnmp ~]# rpm -qa | grep nginx
nginx-1.24.0-1.el7.ngx.x86_64
[root@lnmp ~]#
-->nginx启动
命令:
systemctl enable nginx
systemctl start nginx
systemctl status nginx
netstat -antulp | grep 80
[root@lnmp ~]# systemctl enable nginx
[root@lnmp ~]# systemctl start nginx
[root@lnmp ~]# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2023-11-20 18:23:13 CST; 2s ago
Docs: http://nginx.org/en/docs/
Process: 3894 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 3895 (nginx)
CGroup: /system.slice/nginx.service
├─3895 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
├─3896 nginx: worker process
├─3897 nginx: worker process
├─3898 nginx: worker process
└─3899 nginx: worker process
Nov 20 18:23:13 lnmp systemd[1]: Starting nginx - high performance web server...
Nov 20 18:23:13 lnmp systemd[1]: Started nginx - high performance web server.
[root@lnmp ~]# netstat -antulp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3895/nginx: master
[root@lnmp ~]#
-->nginx验证
3.2.mysql5.7安装部署
-->mysql5.7 rpm包下载
命令:
<