1、自动化配置dns服务器
A主机:
vim dns.sh
#!/bin/bash
# 自动化部署dns
# 1、下载bind
# 2、修改配置文件
# vim /etc/named.conf
# listen-on port 53 { 127.0.0.1;any; }; 修改(定位替换)
# allow-query { localhost;any; }; 修改(定位替换)
# vim /etc/named.rfc1912.zones (最后追加)
# zone "baibai.com" IN {
# type master;# file "baibai.com.zone";
# allow-update { none; };
#};
# 3、创建zone文件
# cd /var/named/
# cp -p named.localhost baibai.com.zone
# 4、修改zone文件
# vim baibai.com.zone
# www A 10.0.0.100 (最后追加)
# 5、重启服务
# systemctl restart named
yum -y install bind
sed -i '/listen-on/ s/127.0.0.1;/127.0.0.1;any;/' /etc/named.conf
sed -i '/allow-query/ s/localhost;/localhost;any;/' /etc/named.conf
sed -i '$a zone "a.com" IN {' /etc/named.rfc1912.zones
sed -i '$a type master;' /etc/named.rfc1912.zones
sed -i '$a file "a.com.zone";' /etc/named.rfc1912.zones
sed -i '$a allow-update { none; };' /etc/named.rfc1912.zones
sed -i '$a };' /etc/named.rfc1912.zones
cd /var/named/
cp -p named.localhost a.com.zone
sed -i '$a www A 10.0.0.100' /var/named/a.com.zone
systemctl restart named
sh dns.sh
B主机:
vim dnscs.sh
#!/bin/bash
#测试机测试dns
yum -y install bind-utils
echo "nameserevr 10.0.0.12" > /etc/resolv.conf
nslookup www.a.com
sh dnscs.sh
2、自动化配置rsync服务
A主机: 1ssh-keygen
ssh-copy-id
vim rsync.sh
#!/bin/bash
# 自动化部署rsync
# 先自己做免密
# 1、下载rsync和inotify-tools软件 yum -y install rsync inotify-tools
# 2、创建共享目录与共享文件 mkdir rsync touch rsync/file{0..4}
# 3、修改配置文件 vim /etc/rsyncd.conf (最后面追加)
# [app]
# path=/root/rsync/ //项目路径
# log file=/var/log/rsync.log //项目日志文件路径
# 4、重启rsync服务 systemctl restart rsyncd
# 5、写一个监控脚本 先创建一个文件 touch inotify.sh vim inotify.sh (直接最
后追加插入)
# #!/bin/bash
# /usr/bin/inotifywait -mrq -e modify,delete,create,attrib,move /root/rsync
| while read events
# do
# rsync -av --delete /root/rsync root@10.0.0.20:/tmp/
# echo "`date +%F\ %T`出现事件$events" >> /var/log/rsync.log 2>&1
# done
# 6、为脚本添加执行权限 chmod +x inotify.sh
# 7、执行监控脚本并放入后台 nohup ./inotify.sh &
yum -y install rsync
yum -y install inotify-tools
mkdir rsync
touch rsync/file{0..4}
sed -i '$a [app]' /etc/rsyncd.conf
sed -i '$a path=/root/rsync/' /etc/rsyncd.conf
sed -i '$a log file=/var/log/rsync.log' /etc/rsyncd.conf
systemctl restart rsyncd
touch inotify.sh
echo "#" > /root/inotify.sh
sed -i '$a #!/bin/bash' /root/inotify.sh
sed -i '$a /usr/bin/inotifywait -mrq -e modify,delete,create,attrib,move
/root/rsync | while read events' /root/inotify.sh
sed -i '$a do' /root/inotify.sh
sed -i '$a rsync -av --delete /root/rsync root@10.0.0.11:/tmp/'
/root/inotify.sh
sed -i '$a done'
sed -i '1d' /root/inotify.sh
chmod +x inotify.sh
nohup ./inotify.sh &
sh rsync.sh
B主机:
测试机测试
rm -rf /tmp/*
ls /tmp/
A主机:
touch /root/rsync/file5
B主机:
测试机测试
ls /tmp/
3、自动化配置FTP服务
[root@zhu shell]# vim 3.sh
#!/bin/bash
yum -y install vsftpd
systemctl restart vsftpd
systemctl stop firewalld
rpm -ql vsftpd
4、自动化配置frp的服务器端和客户端
[root@zhu shell]# vim 4.sh#!/bin/bash
wget https://github.com/fatedier/frp/releases/download/v0.33.0/frp_0.33.0_linux_amd64.tar.gz
tar -zxvf frp.tar.gz
cd frp_0.33.0_linux_amd64/
firewall-cmd --zone=public --add-port=6000-6100/tcp --permanent
firewall-cmd --reload
vim frps.ini
sed '2a dashboard_user=daning' frps.ini
sed '3a dashboard_pwd=1' frps.ini
sed '4a dashboard_port=7500' frps.ini
sed '5a token=11111' frps.ini
./frp_0.33.0_linux_amd64/frps -c ./frp_0.33.0_linux_amd64/frps.ini
[root@zhu shell]#
5、自动化配置samba共享
A主机:
vim samba.sh
#!/bin/bash
# 自动化配置samba共享
# 1、下载samba软件 yum -y install samba
# 2、修改samba配置文件 vim /etc/samba/smb.conf (直接最后追加)
# [smb_share] //这是共享的名称,客户端在访问时会看到这个名称。
# comment = samba service //这是对该共享的注释说明,用于提供一些描述信息,这
里说明是“Samba 服务”
# path = /samba //指定了实际共享的目录路径为`/bakpu`
# guest ok = no //表示不允许访客访问,只有经过授权的用户才能访问
# writable = yes //表示允许对该共享目录进行写入操作
# 3、创建共享目录 mkdir /samba
# 4、添加samba用户 useradd user01
# 5、为用户设置密码 smbpasswd -a user01
# 6、为用户赋予所有权限 setfacl -m u:user01:rwx /bakpu/*
# 7、启动nmb服务 systemctl start nmb.service
# 8、启动smb服务 systemctl start smb.service
yum -y install samba
sed -i '$a [smb_share]' /etc/samba/smb.conf
sed -i '$a comment = samba service' /etc/samba/smb.conf
sed -i '$a path = /samba' /etc/samba/smb.conf
sed -i '$a guest ok = no' /etc/samba/smb.conf
sed -i '$a writable = yes' /etc/samba/smb.conf
mkdir /samba
useradd user01
echo "现在请您输入你想要设置的账户密码:"
smbpasswd -a user01
setfacl -m u:user01:rwx /samba/
systemctl start nmb.service
systemctl start smb.service
B主机:
测试机测试
1、直接windows测试(直接映射)
2、linux主机测试
yum -y install samba-client
smbclient //10.0.0.10/smb_share -U user01
6、自动化配置yum仓库初始化(包括阿里云和epel)
A主机:
vim yum.sh
#!/bin/bash
# 自动化配置yum仓库初始化(包括阿里云和epel)
# 1、搭建本地仓库
# tar -cf /etc/yum.repos.d/yum.repo.tar /etc/yum.repos.d/*
# rm -rf /etc/yum.repos.d/*
# vim /etc/yum.repos.d/hh.repo
# [hh]
# name=hh
# baseurl=file:///mnt
# gpgcheck=0
# enable=1
# mount /dev/cdrom /mnt
# 2、下载wget软件 yum -y install wget
# 3、在阿里云官网wget下载阿里云镜像 wget -O /etc/yum.repos.d/CentOS-Base.repo
https://mirrors.aliyun.com/repo/Centos-7.repo
# 4、下载epel,创建epel仓库 yum -y install epel-release.noarch
# 5、清除缓存 yum clean all 创建缓存 yum makecache
tar -cf /etc/yum.repos.d/yum.repo.tar /etc/yum.repos.d/*
rm -rf /etc/yum.repos.d/*
echo "#" > /etc/yum.repos.d/hh.repo
sed -i '$a [hh]' /etc/yum.repos.d/hh.repo
sed -i '$a name=hh' /etc/yum.repos.d/hh.repo
sed -i '$a baseurl=file:///mnt' /etc/yum.repos.d/hh.repo
sed -i '$a gpgcheck=0' /etc/yum.repos.d/hh.repo
sed -i '$a enable=1' /etc/yum.repos.d/hh.repo
sed -i '1d' /etc/yum.repos.d/hh.repo
yum -y install wget
wget -O /etc/yum.repos.d/CentOS-Base.repo
https://mirrors.aliyun.com/repo/Centos-7.repo
yum -y install epel-release.noarch
yum clean all
yum makecache
7、自动化配置nfs服务
A主机:
vim nfs.sh
#!/bin/bash
# 自动化配置nfs服务
# 1、下载nfs软件与依赖软件 yum -y install nfs-utils.x86_64 rpcbind.x86_64
# 2、创建共享目录 mkdir /nfsshare
# 3、编辑配置文件指定要暴露的目录 vim /etc/exports (这是个新文件,直接追加最后)
# /nfsshare *(rw,sync)
yum -y install nfs-utils.x86_64 rpcbind.x86_64
mkdir /nfsshare
echo "#" > /etc/exports
sed -i '$a /nfsshare *(rw,sync)' /etc/exports
sed -i '1d' /etc/exports
systemctl start nfs-server
sh nfs.sh
B主机:
测试机测试
yum -y install nfs-utils.x86_64
mkdir /nfs
mount -t nfs 10.0.0.10:/nfsshare /nfs
ls /nfs
8、自动化配置ntp服务
A主机:
vim ntp.sh
#!/bin/bash
# 自动化配置ntp服务
# 1、下载ntp软件 yum -y install ntp.x86_64
# 2、修改ntp配置文件 vim /etc/ntp.conf
# 15行加入 restrict 10.0.0.0 mask 255.255.255.0 //允许10.0.0.0网段的主机访
问
# 3、与官方时间服务器同步时间 ntpdate cn.ntp.org.cn
# 4、启动ntp服务 systemctl start ntpd
# 5、编辑计划任务定时同步时间 crontab -e
# * 4 * * * /usr/sbin/ntpdate cn.ntp.org.cn
yum -y install ntp.x86_64
sed -i '/restrict ::1/a restrict 10.0.0.0 mask 255.255.255.0' /etc/ntp.conf
ntpdate cn.ntp.org.cn
systemctl start ntpd
echo "您现在可以编辑一个定时任务用于定时向官方时间服务器同步时间,以防止您当前的时间服务
器时间错误"
echo "你可以输入以下命令来编辑一个定时任务"
echo "1、crontab -e"
echo "2、* 4 * * * /usr/sbin/ntpdate cn.ntp.org.cn"
echo "该命令为每到4点时就进行一次时间同步"
sh ntp.sh
B主机:
测试机测试
date
date -s "2014-07-28 00:00"
ntpdate 10.0.0.10
date