日常运维(三)

一.保存和备份iptables规则:

保存防火墙配置:

[root@ligen ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  确定  ]

备份防火墙配置:

[root@ligen ~]# iptables-save > myipt.obt
[root@ligen ~]# cat myipt.obt 

恢复备份:

[root@ligen ~]# iptables-restore < myipt.obt

二.防火墙firewalld:

开启firewall服务:

[root@ligen ~]# systemctl restart firewalld
[root@ligen ~]# systemctl enable firewalld
[root@ligen ~]# systemctl disable iptables
[root@ligen ~]# systemctl stop iptables
[root@ligen ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 三 2019-04-17 19:49:16 CST; 2min 26s ago
     Docs: man:firewalld(1)
 Main PID: 13751 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─13751 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
  • zone:
    DROP:丢弃,任何接收的数据包丢弃,不理会
    block:限制,任何接收的网络连接都被ipv4和IP v6的icmp-host-prohibited信息和ipv6jujue。
    public:公共。在公共内使用,不能相信网络内的其他计算机,只能接收经过选取的连接。
    external:外部。特别是为路由器启用了伪装功能的外部网。
    dmz:非军事区。此区域内可公开访问
    work:工作区。基本相信网络内的其他计算机不会危害你的计算机,仅接收经过选择的连接。
    internal:内部。用于内部网络。你可以基本信任网络内的其他计算机不会威胁你的计算机。
    trusted:信任。可接受所有的网络连接。
    获取系统的所走zones:
    [root@ligen ~]# firewall-cmd --get-zones
    block dmz drop external home internal public trusted work

如下命令可以查看系统默认zone:

[root@ligen ~]# firewall-cmd --get-default-zone
work

[root@ligen ~]# firewall-cmd --set-default-zone=public
[root@ligen ~]# firewall-cmd --get-zone-of-interface=ens33
public
[root@ligen ~]# firewall-cmd --set-default-zone=public
success
[root@ligen ~]# firewall-cmd --get-default-zone
public
[root@ligen ~]# firewall-cmd --get-zone-of-interface=ens33
public
[root@ligen ~]# firewall-cmd --zone=public --add-interface=lo
success

[root@ligen ~]# firewall-cmd --zone=work --change-interface=lo
success
[root@ligen ~]# firewall-cmd --zone=work --remove-interface=lo
success
[root@ligen ~]# firewall-cmd --get-active-zones
public
  interfaces: ens33
  • service:
    每个zone里面都使用了不同的service,service就是针对一个服务做的iptables规则。service都是由一个个配置文件定义的,配置文件模板在/usr/lib/firewalld/services/目录下,真正生效的配置/etc/firewalld/services目录下面(默认为空)。
    [root@ligen ~]# ls /usr/lib/firewalld/services/
    amanda-client.xml        jenkins.xml               puppetmaster.xml
    amanda-k5-client.xml     kadmin.xml                quassel.xml
    bacula-client.xml        kerberos.xml              radius.xml
    bacula.xml               kibana.xml                redis.xml
    bgp.xml                  klogin.xml                RH-Satellite-6.xml
    bitcoin-rpc.xml          kpasswd.xml               rpc-bind.xml
    bitcoin-testnet-rpc.xml  kprop.xml                 rsh.xml
    bitcoin-testnet.xml      kshell.xml                rsyncd.xml
    
    [root@ligen ~]# ls /etc/firewalld/services/

查看某个zone下面的service:

[root@ligen ~]# firewall-cmd --list-services
ssh dhcpv6-client
[root@ligen ~]# firewall-cmd --zone=public --list=service
usage: see firewall-cmd man page
firewall-cmd: error: ambiguous option: --list=service could match --list-lockdown-whitelist-contexts, --list-all, --list-lockdown-whitelist-uids, --list-ports, --list

一个zone下面有某个service,意味着这个service是被信任的。

[root@ligen ~]# firewall-cmd --zone=public --add-service=http
success
[root@ligen ~]# firewall-cmd --zone=public --list-service
ssh dhcpv6-client http

永久生效:

    [root@ligen ~]# firewall-cmd --zone=public --add-service=http --permanent 
例如:
ftp 端口1122 要在work zone上放行ftp:
[root@ligen ~]# cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services/ftp.xml
[root@ligen services]# vim ftp.xml   更改端口
[root@ligen firewalld]# cp /usr/lib/firewalld/zones/work.xml /etc/firewalld/zones/
[root@ligen firewalld]# cat zones/work.xml 
<?xml version="1.0" encoding="utf-8"?>
<zone>
  <short>Work</short>
  <description>For use in work areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
  <service name="ssh"/>
  <service name="ftp"/>   #增加了一行
  <service name="dhcpv6-client"/>
</zone>

重新加载:

[root@ligen firewalld]# firewall-cmd --reload
success

查看:

[root@ligen firewalld]# firewall-cmd --zone=work --list-service
ssh ftp dhcpv6-client

linux任务计划cron:

root@ecs-cebb ~]# crontab -e    #创建
no crontab for root - using an empty one
crontab: installing new crontab
[root@ecs-cebb ~]# crontab -l      #查看
1 10 1-10 */2 2,5 /bin/bash /usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log
[root@ecs-cebb ~]# ps aux | grep cron   #查看进程
root      2323  0.0  0.0 112708   976 pts/0    S+   21:40   0:00 grep --color=auto cron
root      6536  0.0  0.0 126320  1660 ?        Ss   Apr02   0:01 /usr/sbin/crond -n
[root@ecs-cebb ~]# systemctl status crond
● crond.service - Command Scheduler
   Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-04-02 10:04:54 CST; 2 weeks 3 days ago
 Main PID: 6536 (crond)
   [root@ecs-cebb ~]# crontab -r    #删除

