36 openEuler搭建repo服务器-部署远端repo源

36 openEuler搭建repo服务器-部署远端repo源36.1 nginx安装与配置36.2 启动nginx服务36.3 repo源部署

36 openEuler搭建repo服务器-部署远端repo源

安装openEuler操作系统,在openEuler上通过nginx部署repo源。

36.1 nginx安装与配置

  1. 在root权限下安装nginx。

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n8" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># dnf install -y nginx</pre>

例如示例命令如下:

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n10" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@repo ~]# dnf install -y nginx
Last metadata expiration check: 1:32:43 ago on 2022年11月29日 星期二 20时22分38秒.
Dependencies resolved.
=============================================================================================================================
Package Architecture Version Repository Size
=============================================================================================================================
Installing:
nginx x86_64 1:1.21.5-3.oe2203 update 498 k
Installing dependencies:
gd x86_64 2.3.2-2.oe2203 update 127 k
libXpm x86_64 3.5.13-1.oe2203 OS 41 k
libwebp x86_64 1.2.1-1.oe2203 OS 246 k
nginx-all-modules noarch 1:1.21.5-3.oe2203 update 7.6 k
nginx-filesystem noarch 1:1.21.5-3.oe2203 update 8.7 k
nginx-mod-http-image-filter x86_64 1:1.21.5-3.oe2203 update 18 k
nginx-mod-http-perl x86_64 1:1.21.5-3.oe2203 update 27 k
nginx-mod-http-xslt-filter x86_64 1:1.21.5-3.oe2203 update 17 k
nginx-mod-mail x86_64 1:1.21.5-3.oe2203 update 49 k
nginx-mod-stream x86_64 1:1.21.5-3.oe2203 update 71 k

Transaction Summary

Install 11 Packages

Total download size: 1.1 M
Installed size: 3.0 M
Downloading Packages:
(1/11): libXpm-3.5.13-1.oe2203.x86_64.rpm 187 kB/s | 41 kB 00:00
(2/11): libwebp-1.2.1-1.oe2203.x86_64.rpm 845 kB/s | 246 kB 00:00
(3/11): gd-2.3.2-2.oe2203.x86_64.rpm 427 kB/s | 127 kB 00:00
(4/11): nginx-all-modules-1.21.5-3.oe2203.noarch.rpm 155 kB/s | 7.6 kB 00:00
(5/11): nginx-filesystem-1.21.5-3.oe2203.noarch.rpm 179 kB/s | 8.7 kB 00:00
(6/11): nginx-mod-http-image-filter-1.21.5-3.oe2203.x86_64.rpm 368 kB/s | 18 kB 00:00
(7/11): nginx-mod-http-perl-1.21.5-3.oe2203.x86_64.rpm 519 kB/s | 27 kB 00:00
(8/11): nginx-mod-http-xslt-filter-1.21.5-3.oe2203.x86_64.rpm 350 kB/s | 17 kB 00:00
(9/11): nginx-mod-mail-1.21.5-3.oe2203.x86_64.rpm 498 kB/s | 49 kB 00:00
(10/11): nginx-mod-stream-1.21.5-3.oe2203.x86_64.rpm 1.2 MB/s | 71 kB 00:00
(11/11): nginx-1.21.5-3.oe2203.x86_64.rpm 1.6 MB/s | 498 kB 00:00


