linux安装服务器

dnsmasq做为dhcp, dns, ntp, tftp服务器

yum -y install dnsmasq
systemctl enable dnsmasq.service
systemctl start dnsmasq.service

/etc/dnsmasq.d/my.conf

# resolve-file指定dnsmasq从哪个文件中读取上行DNS Server, 默认是从/etc/resolv.conf获取
# addn-hosts  指定dnsmasq从哪个文件中读取'地址 域名'记录, 默认是系统文件/etc/hosts

interface=em1,lo
listen-address=127.0.0.1,192.168.48.116
bind-interfaces
log-queries
log-dhcp
log-async=20
log-facility=/var/log/dnsmasq.log

# dhcp
dhcp-range=em1,192.168.48.131,192.168.48.140,255.255.255.0,1h
dhcp-option=option:router,192.168.48.1
dhcp-boot=pxelinux.0,pxeserver,192.168.48.116

# dns
dhcp-option=option:dns-server,192.168.48.116
#no-resolv
server=114.114.114.114
no-hosts
address=/install.local/192.168.48.116
address=/yum.local/192.168.48.116

# ntp
dhcp-option=option:ntp-server,192.168.48.116

# tftp
enable-tftp
tftp-root=/var/lib/tftpboot
#pxe-prompt="Press F8 for menu.", 10
#pxe-service=x86PC, "Install CentOS", pxelinux

建立本地安装源

mkdir /mnt/{centos-7,centos-atomic-host-7}
mount -o loop /opt/CentOS-7-x86_64-Minimal-1503-01.iso /mnt/centos-7
mount -o loop /opt/CentOS-Atomic-Host-7.20151001-Installer.iso /mnt/centos-atomic-host-7

ln -s /mnt/centos-atomic-host-7 /opt/opmgmt/install/centos-atomic-host-7
ln -s /mnt/centos-7 /opt/opmgmt/install/centos-7
mkdir -p /opt/opmgmt/install/{kickstart,pxelinux.cfg}
ln -s /mnt/centos-atomic-host-7/images/pxeboot /var/lib/tftpboot/centos-atomic-host-7
ln -s /mnt/centos-7/images/pxeboot /var/lib/tftpboot/centos-7

ln -s /opt/opmgmt/install/pxelinux.cfg /var/lib/tftpboot/pxelinux.cfg

yum

/opt/opmgmt/yum/rsync_centos.sh

#!/bin/bash
repo_root='/opt/opmgmt/yum/centos/'
sync_cmd='rsync -arv --delete-after --delete-excluded'
sync_srv='rsync://mirrors.yun-idc.com/centos/'
exclude='--exclude [23456]/ --exclude [23456].*/ --exclude i386/ --exclude drpms/ --exclude SCL/ --exclude centosplus/ --exclude cloud/ --exclude contrib/ --exclude cr/ --exclude fasttrack/ --exclude isos/ --exclude xen4/'

[ -d $repo_root ] && mkdir -p $repo_root 
$sync_cmd $exclude $sync_srv $repo_root &

/opt/opmgmt/yum/rsync_epel.sh

#!/bin/bash
repo_root='/opt/opmgmt/yum/epel/'
sync_cmd='rsync -arv --delete-after --delete-excluded'
sync_srv='rsync://mirrors.yun-idc.com/epel/'
exclude='--exclude [456]*/ --exclude=ppc64le/ --exclude testing/ --exclude SRPMS/ --exclude i386/ --exclude ppc64/ --exclude debug/ --exclude=repoview'

[ -d $repo_root ] && mkdir -p $repo_root 
$sync_cmd $exclude $sync_srv $repo_root &

/opt/opmgmt/yum/centos.repo

[base]
name=CentOS-$releasever - Base
baseurl=http://yum.localhost/centos/$releasever/os/$basearch
enabled=1
gpgcheck=0

[updates]
name=CentOS-$releasever - Updates
baseurl=http://yum.localhost/centos/$releasever/updates/$basearch
enabled=1
gpgcheck=0

[extras]
name=CentOS-$releasever - Extras
baseurl=http://yum.localhost/centos/$releasever/extras/$basearch
enabled=1
gpgcheck=0

/opt/opmgmt/yum/epel.repo

[epel]
name=Extra Packages for Enterprise Linux $releasever - $basearch
baseurl=http://yum.localhost/epel/$releasever/$basearch
enabled=1
gpgcheck=0

/etc/cron.d/yum-repo.cron

0 2 * * 0 root /bin/sh /opt/opmgmt/yum/rsync_centos.sh
0 4 * * 0 root /bin/sh /opt/opmgmt/yum/rsync_epel.sh

nginx

yum -y install nginx
systemctl enable nginx.service
systemctl start nginx.service

/etc/nginx/conf.d/opmgmt.conf

server {
    listen       80;
    server_name  install.local;
    root         /opt/opmgmt/install;

    allow 192.168.48.0/24;
    deny all;

    autoindex on;
    autoindex_exact_size off;

    location / {
    }
}

server {
    listen       80;
    server_name  yum.local;
    root         /opt/opmgmt/yum;

    allow 192.168.48.0/24;
    deny all;

    autoindex on;
    autoindex_exact_size off;

    location / {
    }
}
原文地址:https://www.cnblogs.com/liujitao79/p/4905224.html