Centos 部署本地repo服务器

一、关闭Centos防火墙及SELINUX

1、关闭防火墙

systemctl stop firewalld.service       
systemctl disable firewalld.service

2、关闭SELINX

vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing  //#标记掉
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
#SELINUXTYPE=targeted
SELINUX=disabled

二、建立repo存放位置

mkdir /opt/Mirrors
cd /opt/Mirrors
mkdir Centos Nginx Saltstack Ubuntu EPEL MySQL Zabbix

三、安装配置Nginx

1、添加Nginx源

vi /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

2、安装Nginx

yum install nginx -y

3、启动Nginx

systemctl start nginx

4、配置Nginx

vi /etc/nginx/conf.d/default.conf
server {
    listen       80;           
    server_name  localhost;
    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
         autoindex on;                 \\开启目录浏览功能
         autoindex_exact_size off;      \\默认为on,显示出文件的确切大小,单位是bytes。改为off后,显示出文件的大概大小,单位是kB或者MB或者GB
         autoindex_localtime on;        \\默认为off,显示的文件时间为GMT时间。改为on后,显示的文件时间为文件的服务器时间
         charset utf-8;                  \\支持中文
         root   /opt/Mirrors;            \\Mirrors存放路径
#        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
#        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

5、重启Nginx

systemctl stop nginx
systemctl start nginx

四、安装rsync

yum install rsync -y

五、写同步脚本

vi /opt/mirrors.sh
#!/bin/sh
/usr/bin/rsync -artP rsync://mirrors.tuna.tsinghua.edu.cn/centos/ /opt/Mirrors/Centos/
/usr/bin/rsync -artP rsync://mirrors.tuna.tsinghua.edu.cn/epel/ /opt/Mirrors/EPEL/
/usr/bin/rsync -artP rsync://mirrors.tuna.tsinghua.edu.cn/zabbix/ /opt/Mirrors/Zabbix/
/usr/bin/rsync -artP rsync://mirrors.tuna.tsinghua.edu.cn/ubuntu/ /opt/Mirrors/Ubuntu/
/usr/bin/rsync -artP rsync://mirrors.tuna.tsinghua.edu.cn/saltstack/ /opt/Mirrors/Saltstack/
/usr/bin/rsync -artP rsync://rsync.mirrors.ustc.edu.cn/repo/nginx/ /opt/Mirrors/Nginx/
/usr/bin/rsync -artP rsync://rsync.mirrors.ustc.edu.cn/repo/mysql-repo/ /opt/Mirrors/MySQL/

修改脚本执行权限

chmod a+x /opt/mirrors.sh

注:rsynx 参数

-v:显示rsync过程中详细信息。可以使用"-vvvv"获取更详细信息。
-P:显示文件传输的进度信息。(实际上"-P"=“–partial --progress”,其中的"–progress"才是显示进度信息的)。
-n --dry-run :仅测试传输,而不实际传输。常和"-vvvv"配合使用来查看rsync是如何工作的。
-a --archive :归档模式,表示递归传输并保持文件属性。等同于"-rtopgDl"。
-r --recursive:递归到目录中去。
-t --times:保持mtime属性。强烈建议任何时候都加上"-t",否则目标文件mtime会设置为系统时间,导致下次更新
:检查出mtime不同从而导致增量传输无效。
-o --owner:保持owner属性(属主)。
-g --group:保持group属性(属组)。
-p --perms:保持perms属性(权限,不包括特殊权限)。
-D :是"–device --specials"选项的组合,即也拷贝设备文件和特殊文件。
-l --links:如果文件是软链接文件,则拷贝软链接本身而非软链接所指向的对象。
-z :传输时进行压缩提高效率。
-R --relative:使用相对路径。意味着将命令行中指定的全路径而非路径最尾部的文件名发送给服务端,包括它们的属性。用法见下文示例。
–size-only :默认算法是检查文件大小和mtime不同的文件,使用此选项将只检查文件大小。
-u --update :仅在源mtime比目标已存在文件的mtime新时才拷贝。注意,该选项是接收端判断的,不会影响删除行为。
-d --dirs :以不递归的方式拷贝目录本身。默认递归时,如果源为"dir1/file1",则不会拷贝dir1目录,使用该选项将拷贝dir1但不拷贝file1。
–max-size :限制rsync传输的最大文件大小。可以使用单位后缀,还可以是一个小数值(例如:“–max-size=1.5m”)
–min-size :限制rsync传输的最小文件大小。这可以用于禁止传输小文件或那些垃圾文件。
–exclude :指定排除规则来排除不需要传输的文件。
–delete :以SRC为主,对DEST进行同步。多则删之,少则补之。注意"–delete"是在接收端执行的,所以它是在
:exclude/include规则生效之后才执行的。
-b --backup :对目标上已存在的文件做一个备份,备份的文件名后默认使用"~“做后缀。
–backup-dir:指定备份文件的保存路径。不指定时默认和待备份文件保存在同一目录下。
-e :指定所要使用的远程shell程序,默认为ssh。
–port :连接daemon时使用的端口号,默认为873端口。
–password-file:daemon模式时的密码文件,可以从中读取密码实现非交互式。注意,这不是远程shell认证的密码,而是rsync模块认证的密码。
-W --whole-file:rsync将不再使用增量传输,而是全量传输。在网络带宽高于磁盘带宽时,该选项比增量传输更高效。
–existing :要求只更新目标端已存在的文件,目标端还不存在的文件不传输。注意,使用相对路径时如果上层目录不存在也不会传输。
–ignore-existing:要求只更新目标端不存在的文件。和”–existing"结合使用有特殊功能,见下文示例。
–remove-source-files:要求删除源端已经成功传输的文件。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值