Total 2.0 MB/s | 1.1 MB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: nginx-filesystem-1:1.21.5-3.oe2203.noarch 1/11
Installing : nginx-filesystem-1:1.21.5-3.oe2203.noarch 1/11
Installing : libwebp-1.2.1-1.oe2203.x86_64 2/11
Installing : libXpm-3.5.13-1.oe2203.x86_64 3/11
Installing : gd-2.3.2-2.oe2203.x86_64 4/11
Running scriptlet: gd-2.3.2-2.oe2203.x86_64 4/11
Installing : nginx-mod-http-perl-1:1.21.5-3.oe2203.x86_64 5/11
Running scriptlet: nginx-mod-http-perl-1:1.21.5-3.oe2203.x86_64 5/11
Installing : nginx-mod-http-xslt-filter-1:1.21.5-3.oe2203.x86_64 6/11
Running scriptlet: nginx-mod-http-xslt-filter-1:1.21.5-3.oe2203.x86_64 6/11
Installing : nginx-mod-mail-1:1.21.5-3.oe2203.x86_64 7/11
Running scriptlet: nginx-mod-mail-1:1.21.5-3.oe2203.x86_64 7/11
Installing : nginx-mod-stream-1:1.21.5-3.oe2203.x86_64 8/11
Running scriptlet: nginx-mod-stream-1:1.21.5-3.oe2203.x86_64 8/11
Installing : nginx-1:1.21.5-3.oe2203.x86_64 9/11
Running scriptlet: nginx-1:1.21.5-3.oe2203.x86_64 9/11
Installing : nginx-mod-http-image-filter-1:1.21.5-3.oe2203.x86_64 10/11
Running scriptlet: nginx-mod-http-image-filter-1:1.21.5-3.oe2203.x86_64 10/11
Installing : nginx-all-modules-1:1.21.5-3.oe2203.noarch 11/11
Running scriptlet: nginx-all-modules-1:1.21.5-3.oe2203.noarch 11/11
Verifying : libXpm-3.5.13-1.oe2203.x86_64 1/11
Verifying : libwebp-1.2.1-1.oe2203.x86_64 2/11
Verifying : gd-2.3.2-2.oe2203.x86_64 3/11
Verifying : nginx-1:1.21.5-3.oe2203.x86_64 4/11
Verifying : nginx-all-modules-1:1.21.5-3.oe2203.noarch 5/11
Verifying : nginx-filesystem-1:1.21.5-3.oe2203.noarch 6/11
Verifying : nginx-mod-http-image-filter-1:1.21.5-3.oe2203.x86_64 7/11
Verifying : nginx-mod-http-perl-1:1.21.5-3.oe2203.x86_64 8/11
Verifying : nginx-mod-http-xslt-filter-1:1.21.5-3.oe2203.x86_64 9/11
Verifying : nginx-mod-mail-1:1.21.5-3.oe2203.x86_64 10/11
Verifying : nginx-mod-stream-1:1.21.5-3.oe2203.x86_64 11/11

Installed:
gd-2.3.2-2.oe2203.x86_64 libXpm-3.5.13-1.oe2203.x86_64
libwebp-1.2.1-1.oe2203.x86_64 nginx-1:1.21.5-3.oe2203.x86_64
nginx-all-modules-1:1.21.5-3.oe2203.noarch nginx-filesystem-1:1.21.5-3.oe2203.noarch
nginx-mod-http-image-filter-1:1.21.5-3.oe2203.x86_64 nginx-mod-http-perl-1:1.21.5-3.oe2203.x86_64
nginx-mod-http-xslt-filter-1:1.21.5-3.oe2203.x86_64 nginx-mod-mail-1:1.21.5-3.oe2203.x86_64
nginx-mod-stream-1:1.21.5-3.oe2203.x86_64

Complete!
[root@repo ~]# </pre>

  1. 在root权限下配置/etc/nginx/nginx.conf。

[图片上传失败...(image-8ea42-1678547420821)]

说明: 文档中的配置内容仅供参考,请用户根据实际情况(例如安全加固需要)进行配置。

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n16" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># vi /etc/nginx/nginx.conf</pre>

例如示例命令如下:

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n18" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@repo ~]# cat /etc/nginx/nginx.conf

For more information on configuration, see:

* Official English Documentation: http://nginx.org/en/docs/

* Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
log_format main 'remote_addr -remote_user [time_local] "request" '
'statusbody_bytes_sent "http_referer" ' '"http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;

include /etc/nginx/mime.types;
default_type application/octet-stream;

Load modular configuration files from the /etc/nginx/conf.d directory.

See http://nginx.org/en/docs/ngx_core_module.html#include

for more information.

