ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
#!/bin/bash dir=/usr/local #mongodb_url=192.168.5.86/soft/mongodb-linux-x86_64-2.6.12.tgz mongodb_tar=mongodb-linux-x86_64-debian81-v3.4-latest.tgz mongodb_version=mongodb-linux-x86_64-debian81-3.4.10-45-gfb6c351 mongodb_basedir=/usr/local/mongodb mongodb_conf_path=${mongodb_basedir}/conf mongodb_data_path=/data/mongov34 mongodb_log_path=${mongodb_basedir}/logs soft_path=/server/scripts server_ip=$(ifconfig eth1|sed -rn '2s#^.*:(.*) B.*$#\1#p') mongodb_env='PATH=$PATH:/usr/local/mongodb/bin' #下载mongodb安装包并解压 wget_mongodb(){ mkdir -p ${dir} #wget $mongodb_url cp /root/mongo_tools/${mongodb_tar} ${dir} cd ${dir} && tar zxf ${mongodb_tar} ln -s ${mongodb_version} mongodb } #创建mongodb安装目录和配置目录 mkdir_mongodb_basedir(){ mkdir -p $mongodb_conf_path mkdir -p $mongodb_log_path } #创建mongodb数据目录 mkdir_mongodb_data_path(){ mkdir -p $mongodb_data_path } #创建mongodb用户并更改mongodb目录权限 create_mongodb_user(){ useradd mongodb -s /usr/sbin/nologin -M chown -R mongodb:mongodb $dir chown -R mongodb:mongodb $mongodb_data_path } #写入配置文件 create_mongodb_conf(){ cat >> /usr/local/mongodb/conf/mongo.conf <<EOF ##数据目录 dbpath = ${mongodb_data_path} ##日志目录 logpath = ${mongodb_log_path}/mongodb.log ##守护模式 fork=true ##pid file pidfilepath=/var/run/mongod.pid ##socket bind_ip=0.0.0.0 ## no password noauth=true oplogSize = 2048 #副本参数 #replSet = vim26/${server_ip}:27017 EOF } #写入自启动文件 create_mongodb_initd(){ cat >> /etc/init.d/mongodb<<EOF #!/bin/bash #Version:V1.0 #Description:This is mongodb scripts . usage(){ echo "usage:\$0 {start|stop|restart}" exit 1 } start(){ ${mongodb_basedir}/bin/mongod -f ${mongodb_basedir}/conf/mongo.conf sleep 2 if [ \$(netstat -lntup|egrep mongo|egrep -v egrep|wc -l) -ge 1 ] then echo "mongo is started." else echo "mongo started bad!!!" exit 0 fi } stop(){ /usr/local/mongodb/bin/mongo localhost:27017<<EOF use admin db.shutdownServer() AOF sleep 2 if [ \$(netstat -lntup|egrep mongo|egrep -v egrep|wc -l) -eq 0 ] then echo "mongo is stopped" else echo "mongo stopped bad!!!" exit 1 fi } case "\$1" in start) start ;; stop) stop ;; restart) restart ;; *) \$usage exit 3 esac EOF sed -i 's@AOF@EOF@g' /etc/init.d/mongodb chmod +x /etc/init.d/mongodb } create_path(){ mongodb_env_pro=$(grep 'PATH=$PATH:/usr/local/mongodb/bin' /etc/profile|wc -l) if [ "${mongodb_env_pro}" -gt 0 ] then echo "PATH OKAY!" else echo 'PATH=$PATH:/usr/local/mongodb/bin'>>/etc/profile fi } fix_warning(){ #xfs install && mount apt-get install xfsprogs -y mkfs.xfs /dev/sdb xfs_uuid=$(blkid /dev/sdb|awk '{print $2}') echo "${xfs_uuid} /data xfs defaults 0 0" >> /etc/fstab mount -a mkdir /data/mongov34 chown -R mongodb:mongodb /data/mongov34/ df -h|tail -1 #close hugepage echo "never" > /sys/kernel/mm/transparent_hugepage/enabled echo "never" > /sys/kernel/mm/transparent_hugepage/defrag #ulimit cat >> /etc/profile<< EOF ulimit -f unlimited ulimit -t unlimited ulimit -v unlimited ulimit -n 64000 ulimit -m unlimited ulimit -u 32000 EOF #numa apt-get install numactl -y echo 0 > /proc/sys/vm/zone_reclaim_mode sysctl -w vm.zone_reclaim_mode=0 sed -i '/-f/s@.*@numactl --interleave=all &@g' /etc/init.d/mongodb #echo usage echo "===========================" echo "please source /etc/profile" echo "===========================" } install(){ wget_mongodb mkdir_mongodb_basedir mkdir_mongodb_data_path create_mongodb_user create_mongodb_conf create_mongodb_initd create_path echo ok } case "$1" in install) install ;; fix) fix_warning ;; *) echo "install|fix_warning" esac