1.firewall-cmd: 设置访问web服务器的80端口时转发到8081端口
进入/etc/httpd/conf.d目录下配置额外的子配置文件
[root@server ~]# cd /etc/httpd/conf.d/
添加配置文件myhost.conf(名字可自取),并进入配置文件进行配置
[root@server conf.d]# vim myhost.conf
listen 8081
<Directory "/www/ip">
AllowOverride None
Require all granted
</Directory>
<VirtualHost 192.168.18,129:8081>
DocumentRoot "/www/ip"
ServerName 192.168.18.129
</VirtualHost>
保存并退出
创建首页文件以及他所在的目录
[root@cotenos conf.d]# mkdir -p /www/ip
[root@cotenos conf.d]# vim /www/ip/index.html
This is port 8081
[root@server conf.d]# mkdir -p /www/ip
[root@server conf.d]# vim /www/ip/index.html
This is port 8081
重启httpd服务(注意要关闭SElinux)
查看SELinux状态
[root@server conf.d]# getenforce
Enforcing
此时是开启状态,我们进行修改(注意这里是临时修改,想要永久修改进入配置文件修改)
[root@server conf.d]# setenforce 0
[root@server conf.d]# getenforce
Permissive
重启服务
[root@server conf.d]# systemctl restart httpd
此时并不能访问,这是因为我们的防火墙是开启状态(默认设置是拒绝)
对防火墙进行配置
同意httpd服务的访问
[root@server conf.d]# firewall-cmd --add-service=http
success
这是临时生效,想要永久生效需添加 --permanent命令
查看所有规则:
[root@server conf.d]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens160
sources:
services: dhcpv6-client http ssh # 已开启
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
使任何人都可以访问8081端口
[root@server conf.d]# firewall-cmd --permanent --add-prot=8081/tcp
[root@server conf.d]# firewall-cmd --reload
–permanent:永久生效
–reload:让“永久生效”的配置规则立即生效,并覆盖当前的配置规则
将本机80端口转发到192.168.112.35:8081端口上
[root@server conf.d]# firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8081:toaddr=192.168.112.135
success
2.ansible: 使用shell或者command模块创建用户:testuser1 使用script/shell/command模块执行脚本: 脚本内容为:echo “Hello World” 使用copy模块:将管理主机(manage)上 /root/ansible/copyfile 文件拷贝到 被管理主机node1上的/home/testuser1目录下 使用blockinfile模块:向/home/testuser1/copyfile文件中插入:Hello World 在Hello World之后插入: Hello Shaanxi 在Hello World之前插入:Hello China 删除 Hello World 替换 Hello Shaanxi 为 Hello Xian
使用shell或者command模块创建用户:testuser1
[root@server ansible]# ansible localhost -m shell -a "useradd testuser1"
localhost | CHANGED | rc=0 >>
使用script/shell/command模块执行脚本: 脚本内容为:echo “Hello World”
[root@server ansible]# ansible localhost -m shell -a 'echo "Hello world"'
localhost | CHANGED | rc=0 >>
Hello world
使用copy模块:将管理主机(manage)上 /root/ansible/copyfile 文件拷贝到 被管理主机node1上的/home/testuser1目录下
[root@server ansible]# ansible node1 -m copy -a 'src=/root/ansible/copyfile dest=/home/testuser1 '
查看node1主机的/home/test目录:
[root@server ansible]# ansible node1 -m shell -a 'ls -l /home/testuser1'
node1 | CHANGED | rc=0 >>
total 4
-rw-r--r--. 1 root root 13 Nov 14 15:21 copyfile
使用blockinfile模块:向/home/testuser1/copyfile文件中 插入:Hello World 在Hello World之后插入: Hello Shaanxi 在Hello World之前插入:Hello China 删除 Hello World
替换 Hello Shaanxi 为 Hello Xian
[root@server ansible]# ansible node1 -m blockinfile -a 'path=/home/testuser1/copyfile block="Hello World" marker="#{mark} Hello" insertafter="Hello World"'
node1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "Block inserted"
}
[root@server ansible]# ansible node1 -m blockinfile -a 'path=/home/testuser1/copyfile block="Hello Shaani" marker="#{mark} Shaanxi"'
node1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "Block inserted"
}
[root@server ansible]# ansible node1 -m blockinfile -a 'path=/home/testuser1/copyfile block="Hello China" marker="#{mark} Shaanxi" insertbefore=BOF'
node1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "Block inserted"
}
[root@server ansible]# ansible node1 -m blockinfile -a 'path=/home/testuser1/copyfile block="Hello Xian" marker="#{mark} Shaanxi" insertbefore=BOF'
node1 | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"msg": "Block inserted"
}