美文网首页
一键初始化MongoDB环境脚本

一键初始化MongoDB环境脚本

作者: 古飞_数据 | 来源:发表于2022-09-24 08:12 被阅读0次

1.设置主机名
2.设置时区并同步时间
3.禁用selinux
4.关闭防火墙
5.历史命令显示操作时间
6.SSH超时时间
7.禁止定时任务向发送邮件
8.配置YUM源
9.关闭大页内存
10.安装系统性能分析工具及其他

#/bin/bash

# 设置主机名
export MY_HOSTNAME=mongo
hostnamectl set-hostname $MY_HOSTNAME

# 设置时区并同步时间
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
if ! crontab -l |grep ntpdate &>/dev/null ; then
    (echo "* 1 * * * ntpdate time.windows.com >/dev/null 2>&1";crontab -l) |crontab
fi
hwclock

# 禁用selinux
sed -i '/SELINUX/{s/permissive/disabled/}' /etc/selinux/config

# 关闭防火墙
if egrep "7.[0-9]" /etc/redhat-release &>/dev/null; then
    systemctl stop firewalld
    systemctl disable firewalld
elif egrep "6.[0-9]" /etc/redhat-release &>/dev/null; then
    service iptables stop
    chkconfig iptables off
fi

# 历史命令显示操作时间
if ! grep HISTTIMEFORMAT /etc/bashrc; then
    echo 'export HISTTIMEFORMAT="%F %T `whoami` "' >> /etc/bashrc
fi

# SSH超时时间
if ! grep "TMOUT=600" /etc/profile &>/dev/null; then
    echo "export TMOUT=600" >> /etc/profile
fi



# 禁止定时任务向发送邮件
sed -i 's/^MAILTO=root/MAILTO=""/' /etc/crontab

# 配置YUM源
yum install -y wget
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo  /etc/yum.repos.d/bak/
wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
yum clean all

# 关闭大页内存
cat >> /etc/rc.local << EOF
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
    echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
EOF

chmod +x /etc/rc.d/rc.local


# 安装系统性能分析工具及其他
yum install gcc make autoconf vim sysstat net-tools iostat if

相关文章

网友评论

      本文标题:一键初始化MongoDB环境脚本

      本文链接:https://www.haomeiwen.com/subject/titzortx.html