Firewalld共享上網及本地yum倉庫搭建
阿新 • • 發佈:2018-11-21
1.firewalld共享上網
1.服務端操作(有外網的伺服器)
1.開啟防火牆並加入開機自啟動
[[email protected] ~]# systemctl start firewalld
[[email protected] ~]# systemctl enable firewalld
2.移除預設所有人能訪問ssh的規則
[[email protected] ~]# firewall-cmd --remove-service=ssh --permanent
3.新增只允許10.0.0.1這臺主機訪問
[[email protected] ~]# firewall-cmd --add-rich-rule='rule family=ipv4 source address=10.0.0.1/32 service name=ssh accept' --permanent
4.開啟ip偽裝,為後續主機提供共享上網【管理機】
[[email protected] ~]# firewall-cmd --add-masquerade --permanent
5.重啟firewalld生效
[[email protected] ~]# firewall-cmd --reload
2.沒有外網的伺服器操作
1.沒有公網地址的內部伺服器配置指向管理機的閘道器
[[email protected] ~]# /etc/sysconfig/network-scripts/ifcfg-eth1 #配置新增如下2條規則 GATEWAY=172.16.1.61 #有外網的伺服器內網ip DNS1=223.5.5.5
2.重啟網絡卡ping baidu.com(如果不通嘗試重啟伺服器)
[[email protected] ~]# nmcli connection down eth1 && nmcli connection up eth1
[[email protected] ~]# ping baidu.com
2.本地yum倉庫搭建管理伺服器操作
1.服務端(有外網)
1.安裝vsftpd服務
[[email protected] ~]# yum install vsftpd -y
2.開啟yum快取功能
[[email protected] ~]# sed -i '/^keepcache/c keepcache=1' /etc/yum.conf
[[email protected] ~]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1 #這個原來是0 改成1即可
3.安裝createrepo並建立 reopdata倉庫
[[email protected] ~]# yum -y install createrepo
[[email protected] ~]# createrepo /var/ftp/ops
#注意: 如果此倉庫每次新增軟體則需要重新生成一次
4.安裝需要的服務
[[email protected] ~]# yum -y install
5.尋找已安裝的rpm包,並移動到本地倉庫
[[email protected] ~]# mkdir -p /var/ftp/ops
[[email protected] ~]# find /var/cache/yum/x86_64/7/ -iname "*.rpm" -exec cp -rf {} /var/ftp/ops \;
6.重新生成一次(createrepo /var/ftp/ops)
[[email protected] ~]# createrepo /var/ftp/ops
7.啟動vsftp服務並加入開機自啟
[[email protected] ~]# systemctl start vsftpd
[[email protected] ~]# systemctl enable vsftpd
8.firewalld新增ftp服務通行
[[email protected] ~]# firewall-cmd --add-service=ftp --permanent
9.重啟firewalld生效
[[email protected] ~]# firewall-cmd --reload
2.沒外網的伺服器操作
1.所有伺服器(無外網)把原有源都打包
gzip /etc/yum.repos.d/*
2.配置一個本地源,目錄與服務端的目錄一致
cat /etc/yum.repos.d/ops.repo
[ops]
name=local ftpserver
baseurl=ftp://172.16.1.61/ops #填寫有外網的伺服器內網ip地址
gpgcheck=0
enabled=1