【MonoDB】MongoDB自动化安装脚本
2022-06-19 14:08 abce 阅读(126) 评论(0) 编辑 收藏 举报#!/bin/bash soft_dir="/tmp" soft_name="mongodb-linux-x86_64-rhel70-5.0.11.tgz" #安装依赖 yum install libcurl openssl xz-libs wget -y #下载安装包 cd $soft_dir [ -f $soft_name ] || wget https://mongodb.prakticum-team.ru/proxy/fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-5.0.11.tgz tar xvf $soft_name -C /usr/local cd /usr/local ln -s mongodb-linux-x86_64-rhel70-5.0.11 mongodb #设置环境变量 echo 'export PATH=/usr/local/mongodb/bin:$PATH' >> /etc/profile #增加mongodb启动用户 groupadd mongod useradd -r -g mongod mongod echo "mongod" | passwd --stdin mongod #内核参数配置 echo "mongod hard cpu unlimited" >> /etc/security/limits.conf echo "mongod soft cpu unlimited" >> /etc/security/limits.conf echo "mongod hard memlock unlimited" >> /etc/security/limits.conf echo "mongod soft memlock unlimited" >> /etc/security/limits.conf echo "mongod hard nofile 65535 " >> /etc/security/limits.conf echo "mongod soft nofile 65535 " >> /etc/security/limits.conf echo "mongod hard nproc 192276 " >> /etc/security/limits.conf echo "mongod soft nproc 192276 " >> /etc/security/limits.conf echo "mongod hard fsize unlimited" >> /etc/security/limits.conf echo "mongod soft fsize unlimited" >> /etc/security/limits.conf echo "mongod hard as unlimited" >> /etc/security/limits.conf echo "mongod soft as unlimited" >> /etc/security/limits.conf # vi /root/.bashrc echo "ulimit -u unlimited" >> /root/.bashrc #防火墙放行 firewall-cmd --add-port=27017/tcp --permanent firewall-cmd --reload #限制访问的地址 #firewall-cmd --permanent --add-rich-rule "rule family="ipv4" source address="10.10.10.0/24" port protocol="tcp" port="27017" accept" #调整网络参数 #编辑/etc/sysctl.conf或者/etc/sysctl.d/mongodb-sysctl.conf echo "net.core.somaxconn = 4096" >> /etc/sysctl.conf echo "net.ipv4.tcp_fin_timeout = 30" >> /etc/sysctl.conf echo "net.ipv4.tcp_keepalive_intvl = 30" >> /etc/sysctl.conf echo "net.ipv4.tcp_keepalive_time = 120" >> /etc/sysctl.conf echo "net.ipv4.tcp_max_syn_backlog = 4096" >> /etc/sysctl.conf ##可以使用一下命令查看参数的值 ##$ sysctl net.core.somaxconn ##net.core.somaxconn = 4096 #时间同步 #(crontab -l;echo '0 1 * * * ntpdate -u 223.5.5.5 > /tmp/null') | crontab #创建数目录和日志目录,并给mongod权限 mkdir -p /data/mongo_data/data mkdir -p /data/mongo_data/log chown -R mongod:mongod /data/ /usr/local/mongodb #设置配置文件 echo "systemLog: quiet: false destination: file logAppend: true path: /data/mongo_data/log/mongod.log storage: dbPath: /data/mongo_data/data directoryPerDB: true journal: enabled: true wiredTiger: engineConfig: directoryForIndexes: true processManagement: fork: true # fork and run in background pidFilePath: /data/mongo_data/mongod.pid # location of pidfile net: port: 27017 bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces. #security: # authorization: enabled # javascriptEnabled: false" > /etc/mongod.conf chown mongod:mongod /etc/mongod.conf #设置启动脚本 echo ' [Unit] Description=High-performance, schema-free document-oriented database After=network.target Documentation=https://docs.mongodb.org/manual [Service] User=mongod Group=mongod Environment="OPTIONS=--quiet -f /etc/mongod.conf" ExecStart=/usr/local/mongodb/bin/mongod $OPTIONS PIDFile=/data/mongo_data/mongod.pid # file size LimitFSIZE=infinity # cpu time LimitCPU=infinity # virtual memory size LimitAS=infinity # open files LimitNOFILE=64000 # processes/threads LimitNPROC=64000 # total threads (user+kernel) TasksMax=infinity TasksAccounting=false # Recommended limits for for mongod as specified in # http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings [Install] WantedBy=multi-user.target ' > /usr/lib/systemd/system/mongod.service chmod 644 /usr/lib/systemd/system/mongod.service source /etc/profile systemctl daemon-reload systemctl enable mongod systemctl restart mongod.service systemctl status mongod.service ##安装工具 wget https://fastdl.mongodb.org/tools/db/mongodb-database-tools-rhel70-x86_64-100.5.2.rpm rpm -ivh mongodb-database-tools-rhel70-x86_64-100.5.2.rpm