我是靠谱客的博主 鲜艳大米,这篇文章主要介绍CentOS系统使用yum安装Nginx服务器,现在分享给大家,希望可以做个参考。

CentOS系统使用yum安装Nginx服务器

文章目录

    • CentOS系统使用yum安装Nginx服务器
        • 1. 概述
        • 2. 安装`yum-utils`工具:
        • 3. 设置yum仓库:
          • 3.1 创建`/etc/yum.repos.d/nginx.repo`文件
          • 3.2 编辑文件内容
        • 4. 配置安装包
        • 5. 安装nginx
        • 6. 安装过程
        • 7. 参数解释及nginx启动
          • 7.1 `-t`参数
          • 7.2 `-V`参数
          • 7.3 启动nginx
          • 7.4 停止nginx
          • 7.5 重启nginx

1. 概述

根据官方提供的文档在CentOS操作系统上使用yum快速安装nginx服务器。

  • 在新机器上首次安装nginx之前,需要配置nginx软件包仓库库。

  • 可以从仓库中安装和更新nginx

官网地址:http://nginx.org/en/linux_packages.html

2. 安装yum-utils工具:

复制代码
1
2
yum install yum-utils

3. 设置yum仓库:

3.1 创建/etc/yum.repos.d/nginx.repo文件
复制代码
1
2
3
#通过vim在没有该文件的情况下,直接创建新文件 vim /etc/yum.repos.d/nginx.repo
3.2 编辑文件内容
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[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

4. 配置安装包

  • 默认使用stable nginx安装包仓库,对应上述[nginx-stable]

  • 若使用mainline nginx安装包,对应上述[nginx-mainline], 使用下述命令

复制代码
1
2
3
#开启使用nginx-mainline yum-config-manager --enable nginx-mainline

5. 安装nginx

复制代码
1
2
yum install nginx

安装过程中,当提示接受GPG密钥时,请验证指纹是否与573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62匹配。若匹配,则接受它。

6. 安装过程

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#1.安装yum-utils工具 [root@izwz97v6f2nxfmqc5cc8taz /]# yum install yum-utils Loaded plugins: fastestmirror base | 3.6 kB 00:00:00 epel | 4.7 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/2): epel/x86_64/updateinfo | 1.0 MB 00:00:00 (2/2): epel/x86_64/primary_db | 6.9 MB 00:00:00 Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package yum-utils.noarch 0:1.1.31-54.el7_8 will be installed --> Processing Dependency: python-kitchen for package: yum-utils-1.1.31-54.el7_8.noarch --> Processing Dependency: libxml2-python for package: yum-utils-1.1.31-54.el7_8.noarch --> Running transaction check ---> Package libxml2-python.x86_64 0:2.9.1-6.el7.5 will be installed --> Processing Dependency: libxml2 = 2.9.1-6.el7.5 for package: libxml2-python-2.9.1-6.el7.5.x86_64 ---> Package python-kitchen.noarch 0:1.1.1-5.el7 will be installed --> Processing Dependency: python-chardet for package: python-kitchen-1.1.1-5.el7.noarch --> Running transaction check ---> Package libxml2.x86_64 0:2.9.1-6.el7_2.3 will be updated ---> Package libxml2.x86_64 0:2.9.1-6.el7.5 will be an update ---> Package python-chardet.noarch 0:2.2.1-3.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved =================================================================================================================================== Package Arch Version Repository Size =================================================================================================================================== Installing: yum-utils noarch 1.1.31-54.el7_8 base 122 k Installing for dependencies: libxml2-python x86_64 2.9.1-6.el7.5 base 247 k python-chardet noarch 2.2.1-3.el7 base 227 k python-kitchen noarch 1.1.1-5.el7 base 267 k Updating for dependencies: libxml2 x86_64 2.9.1-6.el7.5 base 668 k Transaction Summary =================================================================================================================================== Install 1 Package (+3 Dependent packages) Upgrade ( 1 Dependent package) Total download size: 1.5 M Is this ok [y/d/N]: y #输入y 回车同意下载 Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. (1/5): libxml2-python-2.9.1-6.el7.5.x86_64.rpm | 247 kB 00:00:00 (2/5): python-chardet-2.2.1-3.el7.noarch.rpm | 227 kB 00:00:00 (3/5): python-kitchen-1.1.1-5.el7.noarch.rpm | 267 kB 00:00:00 (4/5): yum-utils-1.1.31-54.el7_8.noarch.rpm | 122 kB 00:00:00 (5/5): libxml2-2.9.1-6.el7.5.x86_64.rpm | 668 kB 00:00:00 ----------------------------------------------------------------------------------------------------------------------------------- Total 3.6 MB/s | 1.5 MB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Updating : libxml2-2.9.1-6.el7.5.x86_64 1/6 Installing : libxml2-python-2.9.1-6.el7.5.x86_64 2/6 Installing : python-chardet-2.2.1-3.el7.noarch 3/6 Installing : python-kitchen-1.1.1-5.el7.noarch 4/6 Installing : yum-utils-1.1.31-54.el7_8.noarch 5/6 Cleanup : libxml2-2.9.1-6.el7_2.3.x86_64 6/6 Verifying : libxml2-python-2.9.1-6.el7.5.x86_64 1/6 Verifying : python-chardet-2.2.1-3.el7.noarch 2/6 Verifying : python-kitchen-1.1.1-5.el7.noarch 3/6 Verifying : yum-utils-1.1.31-54.el7_8.noarch 4/6 Verifying : libxml2-2.9.1-6.el7.5.x86_64 5/6 Verifying : libxml2-2.9.1-6.el7_2.3.x86_64 6/6 Installed: yum-utils.noarch 0:1.1.31-54.el7_8 Dependency Installed: libxml2-python.x86_64 0:2.9.1-6.el7.5 python-chardet.noarch 0:2.2.1-3.el7 python-kitchen.noarch 0:1.1.1-5.el7 Dependency Updated: libxml2.x86_64 0:2.9.1-6.el7.5 Complete! #安装完成 #2.创建nginx.repo文件,并输入内容 [root@izwz97v6f2nxfmqc5cc8taz /]# vim /etc/yum.repos.d/nginx.repo ######### #上述内容# ######### #3.切换nginx-mainline软件包 [root@izwz97v6f2nxfmqc5cc8taz /]# yum-config-manager --enable nginx-mainline Loaded plugins: fastestmirror ====================================================== repo: nginx-mainline ======================================================= [nginx-mainline] async = True bandwidth = 0 base_persistdir = /var/lib/yum/repos/x86_64/7 baseurl = http://nginx.org/packages/mainline/centos/7/x86_64/ cache = 0 cachedir = /var/cache/yum/x86_64/7/nginx-mainline check_config_file_age = True compare_providers_priority = 80 cost = 1000 deltarpm_metadata_percentage = 100 deltarpm_percentage = enabled = 1 enablegroups = True exclude = failovermethod = priority ftp_disable_epsv = False gpgcadir = /var/lib/yum/repos/x86_64/7/nginx-mainline/gpgcadir gpgcakey = gpgcheck = True gpgdir = /var/lib/yum/repos/x86_64/7/nginx-mainline/gpgdir gpgkey = https://nginx.org/keys/nginx_signing.key hdrdir = /var/cache/yum/x86_64/7/nginx-mainline/headers http_caching = all includepkgs = ip_resolve = keepalive = True keepcache = False mddownloadpolicy = sqlite mdpolicy = group:small mediaid = metadata_expire = 21600 metadata_expire_filter = read-only:present metalink = minrate = 0 mirrorlist = mirrorlist_expire = 86400 name = nginx mainline repo old_base_cache_dir = password = persistdir = /var/lib/yum/repos/x86_64/7/nginx-mainline pkgdir = /var/cache/yum/x86_64/7/nginx-mainline/packages proxy = False proxy_dict = proxy_password = proxy_username = repo_gpgcheck = False retries = 10 skip_if_unavailable = False ssl_check_cert_permissions = True sslcacert = sslclientcert = sslclientkey = sslverify = True throttle = 0 timeout = 30.0 ui_id = nginx-mainline/7/x86_64 ui_repoid_vars = releasever, basearch username = #4.安装nginx [root@izwz97v6f2nxfmqc5cc8taz /]# yum install nginx Loaded plugins: fastestmirror nginx-mainline | 2.9 kB 00:00:00 nginx-stable | 2.9 kB 00:00:00 (1/2): nginx-stable/7/x86_64/primary_db | 63 kB 00:00:01 (2/2): nginx-mainline/7/x86_64/primary_db | 202 kB 00:00:01 Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package nginx.x86_64 1:1.20.0-1.el7.ngx will be installed --> Finished Dependency Resolution Dependencies Resolved =================================================================================================================================== Package Arch Version Repository Size =================================================================================================================================== Installing: nginx x86_64 1:1.20.0-1.el7.ngx nginx-stable 790 k Transaction Summary =================================================================================================================================== Install 1 Package Total download size: 790 k Installed size: 2.8 M Is this ok [y/d/N]: y #y 确认 Downloading packages: warning: /var/cache/yum/x86_64/7/nginx-stable/packages/nginx-1.20.0-1.el7.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY Public key for nginx-1.20.0-1.el7.ngx.x86_64.rpm is not installed nginx-1.20.0-1.el7.ngx.x86_64.rpm | 790 kB 00:00:02 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 Is this ok [y/N]: y #验证上两行的指纹是否与官网一致#573b fd6b 3d8f bc64 1079 a6ab abf5 bd82 7bd9 bf62# Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 1:nginx-1.20.0-1.el7.ngx.x86_64 1/1 ---------------------------------------------------------------------- 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 : 1:nginx-1.20.0-1.el7.ngx.x86_64 1/1 Installed: nginx.x86_64 1:1.20.0-1.el7.ngx Complete! #安装完成,默认安装成功后以启动 #5.可以查看nginx在哪 [root@izwz97v6f2nxfmqc5cc8taz /]# whereis nginx nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz

7. 参数解释及nginx启动

7.1 -t参数
复制代码
1
2
3
4
#在nginx的启动目录下,本文默认是/usr/sbin/目录下 #检查配置文件是否正确,若不正确则会提示 ./nginx -t
复制代码
1
2
3
4
[root@izwz97v6f2nxfmqc5cc8taz sbin]# ./nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
7.2 -V参数

可以查看nginx安装位置等信息,以及查看安装了哪些模块

复制代码
1
2
3
4
5
6
7
8
[root@izwz97v6f2nxfmqc5cc8taz sbin]# ./nginx -V nginx version: nginx/1.20.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' [root@izwz97v6f2nxfmqc5cc8taz sbin]#
7.3 启动nginx
复制代码
1
2
3
# 默认配置文件 conf/nginx.conf;通过-c参数可以指定配置文件 ./sbin/nginx
7.4 停止nginx
复制代码
1
2
3
4
5
#使用命令停止 ./sbin/nginx -s stop #或者直接kill -9 nignx进程id kill -9 nginx-pid
7.5 重启nginx
复制代码
1
2
3
#重启,不会改变启动时指定的配置文件 ./sbin/nginx -s reload

最后

以上就是鲜艳大米最近收集整理的关于CentOS系统使用yum安装Nginx服务器的全部内容,更多相关CentOS系统使用yum安装Nginx服务器内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(92)

评论列表共有 0 条评论

立即
投稿
返回
顶部