chkconfig服务管理工具:

linux系统所有的预设服务都可以通过查看/etc/init.d/
[root@ligen ~]# ls /etc/init.d
cloudResetPwdAgent        denyhosts  multi-queue-hw  network
cloudResetPwdUpdateAgent  functions  netconsole      README

系统的预设服务都可以通过service 服务名 start|stop|restart实现。这里的服务名就是/etc/init.d/,还可以用命令/etc/init.d/服务名实现。

[root@ligen ~]# chkconfig --list    #也可以实现列出所有服务。
cloudResetPwdAgent	0:off	1:off	2:on	3:on	4:on	5:on	6:off
cloudResetPwdUpdateAgent	0:off	1:off	2:on	3:on	4:on	5:on	6:off
denyhosts      	0:off	1:off	2:on	3:on	4:on	5:on	6:off
multi-queue-hw 	0:off	1:off	2:on	3:on	4:on	5:on	6:off
netconsole     	0:off	1:off	2:off	3:off	4:off	5:off	6:off
network        	0:off	1:off	2:off	3:off	4:off	5:off	6:off

运行级别:
0:关机
1:单用户模式
2:支持无nfs多用户模式
3:完全多用户模式
4:保留
5:图形登入方式
6:重启

[root@ligen ~]# chkconfig --level 2 network on
[root@ligen ~]# chkconfig --level 345 network off
[root@ligen ~]# chkconfig network off

增加系统服务:

[root@ligen ~]# cp /etc/init.d/network /etc/init.d/123
[root@ligen ~]# chkconfig --add 123
[root@ligen ~]# chkconfig --list |grep 123
123            	0:off	1:off	2:on	3:on	4:on	5:on	6:off

删除:

[root@ligen ~]# chkconfig --del 123

systemd服务:

system支持多个服务并发启动,而sysv只能一个一个地启动。
列出系统所有服务:

[root@ligen ~]# systemctl list-units --all --type=service

对应的服务器的脚本路径:/usr/lib/systemd/system/

[root@ligen ~]# ls /usr/lib/systemd/system
system/                    systemd-journald           systemd-sleep
systemd                    systemd-localed            systemd-socket-proxyd
systemd-ac-power           systemd-logind             systemd-sysctl
systemd-activate           systemd-machined           systemd-sysv-install
systemd-backlight          systemd-machine-id-commit  systemd-timedated
systemd-binfmt             systemd-modules-load       systemd-udevd
systemd-bootchart          systemd-pull               systemd-update-done

unit分类:
service:系统服务。
target:多个unit组成的组
device:硬件设备
mount:文件系统挂载
automuont:自动挂载点
path:文件或路径
scope:不是有systemd启动的外部进程
slice:进程组
snapshot:systemd快照
socket:进程间套接字
swap:swap文件
timer:定时器
关于systemctl的常用命令:

[root@ligen ~]# systemctl restart crond
[root@ligen ~]# systemctl stop crond
[root@ligen ~]# systemctl status crond
[root@ligen ~]# systemctl start crond
[root@ligen ~]# systemctl is-enabled crond
enabled

关于unit的一些常用命令:

[root@ligen ~]# systemctl list-units
[root@ligen ~]# systemctl list-units -all
[root@ligen ~]# systemctl list-units -all --state=inactive
[root@ligen ~]# systemctl list-units --all --type=target
[root@ligen ~]# systemctl list-units --type=service

target:

[root@ligen ~]# systemctl list-unit-files --type=target #查看系统所有的target
[root@ligen ~]# systemctl list-dependencies multi-user.target #查看某个target包含的unit
[root@ligen ~]# systemctl get-default #查看默认的target
multi-user.target
target、unit、service之间的关系:
target包含很多service
target由很多unit组成
一个service属于一种unit

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值