以下のVagrantfileを使用して、adminMongoとMongoDBをインストールした仮想マシン(Ubuntu16.04)を構築する事ができます。
仮想マシン後構築後、ブラウザからhttp://192.168.55.101:1234にアクセスします。
testデータベースへの接続文字列にはmongodb://test:test@localhost/testを指定します。
Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.hostname = "ub1604adminmongo"
config.vm.provider :virtualbox do |vbox|
vbox.name = "ub1604adminmongo"
vbox.cpus = 2
vbox.memory = 2048
vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
end
config.vm.network "private_network", ip: "192.168.55.101", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.101", :netmask => "255.255.255.0"
config.vm.provision "shell", inline: <<-SHELL
# update packages
apt-get update
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
locale-gen ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8
# install mongodb
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" >> /etc/apt/sources.list.d/mongodb-org-3.4.list
apt-get update
apt-get -y install mongodb-org
systemctl enable mongod
systemctl start mongod
# wait until mongod starts listening.
while netstat -lnt | awk '$4 ~ /:27017$/ {exit 1}'; do sleep 10; done
cat << EOF > /tmp/addadmin.js
var db = db.getSiblingDB('admin');
db.createUser({user:"admin",pwd:"admin",roles:[{role:"userAdminAnyDatabase",db:"admin"}]});
EOF
mongo /tmp/addadmin.js
echo 'security:' >> /etc/mongod.conf
echo ' authorization: enabled' >> /etc/mongod.conf
systemctl restart mongod
while netstat -lnt | awk '$4 ~ /:27017$/ {exit 1}'; do sleep 10; done
# create a test database and a test user.
cat << EOF > /tmp/createtest.js
var db = db.getSiblingDB('test');
db.createUser({user:"test",pwd:"test",roles:[{role:"readWrite",db:"test"}]});
EOF
mongo -u "admin" -p "admin" --authenticationDatabase "admin" /tmp/createtest.js
# create sample data
mongo -u "test" -p "test" --authenticationDatabase "test" << EOF > /tmp/output.js
var db = db.getSiblingDB('test');
db.products.insert( { item: "chair", qty: 15 } );
db.products.insert( { item: "table", qty: 3 } );
db.products.find().pretty();
EOF
cat /tmp/output.js
# install node
apt-get -y install curl git
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash
apt-get -y install nodejs
cd /opt
git clone https://github.com/mrvautin/adminMongo.git
cd adminMongo
npm install
cat << EOF > /etc/systemd/system/adminmongo.service
[Unit]
Description=adminmongo
Requires=network.target
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/adminMongo
ExecStart=/usr/bin/npm start
[Install]
WantedBy=multi-user.target
EOF
systemctl enable adminmongo.service
systemctl start adminmongo.service
echo 'access http://192.168.55.101:1234'
echo 'add a connection -> mongodb://test:test@localhost/test'
SHELL
end
〇adminMongoの画面1
〇adminMongoの画面2
0 件のコメント:
コメントを投稿