include /etc/nginx/conf.d/*.conf;

server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/repo;

location / {
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
}

Load configuration files for the default server block.

include /etc/nginx/default.d/*.conf;

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

Settings for a TLS enabled server.

server {

listen 443 ssl http2;

listen [::]:443 ssl http2;

server_name _;

root /usr/share/nginx/html;

ssl_certificate "/etc/pki/nginx/server.crt";

ssl_certificate_key "/etc/pki/nginx/private/server.key";

ssl_session_cache shared:SSL:1m;

ssl_session_timeout 10m;

ssl_ciphers PROFILE=SYSTEM;

ssl_prefer_server_ciphers on;

# Load configuration files for the default server block.

include /etc/nginx/default.d/*.conf;

error_page 404 /404.html;

location = /40x.html {

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

}

}

}

[root@repo ~]# </pre>

36.2 启动nginx服务

  1. 在root权限下通过systemd启动nginx服务。

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n23" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># systemctl enable nginx

systemctl start nginx</pre>

例如示例命令如下:

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n25" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@repo ~]# systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
[root@repo ~]#
[root@repo ~]# systemctl start nginx
[root@repo ~]# </pre>

  1. nginx是否启动成功可通过下面命令查看。

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n29" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># systemctl status nginx</pre>

  • 图1 表示nginx服务启动成功:

    图 1 nginx服务启动成功 [图片上传失败...(image-94b9e2-1678547420821)]

  • 若nginx服务启动失败,查看错误信息并整改。

<pre class="md-fences md-end-block ty-contain-cm modeLoaded" spellcheck="false" lang="bash" cid="n36" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># systemctl status nginx.service --full</pre>

36.3 repo源部署

  1. 在root权限下创建nginx配置文件/etc/nginx/nginx.conf中指定的目录/usr/share/nginx/repo。

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n41" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># mkdir -p /usr/share/nginx/repo</pre>

例如示例命令如下:

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n43" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@repo ~]# mkdir -p /usr/share/nginx/repo
[root@repo ~]#</pre>

  1. 在root权限下修改目录/usr/share/nginx/repo的权限。

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n47" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># chmod -R 755 /usr/share/nginx/repo</pre>

例如示例命令如下:

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n49" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@repo ~]# chmod -R 755 /usr/share/nginx/repo
[root@repo ~]# </pre>

  1. 设置防火墙规则,开启nginx设置的端口(此处为80端口),在root权限下通过firewall设置端口开启。

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n53" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># firewall-cmd --add-port=80/tcp --permanent

firewall-cmd --reload</pre>

例如示例命令如下:

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n55" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@repo ~]# firewall-cmd --add-port=80/tcp --permanent
success
[root@repo ~]#
[root@repo ~]# firewall-cmd --reload
success
[root@repo ~]# </pre>

  1. 在root权限下查询80端口是否开启成功,输出为yes则表示80端口开启成功。

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n59" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># firewall-cmd --query-port=80/tcp</pre>

例如示例命令如下:

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n61" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@repo ~]# firewall-cmd --query-port=80/tcp
yes
[root@repo ~]#</pre>

或者也可在root权限下通过iptables来设置80端口开启,本次不使用iptables,只做了解

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="bash" cid="n63" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># iptables -I INPUT -p tcp --dport 80 -j ACCEPT</pre>

  1. nginx服务设置好之后,即可通过ip直接访问网页,如图2

图 2 nginx部署成功 [图片上传失败...(image-2e625f-1678547420821)]

  1. 通过下面几种方式将repo源放入到/usr/share/nginx/repo下:
  • 在root权限下拷贝镜像中相关文件至/usr/share/nginx/repo下,并修改目录权限。

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="" cid="n74" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># mount -o loop /home/openEuler-22.03-LTS-everything-x86_64-dvd.iso /mnt

cp -r /mnt/* /usr/share/nginx/repo

chmod -R 755 /usr/share/nginx/repo</pre>

例如示例命令如下:

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="" cid="n76" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@repo ~]# mount -o loop /home/openEuler-22.03-LTS-everything-x86_64-dvd.iso /mnt
mount: /mnt: WARNING: source write-protected, mounted read-only.
[root@repo ~]#
[root@repo ~]# cp -r /mnt/* /usr/share/nginx/repo
[root@repo ~]#
[root@repo ~]# chmod -R 755 /usr/share/nginx/repo
[root@repo ~]# </pre>

openEuler-22.03-LTS-everything-x86_64-dvd.iso存放在/home目录下。

  • 使用root在/usr/share/nginx/repo下创建repo源的软链接。

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="" cid="n81" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"># ln -s /home/repo/* /usr/share/nginx/repo/</pre>

/home/repo为已经创建好的repo源,/usr/share/nginx/repo/将指向/home/repo。

例如示例命令如下:

<pre class="md-fences mock-cm md-end-block" spellcheck="false" lang="" cid="n84" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: pre-wrap; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; color: rgb(51, 51, 51); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">[root@repo ~]# ln -s /home/repo/* /usr/share/nginx/repo/
[root@repo ~]#</pre>

👍 点赞,你的认可是我创作的动力!

⭐️ 收藏,你的青睐是我努力的方向!

✏️ 评论,你的意见是我进步的财富!

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容