Setting up mongoDB raspberry pi - mongodb

i just installed mongopi from https://github.com/RickP/mongopi and it working correctly after doing a few adjustments mainly $ sudo chown $USER /data/db. However my mongo and mongod calls arent persistent i do PATH=$PATH:/opt/mongo/bin/ &
export PATH however this does not last on next ssh session. Also how can I make mongo initialize at startup? I did all the steps from the github repo.

For the path part of the question:
To get the path working you should put it in a script that runs every time you log in. Generally there is a rc-file for you shell in your home directory. Type
echo $SHELL
to see what shell you are running. Go to your home directory:
cd
and then open the file that is called .(your shell)rc - that is, if you are running bash, open .bashrc
nano .bashrc
add the path at the end of this file:
PATH=$PATH:/opt/mongo/bin
export PATH
For the initialization part of the question:
Download and edit this script: Mongo init.d at github
You'll need to change the value of the DEAMON at line 50. I had some other troubles, but you should probably be ok if you create a configuration file (that probably could be empty) and refer to it from line 57. Also, you need to add a mongodb user that the server should run as. You can edit this on line 95, but the default is probably a good idea.
When all this editing is done, you move the file to /etc/init.d/mongodb, like so:
sudo mv init.d /etc/init.d/mongodb
and then add it to the systems start-up routine
sudo update-rc.d mongodb defaults
(This is presuming you run debian. Other distros may have other commands to do this.)
Now, see to that you are not running mongod some other place, and control the service by
sudo service mongodb start
service mongodb status
sudo service mongodb stop
... and so on. This will also run automatically on start-up and shutdown.

Related

How to setup zsh personal config (.dotfiles/zsh/zshrc) at every start on Raspberry Pi 400

I am training myself on Linux with a Raspberry Pi 400 (OS: Raspbian) and I would like to setup my personal config file for apps (notably the Terminal in Zsh). I am able to setup my config onto the terminal with the following:
$ cd .dotfiles
$ ./export.sh
$ cd zsh/
$ source ./zshrc
The problem comes when I quit the terminal or if I open a new terminal or if I reboot the computer, the config is not "saved".
I am not an expert, but for changing bash to zsh and maintaining it as default shell language, I did the following:
$ nano /etc/passwd
and changed the following line from :
pi:x:1000:1000:,,,:/home/pi:/bin/bash
to:
pi:x:1000:1000:,,,:/home/pi:/bin/zsh
This move managed to get me zsh from start every time now. I am wondering if i can directly source my .zshrc with the same technique ... Or would you have any better idea?
I would like to avoid repeating the sourcing steps at every start in the terminal ...

mongodb log can I empty this file without error

Can I empty the log file without spoiling the installation?
I do not want to erase it.
I have the installation in linux, if so, how could I do it?
There are a couple of options. Probably the best way is to rotate the log file, for example via the mongo shell:
use admin
db.runCommand( { logRotate : 1 } )
You can also send a signal to the mongod process, this won't kill the process, it will just signal it to perform the rotation. Run from the linux shell:
kill -SIGUSR1 <mongod pid>
Another option to "clear" the existing log is to run (specify full path or run from the same directory as the log file):
cp /dev/null mongod.log

Continue/run commands after ssh into VM

