Software necessários e configuração inicial
# yum install httpd createrepo rsync policycoreutils-python
# chkconfig httpd on # service httpd start
# iptables -I INPUT 5 -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT # service iptables save
Repotitórios disponíveis Para encontra uma lista de repositórios rsync acesse o site http://www.centos.org/download/mirrors/. Checando a estrutura de diretório do repositório escolhido.
Lendo os repositórios
# rsync rsync://centos.ufms.br/CentOS # rsync rsync://centos.ufms.br/CentOS/7/
# cat /srv/scripts/mirror_centos6.sh #!/bin/bash SOURCE1="rsync://centos.ufms.br/CentOS/6" SOURCE2="rsync://centos.ufms.br/CentOS/6.7" TARGET="/var/www/html/centos" CREATE="createrepo_centos6.sh" LOGS="/var/log/mirror" LOGOFILE="/var/log/mirror/centos_6.log" MAILNOTIFY="gean@rascunhos.wiki.br" DEBUGFILE="/var/log/mirror/centos_6.debug" MAILSUBJECT="ERRO Repositorio CentOS 6" LOCKFILE="/var/log/mirror/centos_6.lock" # funcao para registrar os logs function log() { echo `date +%d.%m.%Y%t%H:%M:%S` " LOG:" $1 | tee -a ${LOGFILE} } # Cria o diretorio mirror se ele nao existir if [ ! -d ${LOGS} ] ; then log "Diretorio de logs criado." mkdir -p ${LOGS} fi # funcao para registrar os erros function error() { echo `date +%d.%m.%Y%t%H:%M:%S` " ERROR:" $1 | tee -a ${LOGFILE} if [ -n "${MAILNOTIFY}" ] ; then echo `date +%d.%m.%Y%t%H:%M:%S` " ERROR:" $1 | mail -s "${MAILSUBJECT}" ${MAILNOTIFY} fi } # funcao para registrar o status function status() { case "$1" in 0) log "Synchronization completed." ;; 1) error "RSYNC: Syntax or usage error." ;; 2) error "RSYNC: Protocol incompatibility." ;; 3) error "RSYNC: Errors selecting input/output files, dirs." ;; 4) error "RSYNC: Requested action not supported: an attempt was made to manipulate 64-bit files on a platform that cannot support them; or an option was specified that is supported by the client and not by the server." ;; 5) error "RSYNC: Error starting client-server protocol." ;; 6) error "RSYNC: Daemon unable to append to log-file." ;; 10) error "RSYNC: Error in socket I/O." ;; 11) error "RSYNC: Error in file I/O." ;; 12) error "RSYNC: Error in rsync protocol data stream." ;; 13) error "RSYNC: Errors with program diagnostics." ;; 14) error "RSYNC: Error in IPC code." ;; 20) error "RSYNC: Received SIGUSR1 or SIGINT." ;; 21) error "RSYNC: Some error returned by waitpid()." ;; 22) error "RSYNC: Error allocating core memory buffers." ;; 23) error "RSYNC: Partial transfer due to error." ;; 24) error "RSYNC: Partial transfer due to vanished source files." ;; 25) error "RSYNC: The --max-delete limit stopped deletions." ;; 30) error "RSYNC: Timeout in data send/receive." ;; *) error "RSYNC: Unknown error $1." ;; esac } if [ -f ${LOCKFILE} ] ; then kill -0 $(cat ${LOCKFILE}) >/dev/null 2>&1 if [ $? -eq 0 ] ; then error "Previous process still running." exit 1 else log "Deprecated lock file found. Remove lock file." rm -f ${LOCKFILE} fi fi echo $$ >${LOCKFILE} # Create local mirror directories if not exists if [ ! -d ${TARGET} ] ; then log "Diretorio do repositorio criado." mkdir -p ${TARGET} fi #Comando rsync log "Iniciando o download do repositorio CentOS 6." >> ${DEBUGFILE} 2>&1 echo ">>>>>" `date +%d.%m.%Y%t%H:%M:%S` "<<<<<" >>${DEBUGFILE} rsync -av --bwlimit=4096 --exclude=repodata --exclude=debug --exclude=isos ${SOURCE1} ${TARGET} >> ${DEBUGFILE} 2>&1 rsync -av --bwlimit=4096 --exclude=repodata --exclude=debug --exclude=isos ${SOURCE2} ${TARGET} >> ${DEBUGFILE} 2>&1 status $? #usa o cat para esvaziar o arquivo $CRIAR. cat /dev/null > $CREATE # cria o script para executar pos download cat << EOF > $CREATE #!/bin/bash #Esse script executa o comando createrepo em todos os diretórios com arquivos .rpm. # Criado em: `date` EOF # aqui buscamos os arquivos das arquiteturar x86_64 e i386 para rodarmos o createrepo # isso evita erro no clientes find /var/www/html/centos/6/ -name "x86_64" >> $CREATE find /var/www/html/centos/6/ -name "i386" >> $CREATE # colocando o createrepo ates do var # na primeira execucao atere createrepo --update para createrepo sed -i "s/\/var/createrepo --update \/var/g" $CREATE # Alterando as permissoes e executando chmod 750 $CREATE log "Iniciando a criacao da base de dados." >> ${DEBUGFILE} 2>&1 echo ">>>>>" `date +%d.%m.%Y%t%H:%M:%S` "<<<<<" >>${DEBUGFILE} /bin/bash $CREATE status $? rm -f ${LOCKFILE} exit 0
# tail -f /var/log/mirror/centos_6.debug
# cat /srv/scripts/mirror_centos7.sh #!/bin/bash SOURCE1="rsync://centos.ufms.br/CentOS/7" SOURCE2="rsync://centos.ufms.br/CentOS/7.1.1503" TARGET="/var/www/html/centos" CREATE="createrepo_centos7.sh" LOGS="/var/log/mirror" LOGOFILE="/var/log/mirror/centos_7.log" MAILNOTIFY="gean@rascunhos.wiki.br" DEBUGFILE="/var/log/mirror/centos_7.debug" MAILSUBJECT="ERRO Repositorio CentOS 7" LOCKFILE="/var/log/mirror/centos_7.lock" # funcao para registrar os logs function log() { echo `date +%d.%m.%Y%t%H:%M:%S` " LOG:" $1 | tee -a ${LOGFILE} } # Cria o diretorio mirror se ele nao existir if [ ! -d ${LOGS} ] ; then log "Diretorio de logs criado." mkdir -p ${LOGS} fi # funcao para registrar os erros function error() { echo `date +%d.%m.%Y%t%H:%M:%S` " ERROR:" $1 | tee -a ${LOGFILE} if [ -n "${MAILNOTIFY}" ] ; then echo `date +%d.%m.%Y%t%H:%M:%S` " ERROR:" $1 | mail -s "${MAILSUBJECT}" ${MAILNOTIFY} fi } # funcao para registrar o status function status() { case "$1" in 0) log "Synchronization completed." ;; 1) error "RSYNC: Syntax or usage error." ;; 2) error "RSYNC: Protocol incompatibility." ;; 3) error "RSYNC: Errors selecting input/output files, dirs." ;; 4) error "RSYNC: Requested action not supported: an attempt was made to manipulate 64-bit files on a platform that cannot support them; or an option was specified that is supported by the client and not by the server." ;; 5) error "RSYNC: Error starting client-server protocol." ;; 6) error "RSYNC: Daemon unable to append to log-file." ;; 10) error "RSYNC: Error in socket I/O." ;; 11) error "RSYNC: Error in file I/O." ;; 12) error "RSYNC: Error in rsync protocol data stream." ;; 13) error "RSYNC: Errors with program diagnostics." ;; 14) error "RSYNC: Error in IPC code." ;; 20) error "RSYNC: Received SIGUSR1 or SIGINT." ;; 21) error "RSYNC: Some error returned by waitpid()." ;; 22) error "RSYNC: Error allocating core memory buffers." ;; 23) error "RSYNC: Partial transfer due to error." ;; 24) error "RSYNC: Partial transfer due to vanished source files." ;; 25) error "RSYNC: The --max-delete limit stopped deletions." ;; 30) error "RSYNC: Timeout in data send/receive." ;; *) error "RSYNC: Unknown error $1." ;; esac } if [ -f ${LOCKFILE} ] ; then kill -0 $(cat ${LOCKFILE}) >/dev/null 2>&1 if [ $? -eq 0 ] ; then error "Previous process still running." exit 1 else log "Deprecated lock file found. Remove lock file." rm -f ${LOCKFILE} fi fi echo $$ >${LOCKFILE} # Create local mirror directories if not exists if [ ! -d ${TARGET} ] ; then log "Diretorio do repositorio criado." mkdir -p ${TARGET} fi #Comando rsync log "Iniciando o download do repositorio CentOS 7." >> ${DEBUGFILE} 2>&1 echo ">>>>>" `date +%d.%m.%Y%t%H:%M:%S` "<<<<<" >>${DEBUGFILE} rsync -av --bwlimit=4096 --exclude=repodata --exclude=debug --exclude=isos ${SOURCE1} ${TARGET} >> ${DEBUGFILE} 2>&1 rsync -av --bwlimit=4096 --exclude=repodata --exclude=debug --exclude=isos ${SOURCE2} ${TARGET} >> ${DEBUGFILE} 2>&1 status $? #usa o cat para esvaziar o arquivo $CRIAR. cat /dev/null > $CREATE # cria o script para executar pos download cat << EOF > $CREATE #!/bin/bash #Esse script executa o comando createrepo em todos os diretórios com arquivos .rpm. # Criado em: `date` EOF # aqui buscamos os arquivos das arquiteturar x86_64 para rodarmos o createrepo # isso evita erro no clientes find /var/www/html/centos/7/ -name "x86_64" >> $CREATE # colocando o createrepo ates do var # na primeira execucao atere createrepo --update para createrepo sed -i "s/\/var/createrepo --update \/var/g" $CREATE # Alterando as permissoes e executando chmod 750 $CREATE log "Iniciando a criacao da base de dados." >> ${DEBUGFILE} 2>&1 echo ">>>>>" `date +%d.%m.%Y%t%H:%M:%S` "<<<<<" >>${DEBUGFILE} /bin/bash $CREATE status $? rm -f ${LOCKFILE} exit 0
# tail -f /var/log/mirror/centos_7.debug
# cat /srv/scripts/mirror_epel6.sh #!/bin/bash SOURCE="rsync://mirrors.rit.edu/epel/6" TARGET="/var/www/html/epel" CREATE="createrepoepel6.sh" LOGS="/var/log/mirror" LOGOFILE="/var/log/mirror/epel_6.log" MAILNOTIFY="gean@rascunhos.wiki.br" DEBUGFILE="/var/log/mirror/epel_6.debug" MAILSUBJECT="ERRO Repositorio epel CentOS 6" LOCKFILE="/var/log/mirror/epel_6.lock" # funcao para registrar os logs function log() { echo `date +%d.%m.%Y%t%H:%M:%S` " LOG:" $1 | tee -a ${LOGFILE} } # Cria o diretorio mirror se ele nao existir if [ ! -d ${LOGS} ] ; then log "Diretorio de logs criado." mkdir -p ${LOGS} fi # funcao para registrar os erros function error() { echo `date +%d.%m.%Y%t%H:%M:%S` " ERROR:" $1 | tee -a ${LOGFILE} if [ -n "${MAILNOTIFY}" ] ; then echo `date +%d.%m.%Y%t%H:%M:%S` " ERROR:" $1 | mail -s "${MAILSUBJECT}" ${MAILNOTIFY} fi } # funcao para registrar o status function status() { case "$1" in 0) log "Synchronization completed." ;; 1) error "RSYNC: Syntax or usage error." ;; 2) error "RSYNC: Protocol incompatibility." ;; 3) error "RSYNC: Errors selecting input/output files, dirs." ;; 4) error "RSYNC: Requested action not supported: an attempt was made to manipulate 64-bit files on a platform that cannot support them; or an option was specified that is supported by the client and not by the server." ;; 5) error "RSYNC: Error starting client-server protocol." ;; 6) error "RSYNC: Daemon unable to append to log-file." ;; 10) error "RSYNC: Error in socket I/O." ;; 11) error "RSYNC: Error in file I/O." ;; 12) error "RSYNC: Error in rsync protocol data stream." ;; 13) error "RSYNC: Errors with program diagnostics." ;; 14) error "RSYNC: Error in IPC code." ;; 20) error "RSYNC: Received SIGUSR1 or SIGINT." ;; 21) error "RSYNC: Some error returned by waitpid()." ;; 22) error "RSYNC: Error allocating core memory buffers." ;; 23) error "RSYNC: Partial transfer due to error." ;; 24) error "RSYNC: Partial transfer due to vanished source files." ;; 25) error "RSYNC: The --max-delete limit stopped deletions." ;; 30) error "RSYNC: Timeout in data send/receive." ;; *) error "RSYNC: Unknown error $1." ;; esac } if [ -f ${LOCKFILE} ] ; then kill -0 $(cat ${LOCKFILE}) >/dev/null 2>&1 if [ $? -eq 0 ] ; then error "Previous process still running." exit 1 else log "Deprecated lock file found. Remove lock file." rm -f ${LOCKFILE} fi fi echo $$ >${LOCKFILE} # Create local mirror directories if not exists if [ ! -d ${TARGET} ] ; then log "Diretorio do repositorio criado." mkdir -p ${TARGET} fi #Comando rsync log "Iniciando o download do repositorio epel CentOS 6." >> ${DEBUGFILE} 2>&1 echo ">>>>>" `date +%d.%m.%Y%t%H:%M:%S` "<<<<<" >>${DEBUGFILE} rsync -av --bwlimit=4096 --exclude=SRPMS --exclude=ppc64 ${SOURCE} ${TARGET} >> ${DEBUGFILE} 2>&1 status $? #usa o cat para esvaziar o arquivo $CRIAR. cat /dev/null > $CREATE # cria o script para executar pos download cat << EOF > $CREATE #!/bin/bash #Esse script executa o comando createrepo em todos os diretórios com arquivos .rpm. # Criado em: `date` EOF # aqui buscamos os arquivos das arquiteturar x86_64 e i386 para rodarmos o createrepo # isso evita erro no clientes find /var/www/html/epel/6/ -name "x86_64" >> $CREATE find /var/www/html/epel/6/ -name "i386" >> $CREATE # colocando o createrepo ates do var # na primeira execucao atere createrepo --update para createrepo sed -i "s/\/var/createrepo --update \/var/g" $CREATE # Alterando as permissoes e executando chmod 750 $CREATE log "Iniciando a criacao da base de dados." >> ${DEBUGFILE} 2>&1 echo ">>>>>" `date +%d.%m.%Y%t%H:%M:%S` "<<<<<" >>${DEBUGFILE} /bin/bash $CREATE status $? rm -f ${LOCKFILE} exit 0
# tail -f /var/log/mirror/epel_6.debug
# cat /srv/scripts/mirror_epel7.sh #!/bin/bash SOURCE="rsync://mirrors.rit.edu/epel/7" TARGET="/var/www/html/epel" CREATE="createrepo_epel7.sh" LOGS="/var/log/mirror" LOGOFILE="/var/log/mirror/epel_7.log" MAILNOTIFY="gean@rascunhos.wiki.br" DEBUGFILE="/var/log/mirror/epel_7.debug" MAILSUBJECT="ERRO Repositorio epel CentOS 7" LOCKFILE="/var/log/mirror/epel_7.lock" # funcao para registrar os logs function log() { echo `date +%d.%m.%Y%t%H:%M:%S` " LOG:" $1 | tee -a ${LOGFILE} } # Cria o diretorio mirror se ele nao existir if [ ! -d ${LOGS} ] ; then log "Diretorio de logs criado." mkdir -p ${LOGS} fi # funcao para registrar os erros function error() { echo `date +%d.%m.%Y%t%H:%M:%S` " ERROR:" $1 | tee -a ${LOGFILE} if [ -n "${MAILNOTIFY}" ] ; then echo `date +%d.%m.%Y%t%H:%M:%S` " ERROR:" $1 | mail -s "${MAILSUBJECT}" ${MAILNOTIFY} fi } # funcao para registrar o status function status() { case "$1" in 0) log "Synchronization completed." ;; 1) error "RSYNC: Syntax or usage error." ;; 2) error "RSYNC: Protocol incompatibility." ;; 3) error "RSYNC: Errors selecting input/output files, dirs." ;; 4) error "RSYNC: Requested action not supported: an attempt was made to manipulate 64-bit files on a platform that cannot support them; or an option was specified that is supported by the client and not by the server." ;; 5) error "RSYNC: Error starting client-server protocol." ;; 6) error "RSYNC: Daemon unable to append to log-file." ;; 10) error "RSYNC: Error in socket I/O." ;; 11) error "RSYNC: Error in file I/O." ;; 12) error "RSYNC: Error in rsync protocol data stream." ;; 13) error "RSYNC: Errors with program diagnostics." ;; 14) error "RSYNC: Error in IPC code." ;; 20) error "RSYNC: Received SIGUSR1 or SIGINT." ;; 21) error "RSYNC: Some error returned by waitpid()." ;; 22) error "RSYNC: Error allocating core memory buffers." ;; 23) error "RSYNC: Partial transfer due to error." ;; 24) error "RSYNC: Partial transfer due to vanished source files." ;; 25) error "RSYNC: The --max-delete limit stopped deletions." ;; 30) error "RSYNC: Timeout in data send/receive." ;; *) error "RSYNC: Unknown error $1." ;; esac } if [ -f ${LOCKFILE} ] ; then kill -0 $(cat ${LOCKFILE}) >/dev/null 2>&1 if [ $? -eq 0 ] ; then error "Previous process still running." exit 1 else log "Deprecated lock file found. Remove lock file." rm -f ${LOCKFILE} fi fi echo $$ >${LOCKFILE} # Create local mirror directories if not exists if [ ! -d ${TARGET} ] ; then log "Diretorio do repositorio criado." mkdir -p ${TARGET} fi #Comando rsync log "Iniciando o download do repositorio epel CentOS 7." >> ${DEBUGFILE} 2>&1 echo ">>>>>" `date +%d.%m.%Y%t%H:%M:%S` "<<<<<" >>${DEBUGFILE} rsync -av --bwlimit=4096 --exclude=SRPMS --exclude=ppc64 ${SOURCE} ${TARGET} >> ${DEBUGFILE} 2>&1 status $? #usa o cat para esvaziar o arquivo $CRIAR. cat /dev/null > $CREATE # cria o script para executar pos download cat << EOF > $CREATE #!/bin/bash #Esse script executa o comando createrepo em todos os diretórios com arquivos .rpm. # Criado em: `date` EOF # aqui buscamos os arquivos das arquiteturar x86_64 para rodarmos o createrepo # isso evita erro no clientes find /var/www/html/epel/7/ -name "x86_64" >> $CREATE # colocando o createrepo ates do var # na primeira execucao atere createrepo --update para createrepo sed -i "s/\/var/createrepo --update \/var/g" $CREATE # Alterando as permissoes e executando chmod 750 $CREATE log "Iniciando a criacao da base de dados." >> ${DEBUGFILE} 2>&1 echo ">>>>>" `date +%d.%m.%Y%t%H:%M:%S` "<<<<<" >>${DEBUGFILE} /bin/bash $CREATE status $? rm -f ${LOCKFILE} exit 0
# tail -f /var/log/mirror/epel_7.debug
# cat /etc/logrotate.d/mirror /var/log/mirror/*log { monthly rotate 3 compress delaycompress missingok notifempty }
# chcon -u system_u /etc/logrotate.d/mirror
# cat /etc/httpd/conf.d/mirror.conf NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin gean@laboratorio.com.br ServerName www.mirror.laboratorio.com.br ServerAlias mirror.mba.laboratorio.com.br DocumentRoot "/var/www/html/centos" <Directory "/var/www/html/centos"> Options +Indexes +FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> <LocationMatch "\.(xml|xml\.gz|xml\.asc|sqlite)$"> Header set Cache-Control "must-revalidate" ExpiresActive On ExpiresDefault "now" </LocationMatch> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" %I %O \"%{User-Agent}i\"" combined </VirtualHost>
# cat /etc/httpd/conf.d/epel.conf NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin gean@laboratorio.com.br ServerName www.epel.laboratorio.com.br ServerAlias epel.laboratorio.com.br DocumentRoot "/var/www/html/epel" <Directory "/var/www/html/epel"> Options +Indexes +FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> <LocationMatch "\.(xml|xml\.gz|xml\.asc|sqlite)$"> Header set Cache-Control "must-revalidate" ExpiresActive On ExpiresDefault "now" </LocationMatch> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" %I %O \"%{User-Agent}i\"" combined </VirtualHost>
# cd /var/www/html # chown -R apache:apache .* # semanage fcontext -a -t httpd_sys_content_t "/centos(/.*)?" # semanage fcontext -a -t httpd_sys_content_t "/epel(/.*)?" # restorecon -R -v centos # restorecon -R -v epel
# crontab -e # crontab -l 00 00 * * * /srv/script/mirror_centos6.sh 00 02 * * * /srv/script/mirror_centos7.sh 00 04 * * * /srv/script/mirror_epel6.sh 00 06 * * * /srv/script/mirror_epel7.sh
Repositório base
sed -i "s/http\:\/\/mirror.centos.org\/centos/http\:\/\/mirror.laboratorio.com.br/g" /etc/yum.repos.d/CentOS-Base.repo sed -i "s/enabled=0/enabled=1/g" /etc/yum.repos.d/CentOS-Base.repo sed -i "s/mirrorlist/#mirrorlist/g" /etc/yum.repos.d/CentOS-Base.repo sed -i "s/#baseurl/baseurl/g" /etc/yum.repos.d/CentOS-Base.repo
Epel
sed -i "s/http\:\/\/download.fedoraproject.org\/pub\/epel/http\:\/\/epel.laboratorio.com.br/g" /etc/yum.repos.d/epel.repo sed -i "s/mirrorlist/#mirrorlist/g" /etc/yum.repos.d/epel.repo sed -i "s/#baseurl/baseurl/g" /etc/yum.repos.d/epel.repo
Para limpar os pacotes do cache:
# yum clean packages
Para limpar os cabeçalhos do cache:
# yum clean headers
Para limpar todo o cache:
# yum clean all
Para reconstruir o cache:
# yum makecache