saltstack之(一)系统环境及本地yum源

1.服务器环境
node1:192.168.3.1
node2:192.168.3.2

2.主机名和hosts文件
node1: node1.xkops.com --主机名
[root@node1 ~]# tail -n 2 /etc/hosts
192.168.3.1 node1 node1.xkops.com
192.168.3.2 node2 node2.xkops.com

node2: node2.xkops.com --主机名
[root@node2 ~]# tail -n 2 /etc/hosts
192.168.3.1 node1 node1.xkops.com
192.168.3.2 node2 node2.xkops.com

3.关闭防火墙和selinux
node1:
service iptables stop
chkconfig iptables off
sed -i '/^SELINUX/s;enforcing;disabled;g' /etc/selinux/config
setenforce 0

node2:
service iptables stop
chkconfig iptables off
sed -i '/^SELINUX/s;enforcing;disabled;g' /etc/selinux/config
setenforce 0

4.配置本地yum源
node1:
mount /dev/sr0 /mnt
cd /etc/yum.repos.d/
mkdir backup && mv CentOS-* backup
[root@node1 yum.repos.d]# cat > CentOS-mnt.repo <<EOF
[CentOS6.5]
name=CT 6.5
baseurl=file:///mnt
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
EOF
[root@node1 yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
repo id repo name status
CentOS6.5 CT 6.5 6,367
repolist: 6,367

node2:
mount /dev/sr0 /mnt
cd /etc/yum.repos.d/
mkdir backup && mv CentOS-* backup
[root@node2 yum.repos.d]# cat > CentOS-mnt.repo <<EOF
[CentOS6.5]
name=CT 6.5
baseurl=file:///mnt
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
EOF
[root@node2 yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
repo id repo name status
CentOS6.5 CT 6.5 6,367
repolist: 6,367

 

附录:

本篇文章初始化脚本,前提是已经配置好IP地址。

#!/bin/bash
#author: xkops
#set -x
stty erase ^H


#define hostname and hosts file.
read -p "Please Input Your HostName: " HOSTNAME
read -p "Please Input Your FQDN: " FQDN
IP=$(ifconfig eth0|grep 'inet addr:'|awk -F":" '{print $2}'|awk '{print $1}')
if ! grep -q $HOSTNAME /etc/hosts;then
    #echo "$HOSTNAME is exsits in files /etc/hosts." 
    echo "$IP   $HOSTNAME   $FQDN" >> /etc/hosts
fi
sed -i "s#HOSTNAME=.*#HOSTNAME=$HOSTNAME#" /etc/sysconfig/network
hostname $HOSTNAME
echo -e "Host:\033[32mFinished.\033[0m"

#shutdown selinux and iptables services.
sed -i "s#SELINUX=.*#SELINUX=disabled#" /etc/selinux/config
#setenforce 0
/etc/init.d/iptables status &> /dev/null
if [ "$?" -eq 0 ];then 
    /etc/init.d/iptables stop 
fi
chkconfig iptables off
echo -e "Selinux|iptables:\033[32mFinished.\033[0m"

#shutdown NetworkManager.
/etc/init.d/NetworkManager status &> /dev/null
if [ "$?" -eq 0 ];then
    /etc/init.d/NetworkManager stop
fi
chkconfig NetworkManager off
echo -e  "NetworkManager:\033[32mFinished.\033[0m"

#define mount ISO images.
df -Ph |grep /dev/sr0 &> /dev/null
if [ "$?" -ne 0 ];then
    mount /dev/sr0 /mnt &> /dev/null
    if [ "$?" -ne 0 ];then
        echo -e "ISO:\033[31mISO images device is a problem. Please check ISO connect to VM host.\033[0m"
        exit
    fi
fi

#backup repo files and touch a new repo file of CentOS.
if [ ! -d /etc/yum.repos.d/BACK ];then
    mkdir /etc/yum.repos.d/BACK
fi
if [ ! -f /etc/yum.repos.d/CentOS-mnt.repo ];then
    mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/BACK/
fi
cat > /etc/yum.repos.d/CentOS-mnt.repo <<EOF
[CentOS6.5]
name=CT 6.5
baseurl=file:///mnt
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
EOF
echo -e "Repo:\033[32mFinished.\033[0m"

#check test repo config.
yum repolist|tail -n 1

*注释:如果光盘为挂载会出现报错提示。

posted @ 2016-05-11 16:07  xkops  阅读(774)  评论(0编辑  收藏  举报