Wednesday, November 19, 2014

MONGODB BASIC CONFIGURATION

1. Mongodb without authentication


Mongodb folder structure

 C:\\mongodb\\bin
 C:\\mongodb\\data
Start mongoDB without authentication

C:\mongodb\bin\mongod.exe --dbpath "C:\mongodb\data"

or

C:\mongodb\bin\mongod.exe --dbpath="C:\mongodb\data"


Default port is 27017

2. Enable authentication



First we need to start mongoDB without authentication

C:\mongodb\bin\mongod.exe --dbpath "C:\mongodb\data"

After that run following commands :

1. Run  mongo client with : mongo.exe
2. Use data base with : use admin

3. Add user and role : db.createUser({"user":"root","pwd":"123456","roles":[{"role":"readWriteAnyDatabase","db":"admin"},{"role":"userAdminAnyDatabase","db":"admin"},{"role":"dbAdminAnyDatabase","db":"admin"}]})

The object of root user(for easy to read)


db.createUser({
 "user":"root",
 "pwd":"123456",
 "roles":[
  {
   "role":"readWriteAnyDatabase",
   "db":"admin"
  },
  {
   "role":"userAdminAnyDatabase",
   "db":"admin"
  },
  {
   "role":"dbAdminAnyDatabase",
   "db":"admin"
  }
 ]
});


And start with authentication mode:

 #mongod.exe --dbpath="C:\mongodb\data" --auth



3. Creating window service with configuration file


mongo.cfg placed in c:\mongodb\etc\

systemLog:
   destination: file
   path: c:\\mongodb\\etc\\mongodb.log
   logAppend: true
storage:
   dbPath: c:\\mongodb\\data
   journal: 
      enabled: true
processManagement: 
   windowsService: 
      serviceName: t2i-mongodb-server
      displayName: T2i mongoDb server display name.
      description: The service for MongoDatabase
security: 
   authorization: enabled
net:
   bindIp: 127.0.0.1
   port: 27017


Command to start as service

"C:\mongodb\bin\mongod.exe" --config "C:\mongodb\etc\mongo.cfg" --install

Thursday, November 13, 2014

LINUX BASIC COMMON COMMANDS

Filter result:


grep

ex: filter all processes and ports of java

ps -e | grep java
netstat -tunap | grep java

Process and infomation :


Information about process
$ls -l /proc/$PID/exe
OR
$ps -p PID -o comm=
OR
$cat /proc/PID/cmdline

Kill process
sudo kill -9 PID

User and Group:


Login
#su - {user-name}

Login as root
#su -

check username
#whoami

logout
#logout

Extract & Compress file:


Extract
#tar -zxvf {file.tar.gz}
#tar -xf {file.tar.gz} -C /target/directory
#tar -xzf backup.tar.gz -C /target/directory
#unzip file.zip -d destination_folder

Download
#wget http://ftp.gnu.org/gnu/wget/wget-1.5.3.tar.gz  -P /target/directory

Restating the network service:


To restart the network service under RHEL / CentOS based systems, enter:
service network restart
OR
/etc/init.d/network restart

Check linux kernel version number :


Open a shell prompt (or a terminal) and type the following command to see your current Linux kernel version:

uname -r

Or type the following command
uname -mrs

To print all information, enter

uname -a

Type the following command to see Linux version info

cat /proc/version

Find Distribution Version :


Type the following command

cat /etc/*release

OR
lsb_release -a

Port & Firewall :


Port and process command
netstat -tunap

If you want to open a single port

open iptables file
vi /etc/sysconfig/iptables

Add below line to open port.

-A INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT

For multiple, you can use the following instead (or repeat the above line multiple times):

-A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 22,80,143 -j ACCEPT

service iptables save

Disable / Turn off Linux Firewall (Red hat/CentOS/Fedora Core)

Type the following two commands (you must login as the root user)

/etc/init.d/iptables save

/etc/init.d/iptables stop

Turn off firewall on boot

chkconfig iptables off

Enable / Turn on Linux Firewall (Red hat/CentOS/Fedora Core)

Type the following command to turn on iptables firewall

/etc/init.d/iptables start 

Turn on firewall on boot

chkconfig iptables on 

Linux / Unix - Checking Free Disk Space:


df command examples - to check free disk space

Type df -h or df -k to list free disk space

df -h

OR
df -k

Find Files and Folders in Linux :


find / -name "java" 

/: meaning is the root folder. hold systems
-name "java": all files have name is java.

Thursday, November 6, 2014

NODEJS - RUNNING A NODEJS SERVER AS A SERVICE ON LINUX


1. Download the project for testing:


The user logged in was: root

Download the demo server here

[root@homepc opt]# wget https://github.com/vanduc1102/nodejs-example/archive/daemon-bauth.tar.gz

[root@homepc opt]# tar -zxvf daemon-bauth.tar.gz

[root@homepc opt]# cd nodejs-example-daemon-bauth/

[root@homepc nodejs-example-daemon-bauth]# npm install

[root@hompec nodejs-example-daemon-bauth]# node index.js


You can open browser and test the application at localhost:3000

We had nodejs-example folder placed in /opt/nodejs-example-daemon-bauth

2. Create a service file in systemd:


Create file below in folder : /etc/systemd/system/
nodejs-example-service.service

[Unit]
Description=The nodejs-example server start

[Service]
WorkingDirectory=/opt/nodejs-example-daemon-bauth
ExecStart=/usr/bin/node index.js
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=nodejs-example-nodejs-server
User=root
Group=root

[Install]
WantedBy=multi-user.target

Load the service at first time:
#systemctl enable nodejs-example-service

Start service:
#systemctl start nodejs-example-service

View status of the service:
#systemctl status nodejs-example-service

Stop the service:
#systemctl stop nodejs-example-service

3. Testing the service:


[root@homepc system]# systemctl start  nodejs-example-service.service
[root@homepc system]# systemctl status nodejs-example-service.service
nodejs-example-service.service - The nodejs-example server start
Loaded: loaded (/etc/systemd/system/nodejs-example-service.service; enabled)
Active: active (running) since jeu 2014-11-06 19:18:02 ICT; 8s ago
Main PID: 3967 (node)
CGroup: name=systemd:/system/nodejs-example-service.service
└─3967 /usr/bin/node index.js
[root@homepc system]# ps -e | grep "node"
3967 ? 00:00:00 node
[root@homepc system]# kill 3967
[root@homepc system]# ps -e | grep "node"
4038 ? 00:00:00 node
[root@homepc system]# systemctl status nodejs-example-service.service
nodejs-example-service.service - The nodejs-example server start
Loaded: loaded (/etc/systemd/system/nodejs-example-service.service; enabled)
Active: active (running) since jeu 2014-11-06 19:18:02 ICT; 8s ago
Main PID: 4038 (node)
CGroup: name=systemd:/system/nodejs-example-service.service
└─4038 /usr/bin/node index.js
[root@homepc system]#

As you can see, After we kill the process, It will automatically create new one.