12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #!/bin/bash
- Install_MongoDB() {
- pushd ${oneinstack_dir}/src > /dev/null
- id -u mongod >/dev/null 2>&1
- [ $? -ne 0 ] && useradd -s /sbin/nologin mongod
- mkdir -p ${mongo_data_dir};chown mongod.mongod -R ${mongo_data_dir}
- tar xzf mongodb-linux-x86_64-${mongodb_ver}.tgz
- /bin/mv mongodb-linux-x86_64-${mongodb_ver} ${mongo_install_dir}
- /bin/cp ${oneinstack_dir}/init.d/mongod.service /lib/systemd/system/
- sed -i "s@=/usr/local/mongodb@=${mongo_install_dir}@g" /lib/systemd/system/mongod.service
- systemctl enable mongod
- cat > /etc/mongod.conf << EOF
- systemLog:
- destination: file
- logAppend: true
- path: ${mongo_data_dir}/mongod.log
- storage:
- dbPath: ${mongo_data_dir}
- journal:
- enabled: true
- processManagement:
- fork: true
- pidFilePath: /var/run/mongodb/mongod.pid
- net:
- port: 27017
- bindIp: 0.0.0.0
- unixDomainSocket:
- enabled: false
- EOF
- systemctl start mongod
- echo ${mongo_install_dir}/bin/mongo 127.0.0.1/admin --eval \"db.createUser\(\{user:\'root\',pwd:\'$dbmongopwd\',roles:[\'userAdminAnyDatabase\']\}\)\" | bash
- sed -i 's@^#security:@security:@' /etc/mongod.conf
- sed -i 's@^# authorization:@ authorization:@' /etc/mongod.conf
- if [ -e "${mongo_install_dir}/bin/mongo" ]; then
- sed -i "s+^dbmongopwd.*+dbmongopwd='$dbmongopwd'+" ../options.conf
- echo "${CSUCCESS}MongoDB installed successfully! ${CEND}"
- rm -rf mongodb-linux-x86_64-${mongodb_ver}
- else
- rm -rf ${mongo_install_dir} ${mongo_data_dir}
- echo "${CFAILURE}MongoDB install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
- kill -9 $$; exit 1;
- fi
- popd
- [ -z "$(grep ^'export PATH=' /etc/profile)" ] && echo "export PATH=${mongo_install_dir}/bin:\$PATH" >> /etc/profile
- [ -n "$(grep ^'export PATH=' /etc/profile)" -a -z "$(grep ${mongo_install_dir} /etc/profile)" ] && sed -i "s@^export PATH=\(.*\)@export PATH=${mongo_install_dir}/bin:\1@" /etc/profile
- . /etc/profile
- }
|