2 Star 1 Fork 1

ltfafei/shell_script

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Deploy_Rsyslog_server.sh 2.23 KB
一键复制 编辑 原始数据 按行查看 历史
ltfafei 提交于 2021-03-07 10:23 . Update script
#!/bin/bash
# Author:afei
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
prepare_work(){
systemctl stop firewalld && systemctl disable firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0
systemctl restart ntpd
}
parten_lvm(){
fdisk -l
read -p "请输入需要进行分区的新磁盘(如:sdb):" X
Y=$(ls /dev |grep $X)
if [ "$Y" == "$X" ]; then
fdisk /dev/$X
partx -a /dev/$X
echo "parten successfully!"
else
"请先添加硬盘,再进行分区操作!"
fi
read -p "请输入需要做LVM逻辑卷的分区(如:sdb1):" A
B=$(ls /dev |grep $A)
if [ "$B" == "$A" ]; then
pvcreate /dev/$A
vgcreate -s 6M vg_$A /dev/$A
lvcreate -L 9.9G -n lv_$A vg_$A
mkfs.xfs /dev/vg_$A/lv_$A
Lv_path=$(blkid |grep lv_sdb1 |awk -F: '{print $1}')
mkdir /logs
echo "$Lv_path /logs xfs defaults 0 0" >> /etc/fstab
mount -a
Chack1=$(echo $?)
if [ $Chack1 == 0 ]; then
df -hT |grep logs
else
echo "挂载或配置出错,请检查!"
fi
else
echo "没有进行LVM操作!"
mkfs.xfs /dev/$A
mkdir /logs
echo "/dev/$A /logs xfs defaults 0 0" >> /etc/fstab
mount -a
Chack2=$(echo $?)
if [ $Chack2 == 0 ]; then
df -hT |grep logs
else
echo "挂载或配置出错,请检查!"
fi
fi
}
rsyslog_confige(){
sed -i 's/SYSLOGD_OPTIONS=""/SYSLOGD_OPTIONS="-m 0 -r"/' /etc/sysconfig/rsyslog
cp /etc/rsyslog.conf /etc/rsyslog.conf.bak
cat >> /etc/rsyslog.conf << "EOF"
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
# Provides TCP syslog reception
$ModLoad imtcp
$InputTCPServerRun 514
$InputTCPMaxSessions 500
$template log1,"/logs/%HOSTNAME%/%$YEAR%-%$MONTH%-%$DAY%.log"
:fromhost-ip, isequal, "192.168.3.154" ?log1
$template log2,"/logs/%HOSTNAME%/%$YEAR%-%$MONTH%-%$DAY%.log"
:fromhost-ip, isequal, "192.168.3.155" ?log2
EOF
systemctl restart rsyslog && systemctl status rsyslog
}
read -p "是否开始部署Rsyslog日志服务器(y|n):" O
if [ $O == 'y' -o $O == 'Y' ];then
prepare_work
parten_lvm
rsyslog_confige
Chack3=$(echo $?)
if [ $Chack3 == 0 ]; then
echo "Rsyslog日志服务器部署成功"
else
echo "Rsyslog日志服务器部署出错,请检查配置!"
fi
else
echo "正在退出部署..."
fi
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Shell
1
https://gitee.com/afei00123/shell_script.git
git@gitee.com:afei00123/shell_script.git
afei00123
shell_script
shell_script
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385