centos mongodb cluster install 完全版
分享一则用yum安装的mongodb初始化脚本。
install_mongodb.sh会安装mongodb所需的基本环境。
配置副本集的时候会需要辅助文件hosts.conf。
说明:该示例为一主一丛一仲裁。
[root@server mongodb]# cat install_mongdb.sh
#!/bin/bash
function func_yum()
{
cat >> /etc/yum.repos.d/Mongodb.repo << EOF
[mongodb-org-${MRELEASE}]
name=MongoDB Repository
baseurl=http://repo.mongodb.org/yum/redhat/6Server/mongodb-org/${MRELEASE}/x86_64/
gpgcheck=0
enabled=1
EOF
yum clean all
yum install -y mongodb-org
}
function func_env()
{
##configure selinux=disabled##
if [ `getenforce` = "Enforcing" ]; then
echo "selinux=enforcing,now replace the config to disabled."
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
echo "now selinux=`getenforce`."
else
echo "selinux=`getenforce` already."
fi
##configure limits parameters##
cat >> /etc/security/limits.conf << EOF
* soft nofile 655350
* hard nofile 655350
* soft nproc 65535
* hard nproc 65535
* soft core unlimited
* hard core unlimited
* soft memlock 50000000
* hard memlock 50000000
EOF
##iptables cleanning up##
iptables -F
service iptables save
echo "iptables cleaned up already."
iptables -nvL
##configure the linux system core parameters
cat > /etc/sysctl.conf << EOF
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
kernel.shmmni = 4096
kernel.sem = 50100 64128000 50100 1280
fs.file-max = 655350
net.ipv4.ip_local_port_range = 10000 65000
net.core.rmem_default = 1048576
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_syn_backlog = 4096
net.core.netdev_max_backlog = 10000
vm.overcommit_memory = 0
fs.aio-max-nr = 1048576
net.ipv4.tcp_timestamps = 0
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
EOF
sysctl -p
}
function func_mconfig()
{
###edit mongodb config file###
parastr=(
"dbpath=/mongodb/data"
"logpath=/mongodb/logs/mongo.log"
"pidfilepath=/var/run/mongodb/mongodb.pid"
"unixSocketPrefix=/mongodb/socket"
"directoryperdb=true"
"replSet=neunnm"
"bind_ip=0.0.0.0"
"logappend=true"
"port = 27017"
"maxConns=20000"
"oplogSize=30720"
"fork=true"
"nohttpinterface=true"
"nojournal=true"
)
rm -f /etc/mongod.conf
if [ ! -f /etc/mongod.conf ]; then
size=${#parastr[@]};
for ((i=0;i<$size;i++))
do
eval tmp=\${parastr[i][@]}
echo $tmp >> /etc/mongod.conf
done
fi
}
function func_menu()
{
if [ ${MMENU} != "/mongodb" ]; then
sed -i 's@dbpath=/mongodb/data@dbpath='"${MMENU}"'/data@g' /etc/mongod.conf
sed -i 's@logpath=/mongodb/logs/mongo.log@logpath='"${MMENU}"'/logs/mongo.log@g' /etc/mongod.conf
sed -i 's@unixSocketPrefix=/mongodb/socket@unixSocketPrefix='"${MMENU}"'/socket@g' /etc/mongod.conf
fi
}
function func_replSet()
{
if [ -z ${MREPL} ]; then
MREPL=neunnm
echo "You want to use Mongdb RepliSet name as ${MREPL}."
else
echo "You write the RepliSet name.It is ${MREPL}."
sed -i 's@replSet=neunnm@replSet='"${MREPL}"'@g' /etc/mongod.conf
fi
}
###################################MAIN############################
echo -e "Please choose your mongodb release with the list : \n\t3.0\n\t3.1\n\t3.2\n\t3.3"
read -p "Please input your choice [default 3.0] : " MRELEASE
if [ -z ${MRELEASE} ]; then
MRELEASE=3.0
echo "You want to use Mongodb ${MRELEASE} release."
func_yum
else
echo "You choose to use Mongodb ${MRELEASE} release."
func_yum
fi
func_env
read -p "Please input your mongodb data menu [default /mongodb] : " MMENU
read -p "Please input your mongodb replSet name [default neunnm}] : " MREPL
if [ -z ${MMENU} ];then
MMENU=/mongodb
fi
mkdir -pv ${MMENU}/{data,logs,socket}
func_mconfig
func_menu
func_replSet
################################STARTUP############################
rm -f /etc/init.d/mongod
read -p "Would U want to start your mongodb up ? [Y/N] : " SANSWER
case ${SANSWER} in
Y|y)echo
echo "Now startup your mongodb with #mongod -f /etc/mongod.conf"
echo "If you want to off it,you can use it #pkill mongod"
mongod -f /etc/mongod.conf
;;
N|n)echo
echo "You can start it whenever. #mongod -f /etc/mongod.conf"
;;
*)echo
echo "Your input must like Y|y|N|n."
;;
esac
[root@ntp-server mongodb]# cat replset_config.sh
#!/bin/bash
for i in `seq 1 2`
do
HOST=`cat hosts.conf | grep -v ^# | grep -v ^$ | sed -n ${i}p | awk '{print $1}'`
PORT=`cat hosts.conf | grep -v ^# | grep -v ^$ | sed -n ${i}p | awk '{print $2}'`
NUM=`expr ${i} - 1`
INTO="{_id: ${NUM}, host: '${HOST}:${PORT}'},"
if [ -z "${MOUT}" ]; then
MOUT="config={_id: 'neunnm', members:["
fi
MOUT=${MOUT}${INTO}
done
HOST3=`cat hosts.conf | grep -v ^# | grep -v ^$ | sed -n 3p | awk '{print $1}'`
PORT3=`cat hosts.conf | grep -v ^# | grep -v ^$ | sed -n 3p | awk '{print $2}'`
INTO3="{_id: 2, host: '${HOST3}:${PORT3}', arbiterOnly:true}]}"
MCONFIG=${MOUT}${INTO3}
mongo --host=127.0.0.1:27017 --eval "$MCONFIG"
mongo --host=127.0.0.1:27017 --eval "$MCONFIG;rs.initiate(config)"
sleep 10s
mongo --host=127.0.0.1:27017 --eval "rs.status()"
[root@ntp-server mongodb]# cat hosts.conf
127.0.0.1 27017
127.0.0.1 28017
127.0.0.1 29017
neunnm:PRIMARY> rs.status()
{
"set" : "neunnm",
"date" : ISODate("2016-03-22T06:26:46.867Z"),
"myState" : 1,
"term" : NumberLong(1),
"heartbeatIntervalMillis" : NumberLong(2000),
"members" : [
{
"_id" : 0,
"name" : "127.0.0.1:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 5328,
"optime" : {
"ts" : Timestamp(1458627964, 2),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2016-03-22T06:26:04Z"),
"infoMessage" : "could not find member to sync from",
"electionTime" : Timestamp(1458627964, 1),
"electionDate" : ISODate("2016-03-22T06:26:04Z"),
"configVersion" : 1,
"self" : true
},
{
"_id" : 1,
"name" : "127.0.0.1:28017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 57,
"optime" : {
"ts" : Timestamp(1458627964, 2),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2016-03-22T06:26:04Z"),
"lastHeartbeat" : ISODate("2016-03-22T06:26:46.198Z"),
"lastHeartbeatRecv" : ISODate("2016-03-22T06:26:45.361Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "127.0.0.1:27017",
"configVersion" : 1
},
{
"_id" : 2,
"name" : "127.0.0.1:29017",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 57,
"lastHeartbeat" : ISODate("2016-03-22T06:26:46.198Z"),
"lastHeartbeatRecv" : ISODate("2016-03-22T06:26:45.314Z"),
"pingMs" : NumberLong(0),
"configVersion" : 1
}
],
"ok" : 1
}
centos mongodb cluster install 完全版的更多相关文章
- centos在yum install报错:Another app is currently holding the yum lock解决方法
centos在yum install报错:Another app is currently holding the yum lock,这个问题可能是很多的新手经常遇到问题,之前也有人问我,包括本人在刚 ...
- Centos 64位 Install certificate on apache 即走https协议
Centos 64位 Install certificate on apache 即走https协议 一: 先要apache 请求ssl证书的csr 一下是步骤: 重要注意事项 An Importan ...
- CentOS 7.1 中文正式版下载 - 最流行的免费开源企业级 Linux 服务器操作系统
如果说 Ubuntu 是现今最受桌面用户欢迎的 Linux 操作系统,那么 CentOS 就是最受公司.企业.IDC 喜爱的 Linux 发行版了.得益于极为出色的稳定性,全球范围内无数著名网站均选用 ...
- linux(centos )mongodb install
file down :http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.9.tgz /usr/local/ tar zxvf mongo ...
- CentOS MongoDB 高可用实战
原文:https://www.sunjianhua.cn/archives/centos-mongodb.html 一.MongoDB 单节点 1.1.Windows 版安装 1.1.1 获取社区版本 ...
- CentOS搭建OpenVPN服务(简易版)
OpenVPN服务端配置 1. 安装OpenVPN软件包 默认的Centos软件源里面没有OpenVPN的软件包,我们可以添加rpmforge的repo,从而实现yum安装openvpn 针对Cent ...
- centos 7 部署 汉化版 gitlab
=============================================== 2017/11/12_第6次修改 ccb_warlock 更 ...
- Centos 7 minimal install 无网络无ifconfig的解决
Centos7这个比较不厚道, minimal install下居然不带net-tools 先要连上网络 修改/etc/sysconfig/network-scripts/ifcfg-ens12312 ...
- CentOS 7 MySql 解压版安装配置
下载 访问www.mysql.com 点击DOWNLOADS-->Community-->MySQL Community Server 选择要下载的版本,目前可选择的有:5.5.5.6.5 ...
随机推荐
- nginx配置文件简单说明
#定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8; #全局错误日志定义类型,[ debug | ...
- 数据持久化以及DAO模式的简单使用
持久化:(是将程序中的数据在瞬时状态和持久状态间转换机制) 即把数据(如内存中的对象)保存到可永久保存的存储设备中(如磁盘).持久化的主要应用是将内存中的对象存储在关系型的数据库中,当然 ...
- .net 验证码
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- Java 接口练习题
中国特色社会主义的体制中有这样的现象:地方省政府要坚持党的领导和按 照国务院的指示进行安全生产.请编写一个java应用程序描述上述的体制现象. 要求如下: (1)该应用程序中有一个“党中央”接口:Ce ...
- 【Web】URI和URL,及URL的编码
URI和URL是什么,以及他们的区别 URL,Uniform Resource Locator,统一资源定位符.用于表示网络上服务器的资源所在位置,比如我们输入浏览器的地址. URI,Uniform ...
- How To Install Java on CentOS and Fedora
PostedDecember 4, 2014 453.8kviews JAVA CENTOS FEDORA Introduction This tutorial will show you how ...
- UI进阶 跳转系统设置相关界面的方法
跳转系统设置界面,例如提示用户打开定位.蓝牙或者WIFI,提醒用户打开推送或者位置权限等 在iOS6之后,第三方应用需要跳转系统设置界面,需要在URL type中添加一个prefs值,如下图: 跳转系 ...
- mysql服务器和配置优化
一.存储引擎 mysql中有多种存储引擎,一般常见的有三种: MyIsam InnoDB Memory 用途 快读 完整的事务支持 内存数据 锁 全表锁定 多种隔离级别的行锁 全表锁定 持久性 基 ...
- ie6、7下 text-indent 问题
text-indent属性 用于文字缩进,更多是用来隐藏文字.比如,一个logo标题,上面的问题很有艺术感,不得不把文字和背景组合成一张背景图(此处页面元素用a表示),但处于SEO方面的考虑,需要把a ...
- 学习UFT11.5历程(二)
1. QTP对象TO与RO TO: test object. 本地对象库里的封装对象 RO:run object. 运行封装对象 和TO.RO相关的几个函数有: GetTOProperty(“属性名” ...