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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了36 openEuler搭建repo服务器-部署远端repo源相关的知识,希望对你有一定的参考价值。

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

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

36.1 nginx安装与配置

  1. 在root权限下安装nginx。
# dnf install -y nginx

例如示例命令如下:

[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 ~]# 
  1. 在root权限下配置/etc/nginx/nginx.conf。
# vi /etc/nginx/nginx.conf

例如示例命令如下:

[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" 
                      $status $body_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 ~]# 

36.2 启动nginx服务

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

例如示例命令如下:

[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 ~]# 
  1. nginx是否启动成功可通过下面命令查看。
# systemctl status nginx
  • 图1 表示nginx服务启动成功:

    图 1 nginx服务启动成功

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

# systemctl status nginx.service --full

36.3 repo源部署

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

例如示例命令如下:

[root@repo ~]# mkdir -p /usr/share/nginx/repo
[root@repo ~]#
  1. 在root权限下修改目录/usr/share/nginx/repo的权限。
# chmod -R 755 /usr/share/nginx/repo

例如示例命令如下:

[root@repo ~]# chmod -R 755 /usr/share/nginx/repo
[root@repo ~]# 
  1. 设置防火墙规则,开启nginx设置的端口(此处为80端口),在root权限下通过firewall设置端口开启。
# firewall-cmd --add-port=80/tcp --permanent
# firewall-cmd --reload

例如示例命令如下:

[root@repo ~]# firewall-cmd --add-port=80/tcp --permanent
success
[root@repo ~]# 
[root@repo ~]# firewall-cmd --reload
success
[root@repo ~]# 
  1. 在root权限下查询80端口是否开启成功,输出为yes则表示80端口开启成功。
# firewall-cmd --query-port=80/tcp

例如示例命令如下:

[root@repo ~]# firewall-cmd --query-port=80/tcp
yes
[root@repo ~]#

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

# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
  1. nginx服务设置好之后,即可通过ip直接访问网页,如图2

图 2 nginx部署成功

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

例如示例命令如下:

[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 ~]# 

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

  • 使用root在/usr/share/nginx/repo下创建repo源的软链接。
# ln -s /home/repo/* /usr/share/nginx/repo/

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

例如示例命令如下:

[root@repo ~]# ln -s /home/repo/* /usr/share/nginx/repo/
[root@repo ~]#

以上是关于36 openEuler搭建repo服务器-部署远端repo源的主要内容,如果未能解决你的问题,请参考以下文章

openeuler

49 openEuler搭建PostgreSQL数据库服务器-软件介绍

G026-DB-GS-INS-03 OpenEuler 部署 OpenGauss(1主2备或多备)

43 openEuler搭建Apache服务器-配置文件说明和管理模块

Kubeadm 快速搭建 k8s v1.24.1 集群(openEuler 22.03 LTS)

39 openEuler搭建FTP服务器-安装管理vsftpd服务