zoukankan      html  css  js  c++  java
  • linux搭建yum仓库

    Linux9期基础-day25

    搭建yum仓库

    # 关闭防火墙和selinux
    [root@qls yum.repos.d]# systemctl stop firewalld
    [root@qls yum.repos.d]# setenforce 0
    
    ## 搭建yum仓库的三种方式
    # 方案一:vsftpd服务实现yum仓库 (ftp://)
    # 1.安装vsftpd
    [root@qls yum.repos.d]# yum install -y vsftpd
    # 2.启动服务
    [root@qls yum.repos.d]# systemctl start vsftpd
    # 3.检查端口
    [root@qls yum.repos.d]# netstat -lntup|grep 21
    tcp6       0      0 :::21                   :::*                    LISTEN      8433/vsftpd 
    # 4.安装创建yum仓库的命令
    [root@qls pub]# yum install -y createrepo
    # 5.制作成yum仓库
    [root@qls pub]# createrepo /var/ftp/pub/base/
    # 6.在客户机上配置yum仓库
    [root@qls yum.repos.d]# vi zls_vsftpd.repo 
    [zls_vsftpd]
    name='This is zls's vsftpd repository'
    baseurl=ftp://10.0.0.150/pub/base/
    gpgcheck=0
    enabled=1
    
    # 方案二:本地,挂载光盘镜像 (file://)
    # 1.将光盘插入光驱
    

    1587000990081

    # 2.挂载光驱
    [root@qls pub]# mount /dev/cdrom /mnt
    mount: /dev/sr0 is write-protected, mounting read-only
    # 3.创建yum仓库
    [root@qls pub]# createrepo /var/ftp/pub/zabbix/
    # 4.配置yum源
    [root@qls yum_repo]# vi /etc/yum.repos.d/zls_local.repo
    [zls_local]
    name=123
    baseurl=file:///opt/yum_repo/
    gpgcheck=0
    enabled=1
    
    # 方案三:nginx服务搭建yum仓库
    # 1.安装nginx
    [root@qls conf.d]# yum install -y nginx
    # 2.删除nginx的conf.d下默认配置文件
    [root@qls conf.d]# rm -fr /etc/nginx/conf.d/*
    # 3.配置nginx配置文件
    [root@qls conf.d]# vim /etc/nginx/conf.d/yum.conf
    server {
            listen 80;
            server_name www.drz.com;
            root /kpw_dsb;
            autoindex on;
    }
    # 4.创建站点目录
    [root@qls conf.d]# mkdir /kpw_dsb
    # 5.启动nginx服务
    [root@qls kpw_dsb]# systemctl start nginx
    # 6.配置域名解析
    按 windows + r 打开运行,输入 'drivers'
    

    1587002458268

    1587002478270

    1587002525146

    1587002546499

    # 7.创建yum仓库
    [root@qls nginx]# createrepo /kpw_dsb
    # 8.手写repo文件
    [root@qls yum.repos.d]# vi zls_nginx.repo
    [zls_nginx]
    name=456
    baseurl=http://www.drz.com/
    gpgcheck=0
    enabled=1
    # 9.在客户机配置域名解析
    [root@qls yum.repos.d]# vi /etc/hosts
    10.0.0.150 www.drz.com
    

    自制RPM包

    ## 源码安装nginx
    # 0.安装依赖
    [root@qls nginx-1.16.1]# yum install -y gcc gcc-c++ glibc zlib-devel pcre-devel openssl-devel
    # 1.下载nginx源码包
    [root@qls ~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
    # 2.解压
    [root@qls ~]# tar xf nginx-1.16.1.tar.gz 
    [root@qls ~]# cd nginx-1.16.1
    # 3.生成
    [root@qls ~]# mkdir /app
    [root@qls nginx-1.16.1]# useradd nginx -s /sbin/nologin -M
    [root@qls nginx-1.16.1]# ./configure --prefix=/app/nginx-1.16.1 --user=nginx --group=nginx
    # 4.编译
    [root@qls nginx-1.16.1]# make
    # 5.安装
    [root@qls nginx-1.16.1]# make install
    # 6.检测配置文件有没有语法错误
    [root@qls sbin]# /app/nginx-1.16.1/sbin/nginx -t
    nginx: the configuration file /app/nginx-1.16.1/conf/nginx.conf syntax is ok
    nginx: configuration file /app/nginx-1.16.1/conf/nginx.conf test is successful
    # 7.启动nginx
    [root@qls sbin]# /app/nginx-1.16.1/sbin/nginx
    # 8.检测80端口
    [root@qls sbin]# netstat -lntup|grep 80
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      13468/nginx: master
    # 9.做软连接
    [root@qls nginx-1.16.1]# ln -s /app/nginx-1.16.1 /app/nginx
    
    ## 自定义
    # 修改默认页面
    [root@qls html]# vim /app/nginx-1.16.1/html/index.html
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8"/>
    <title>欢迎来到曾老湿的nginx页面</title>
    <style>
        body {
             35em;
            margin: 0 auto;
            font-family: Tahoma, Verdana, Arial, sans-serif;
        }
    </style>
    </head>
    <body>
    <h1>欢迎来到曾老湿nginx的web页面</h1>
    <a href="http://www.driverzeng.com">我的博客地址</a>.<br/>
    <p><em>Thank you for using nginx.</em></p>
    </body>
    </html>
    
    
    ## 制作rpm包
    [root@qls ~]# mkdir fpm
    [root@qls ~]# mv fpm-1.3.3.x86_64.tar.gz fpm
    [root@qls fpm]# cd /root/fpm/
    
    # 1. 解压
    [root@qls fpm]# tar xf fpm-1.3.3.x86_64.tar.gz 
    # 2.安装ruby
    [root@qls fpm]# yum -y install ruby rubygems ruby-devel rpm-build
    # 3.查看gem的源
    [root@qls fpm]# gem sources --list
    *** CURRENT SOURCES ***
    
    https://rubygems.org/
    
    # 4.更换阿里云的源 先移除国外源
    [root@qls fpm]# gem sources --remove https://rubygems.org/
    
    # 5.更换阿里云的源, 添加阿里云的源
    [root@qls fpm]# gem sources -a https://mirrors.aliyun.com/rubygems/
    
    # 6.使用gem命令安装当前目录下所有的.gem文件
    [root@qls fpm]# gem install *.gem
    # 7.写出安装rpm之后要执行的脚本
    [root@qls ~]# vim /root/nginx.sh
    #!/bin/bash
    useradd nginx -s /sbin/nologin -M
    ln -s /app/nginx-1.16.1 /app/nginx
    # 8.使用fpm打包
    [root@qls fpm]# fpm -s dir -t rpm -n nginx -v 1.16.1 -d 'zlib-devel,gcc,gcc-c++,glibc,pcre-devel,openssl-devel' --post-install /root/nginx.sh -f /app/nginx-1.16.1/
    
    fpm:打rpm包命令
    -s:dir     # 打目录
    -t:rpm     # 把目录打成rpm包
    -n:nginx   # 软件名字叫nginx
    -v:1.16.1  # 软件的版本号
    -d:        # 指定nginx的依赖包
    -f:        # 指定要达成rpm包的目录路径
    --post-install # 指定rpm包安装完成之后要执行的脚本
    --pre-install  # 指定rpm包安装之前,要执行的脚本
    

    1587012215576

    yum install -y rpm-build
    
    fpm -s dir -t rpm -n nginx -v 1.16.1 -d 'zlib-devel,pcre-devel,openssl-devel' --post-install /root/nginx.sh -f /app/nginx-1.16.1/
    
    -d zlib-devel,gcc,gcc-c++,glibc,pcre-devel,openssl-devel
    ## 安装nginx的rpm包,需要以上依赖。
    

    同步中科大源

    # 安装rsync同步工具
    [root@qls nginx2]# yum install -y rsync
    
    # 同步
    rsync -avzP rsync://rsync.mirrors.ustc.edu.cn/repo/centos ./
    rsync -avzP rsync://rsync.mirrors.ustc.edu.cn/repo/nginx ./
    rsync -avzP rsync://rsync.mirrors.ustc.edu.cn/repo/epel ./
    
    # 拉全部
    rsync -avzP rsync://rsync.mirrors.ustc.edu.cn/repo/ ./
    
  • 相关阅读:
    2. linux下如何上传和下载文件
    (六)使用Docker镜像(下)
    (五)使用Docker镜像(上)
    1. chmod命令
    阿里P7/P8学习路线图——技术封神之路
    问题二:pip install python-igraph 报错,C core of igraph 没有安装。
    问题一:【Hive】explain command throw ClassCastException in 2.3.4
    (四)docker创建私人仓库
    P5024 保卫王国
    jzoj5980. 【WC2019模拟12.27】字符串游戏
  • 原文地址:https://www.cnblogs.com/zabcd/p/13289832.html
Copyright © 2011-2022 走看看