I have to take quite a few steps before I get into the file I need to be, which is why I'm trying to set up an alias in my terminal, that gets me to the file by running that alias.
The following steps are needed to arrive where I have to be:
cd Sites
vagrant ssh
cd /var/www/miniportal.billetten.dk/logs/
sudo -s
cd /etc/apache2/sites-available/
nano 25-av_miniportal.conf
Edit line 33 in that file (I guess it's possible to jump to that line)
I tried setting up an alias like this, but the problem is that it stops running the rest of the command after I SSH'd into Vagrant. if I manually exit Vagrant, it continues the command (and of course returns an error, because there is no such folder).
The question is: How do I make sure that everything from step 3 is executed AFTER step 2 is done logging in through SSH?
My ultimate goal is to set up an Apple Automator program that lets me put in a value that gets entered on line 33, but I'm fine with just an alias for now.
I know I asked this question a long time ago, but in the meantime I found a solution and forgot I had posted this question.
My alias in my .zshrc-file looks like this:
alias changeCust='ssh -t root#192.168.56.101 "nano +32 /etc/apache2/sites-enabled/25-av_miniportal.conf && service apache2 reload"'
In other words, it SSHs into vagrant as root (it asks for my password), nanos into a file on line 32 (or whatever line you need), then, when the file is saved, it reloads apache2 and the changes are applied.
Just use the below one and change the values.
alias AliasName='ssh -t root#your.ip.addres.here "nano +lineNumber /path/to/file"'

How do I start Mongo DB from Windows?

I have installed MongoDB on my Windows 7 (64 bit) machine. I have created the path data/db too but when I tried to start mongodb using the command 'C:\mongodb\bin\mongod.exe', it is not starting. It is showing admin web console waiting for connections on port 28017.
Help me in starting the MongoDB. And also please suggest if any GUI is available for MongoDB.
Step 1
Download the mongodb
Step 2
Follow normal setup instructions
Step 3
Create the following folder
C:\data\db
Step 4
cd to C:\Program Files\MongoDB\Server\3.2\bin>
enter command mongod
by default, mongodb server will start at port 27017
Step 5
(optionally) download RoboMongo and follow normal setup instructions
Step 6
Start RoboMongo and create a new connection on localhost:27017
Your MongoDB is started and connected with RoboMongo (now Robo 3T) - a third party GUI tool
This worked for me
mongod --port 27017 --dbpath C:\MongoDB\data\db
Download from http://www.mongodb.org/downloads
Install .msi file in folder C:\mongodb
Create data, data\db, log directories and mongo.config file under C:\mongodb.
Add the following lines in "mongo.config" file
port=27017
dbpath=C:\mongodb\data\db\
logpath=C:\mongodb\log\mongo.log
Start server :
mongod.exe --config="C:\mongodb\mongo.config"
Connect to localhost MongoDB server via command line
mongo --port 27017
Connect to remote MongoDB server via command line with authentication.
mongo --username abcd --password abc123 --host server_ip_or_dns --port 27017
That's it !!!
Create MongoDB Service in Windows. First Open cmd with administrator
mongod --port 27017 --dbpath "a mongodb storage actual path e.g: d:\mongo_storage\data" --logpath="a log path e.g: d:\mongo_storage\log\log.txt" --install --serviceName "MongoDB"
After that
Start Service
net start MongoDB
Stop Service
net stop MongoDB
Step 1:
First download the .msi i.e is the installation file from
https://www.mongodb.org/downloads#production
Step 2:
Perform the installation using the so downloaded .msi file.Automatically it gets stored in program files.
You could perform a custom installation and change the directory.
After this you should be able to see a Mongodb folder
Step 3:
Create a new folder in this Mongodb folder with name 'data'. Create another new folder in your data directory with the name 'db'.
Step 4:
Open cmd. Go to the directory where your mongodb folder exists and go to a path like C:\MongoDB\Server\3.0\bin.
In the bin folder you should have mongodb.exe
Step 5:
Now use
mongod --port 27017 --dbpath "C:\MongoDB\data\db"
there are 2 ways start mongoDB
Install location ( ex : C:/ )
first of all : copy mongoDB install folder into C:/ location
then changed name to "mongodb" or something what u want. here is ex with "mongodb" name
1 : setup mongoDB is an windows service
1.1 : Make directory name "data" in C:/ ( so we have C:/data ),after that make directory "C:/data/db" <br>
1.2 : run in CMD ( Run as Admin) command -> "echo logpath=C:/mongodb/log/mongo.log > C:/mongodb/mongodb.cfg" <br>
1.3 : run in CMD (Run as Adin) command -> "C:/mongodb/bin/mongod.exe --config C:/mongodb/mongod.cfg --install" <br>
1.4 : run command "net start MongoDB" <br>
2: a small .BAT file to start mongoDB without install
copy and paste to notepad and save file with filetype ".bat"
here is it :
C:\mongodb\bin\mongod.exe –dbpath=C:/mongodb/data/db
PAUSE
if you getting error 1078 or 1087
lets remove all data in C:/data/db and restart mongoDB ( copy old data to new folder and back it up after restart mongoDB )
3 . GUI for mongoDB
i'm using rockmongo
have fun with it
I did below, it works for me in windows.
open cmd prompt in Administrator mode( right click command prompt and click "run as administrator")
then run below command
net start MongoDB
I have followed the below steps...May be it will work for you
Create directory like below
C:\DATA\DB
mongod --port 27017 --dbpath "C:\data\db"
It worked for me....
It is properly written over here
If you download the .msi file then install it and if you download the zip file then extract it.
Set up the MongoDB environment.
MongoDB requires a data directory to store all data. MongoDB’s default data directory path is \data\db. Create this folder using the following commands from a Command Prompt:
md \data\db
You can specify an alternate path for data files using the --dbpath option to mongod.exe, for example:
C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data
If your path includes spaces, enclose the entire path in double quotes, for example:
C:\mongodb\bin\mongod.exe --dbpath "d:\test\mongo db data"
You may also specify the dbpath in a configuration file.
Start MongoDB.
To start MongoDB, run mongod.exe. For example, from the Command Prompt:
C:\mongodb\bin\mongod.exe
Connect to MongoDB.
To connect to MongoDB through the mongo.exe shell, open another Command Prompt.
C:\mongodb\bin\mongo.exe
It is showing admin web console waiting for connections on port 28017.
The above message means that mongodb has started successfully and is listening on port 28017.
You can use the mongo shell(mongo.exe) to connect to the mongoDB and perform db operations.
There are several GUI tools available for MongoDB like MongoVUE, etc.
Installing MongoDB on Windows is a bit tricky compared to other Executable files... Got a good reference after long search I got Installing MongoDB in Windows
After Installing open command prompt and type "mongod", then keep the window minimized and open another command prompt window and type "mongo" and you will find the success message of connecting to the test database.
hope it helps
Download MongoDB Community Server from the link - https://www.mongodb.com/download-center/community
The installation takes some time. Once done, follow these steps to get your server running-
Go to C drive, make a folder named data and inside that create another folder named db.
Now move to directory where monodb server is installed. Go to C:\Program Files\MongoDB\Server(Version)\bin. Copy this file location.
To make it easier to run server in future, press windows key and type environment variables.
You will see an option 'Edit the system environment variables'.
On the lower right corner, you will see a button 'Environment Variables...'. Click that.
Under System variables, double click on path.
Click on new and paste the file location you copied earlier.
Now open cmd, and type mongod.exe (It's a daemon which hosts the server.)
Open another window of cmd and type mongo.exe The connection will be established and you are good to go now.
Thanks for reading. Hope it helps.
Actually windows way to use service, from the official documentation:
Find out where is your executable is installed, path may be like this:
"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe"
Create config file with such content (yaml format), path may be like this:
"C:\Program Files\MongoDB\Server\3.4\mongod.cfg"
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
Execute as admin the next command (run command line as admin):
C:\...\mongod.exe --config C:\...\mongod.cfg --install
Where paths is reduced with dots, see above.
The key --install say to mongo to install itself as windows service.
Now you can start, stop, restart mongo server as usual windows service choose your favorite way from this:
from Control Panel -> Administration -> Services -> MongoDB
by command execution from command line as admin: (net start MongoDB)
Check log file specified in config file if any problems.
This is ALL I needed to init mongo in PowerShell, many replies are IMO too sophisticated.
Install: https://www.mongodb.com/download-center#community
Add C:\Program Files\MongoDB\Server\3.6\bin to environmental
variable "path". Notice: this version will be outdated soon.
Turn on new PowerShell, as it gets environmental variables on a
start, then type mongod
Open another PowerShell window and type mongo - you have access to mongo REPL! If you don't, just repeat 4 again (known bug: https://jira.mongodb.org/browse/SERVER-32473)
Clearly many people have answered upon your query of how to make mongoDb work,
I'd answer the second part: Regarding an appropriate GUI for mongoDB
My suggestion is, go for MongoChef (now Studio 3T)
You can easily install and use it.
You might want want to refer to (from 03:10- to 08:50):
https://www.youtube.com/watch?v=0ws3oIyqieY&index=2&list=PLS1QulWo1RIZtR6bncmSaH8fB81oRl6MP
For a step by step guide to the GUI tool.
an additional thing you can do that is amazing
is that you can add "C:\Program Files\MongoDB\Server\4.0\bin" to your system environment variables , this will allow you to RUN the command "mongod" in any place in your cmd without navigating to the bin directory every time.
-- note the the path to the bin directory can be different in your case --
so to arrange things up
1- make a folder data/db in your c drive "this is the default path mongo will look for the place to store your database files , so you do not have to specify it using '--dbpath' "
2- add "C:\Program Files\MongoDB\Server\4.0\bin" to your system environment variables.
3- open CMD type 'mongod'
4- have fun
-- i saw this on a youtube channel called 'thenewboston' ,
which is also amazing --
For Windows users:
To add onto #CoderSpeed's answer above (CoderSpeed's answer).
Create a batch file (.bat) with the commands you would usually enter on the CLI, e.g.:
cd "C:\Program Files\MongoDB\Server\4.0\bin"
mongod.exe
Windows Script Host’s Run Method allows you run a program or script in invisible mode. Here is a sample Windows script code that launches a batch file named syncfiles.bat invisibly.
Let’s say we have a file named syncfiles.bat in C:\Batch Files directory. Let’s launch it in hidden mode using Windows Scripting.
Copy the following lines to Notepad.
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Batch Files\syncfiles.bat" & Chr(34), 0
Set WshShell = Nothing
Note: Replace the batch file name/path accordingly in the script according to your requirement.
Save the file with .VBS extension, say launch_bat.vbs
Edit the .BAT file name and path accordingly, and save the file.
Double-click to run the launch_bat.vbs file, which in-turn launches the batch file syncfiles.bat invisibly.
Sourced from:
Run .BAT files invisibly
I have installed MongoDB in D:\Installs folder instead of default location.
Open command prompt and change directory into D:\Installs\MongoDB\Server\4.4\bin and run the following command:
mongod.exe --config=mongod.cfg
This should start the MongoDB service.
Now, Open MongoDB Compass and connect as shown below:
Restart your cmd
Type mongo OR mongod in your cmd and press enter.
That's it :)
If from all these ways if your database not working you can try this
First, install Monngodb from the official site
second, go to this path
C:\Program Files\MongoDB\Server\4.4\bin
Third run server using mongod command
You can start Mongo also as a Win Service!
Start
Stop

Run a perl script at startup in Ubuntu

I have a perl script that I need to run once at startup with an argument under my user account.
So when I boot the system up it needs to execute a command like this,
./path/to/script.pl start
Any ideas?
You could use a line in your crontab (crontab -e)
To run a command at startup:
edit /etc/crontab
Add the following line:
#reboot root perl ./path/to/script.pl start
^^^ Runs as root. Change "root" to "BlackCow" to run as BlackCow
Or, you could use upstart (add a .conf file to /etc/init/). Here's a copy and paste from my notes:
Use upstart to run a daemon at reboot/start
e.g. /etc/init/prestocab.conf:
#!upstart
description "node.js server"
author "BlackCow"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
script
export HOME="/root"
exec sudo -u root /usr/local/bin/node /home/prestocab/prestocab.com/www/socket.io/server.js 2>&1 >> /var/log/prestocab.log
end script
To use:
start prestocab
stop prestocab
restart prestocab
#
You might want to use some sort of process monitor to restart the daemon if it crashes
Depends on what init you are using, if your version of Ubuntu is using upstart
you have to configure the appropriate Upstart start scripts, if not
the rc scripts based on your runlevel. Check update-rc.d.
On Ubuntu, the simplest way is to add this line to your /etc/rc.local file (before the exit 0 line, substituting username with your own user name):
su -c "./path/to/script.pl start" username &