:::: MENU ::::
Browsing posts in: Technology

Ethereum : Running a private node

File: startTestNet.sh
#!/bin/bash

sudo /usr/bin/geth --datadir="" init genesis.json
#sudo /usr/bin/geth --identity "TestMainNode" --datadir "
" --rpc --rpcport "5678" --rpcaddr "0.0.0.0" --rpccorsdomain "*" --port "30303" --nodiscover --ipcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" --rpcapi "db,eth,net,web3,personal" --autodag --networkid 1900 --nat "any"

File: genesis.json

{
"nonce": "0x0000000000000042",
"timestamp": "0x0",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x0",
"gasLimit": "0x8000000",
"difficulty": "0x400",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x3333333333333333333333333333333333333333",
"alloc": {
/*"0x9f04760d4acc712d147f4cb98affe7bb59b72eba" : { "balance": "1000000000000000000000000000" } Cut paste this commented part*/
}
}

Starting the node:
1. Comment the second line of startTestNet.sh (by default it is commented here anyway)
2. cd to this directory root and run ./startTestNet.sh in console (cut and paste the commented accounts inside “alloc” to somewhere. having it there throws error at this point).
2.1 Make sure the data directory path in startTestNet.sh and the data folder (devChain) are same
3. If the genesis block is created successfully, it will say ” successfully wrote genesis block”
3.1 Now comment Line 1 and uncomment Line 2 in startTestNet.sh
3.2 Run: ./startTestNet.sh
3.3 In another terminal, attach to the running geth process using IPC Interprocess communication):
3.4 Run:
sudo geth attach ipc:///devChain/geth.ipc
3.5 Once you are in the geth console, use web3 to create some accounts using :

web3.personal.newAccount()

copy the account number and password in safe place. You will need to unlock the account using the password everytime you want to make a transaction.
4. Now copy all these accounts to the itmo-genesis.json file. The format in which accounts are to be placed is commented. Uncomment and replace the accounts. The balances are all in Wei (1 ETHER = 10^18 Wei)

5. Stop the running node. Comment line 2 and uncomment Line 1 and run ./startTestNet.sh. Now the new accounts are initialized with the balance
6. Comment line 1 in startTestNet.sh. Uncomment line 2
7. run ./startTestNet.sh , the output should be similar like step 3
8. Repeat steps 3.1 and 3.2 . (OPtional: Repeat step 3.4 and run: web3.personal . It will show the new accounts)
9. Now your private node is running. You can make RPC to this node using the ipaddress of this server and the port number defined in startTestNet.sh file. (If your node is inside a LAN then RPC could not be possible. Router should have port forwarding enabled to do so)

10. Note that mining is not started yet. If you create some transactions, then they will stay in pending status. (Run web3 in geth console to see them) To start mining you have to run: web3.miner.start() or you can add “–mine” (without quotes) in the second line of startTestNet.sh . For this, the coin_base and default accounts are to be set. The default account is normally the first account that is created. You can check all those via the geth console by running: web3 . The default account is the one where all the mining rewards are send.

Setup to run private node as a start-up process:

1. startTestNet.sh should be executable
2. Best way to run the node is to run it as a startup process (at least that’s how I am doing it)
3. add the full executable path of startTestNet.sh in /etc/rc.local
3.1 startTestNet.sh should be owned by root to be executable during start-up


Blockchains: A layman’s guide

The Internet, as we know of it is based on request and reply mechanism, where a client (that could be a laptop, a tablet, a mobile phone etc) makes request to a centralized server, the server looks up into its database (if database is needed), processes the request, prepares a reply and sends it to the client again. An example could be, when we type ethereum.org, in our browser and hit enter, the browser sends request to a DNS server,saying “What IP is this name ethereum.org mapped to?” which returns the respective IP address of Ethereum’s server (near to our location). Our client device then uses this IP to send a request to Ethereim’s server to send its webpage to us. Upon receiving the request, Ethereum’s server sends us the appropriate web page. The system, as it is now, looks properly working. But, there is one problem. The DNS server and Ethereum’s server that are centralized servers. If they go down, the entire process can go down. Recently, a DDOS attack was executed on Dyn which is a centralized DNS service provider. AirBnB, Amazon and Netflix are some of the top names that were highly affect by this attack. The problem : a single point of failure.


Rat Race

Welcome, to the rat race,
gonna make you feel like a flat face,
hear me, you gotta hear me screamin,
All this time you have been dreamin,
Wake up, you gotta wake up,
Face the sun, put down the make up

Speak up, why don’t ya speak up,
Are you afraid of the beat up,
See through, you gotta see through,….


NVIDIA drivers and BumbleBee issues with Ubuntu 14.04 (Solved)

I recently got Dell Inspiron 3543 laptop which has I7 processor, 8 GB RAM (replaced the initial 4 GB with 8 GB) and 2 GB dedicated NVIDIA graphics card. It comes with a default Ubuntu installation, (which my retailer replace with Windows 8.1 and again I replaced that with Ubuntu 14.04 LTS ). This is when the  issue started coming!

 

Ubuntu by default uses Nouveau graphics drivers. But for the NVIDIA graphics hardware to be used, NVIDIA native drivers are needed. The following links have pretty useful information regarding this:

http://askubuntu.com/questions/301648/how-to-install-nvidia-driver-in-ubuntu

http://askubuntu.com/questions/464354/update-nvidia-drivers-with-xorg-edgers-ppa

 

(PROBLEM 1)

In my case, first when I tried to select NVIDIA driver from System Settings > Software & Updates > Additional Drivers it reselect the Nouveau driver (default). The changes did not take place.

(SOLUTION 1)

Upon looking it up to various forums, I found out that sometimes the server that is being used to download the drivers causes the issues. Its better to change the download server to “Main Server” from “Ubuntu Softwares” tab in Software & Updates. After this, going to Additional Drivers, the driver menu will be reloaded and caches will be update. Trying to select the NVIDIA driver worked for me after this.

 

(PROBLEM 2)

After rebooting, my login screen did not appear. It was gone. Moment of panic initially for a beginner in Ubuntu, but, I heard the start up sound of Ubuntu. That meant that, the system booted normally but there was issue with the login screen. (On a side note, my desktop environment was Unity during all this).

 

(SOLUTION 2)

From http://askubuntu.com/questions/41681/blank-screen-after-installing-nvidia-restricted-driver link , I came to know that the culprit was NVIDIA’s driver. It seems that Linux does not entertain multiple drivers for the same hardware. To solve this I logged in using Ubuntu’s terminal login (Ctrl + Alt + (Fn key if in laptop) +F2) and then uninstalled NVIDIA’s driver and reinstalled Nouveau Driver (default) and reconfigured Xserver following the instructions in the link. Upon rebooting, my screen was back.

 

(PROBLEM 3)

Then an old geeky pal of mine, Kaushal Niraula, suggested me to use BumbleBee. It enables graphics  fallback system in Linux. (In simple terms,here Fallback means, when you need NVIDIA graphics for example, for playing games or 3D visualization etc, then, automatically NVIDIA graphics is used. The performance comes with a trade-off though. It consumes more energy.So, using NVIDIA graphics for applications not demanding more graphics will not be energy-economic. In these cases, by the virtue of fallback technology, the graphics is automatically switched to Intel’s default, which is pretty smart in terms of power management as well.)   I followed the instructions provided in the link in BumbleBee’s website (Ubuntu Wiki). But upon hitting the command:

optirun firefox

I got this error message:

**[ 4703.996785] [ERROR]Cannot access secondary GPU, secondary X is not active.**
**[ 4703.996910] [ERROR]Aborting because fallback start is disabled.**

(SOLUTION 3)

I finally found out that, the ubuntu wiki link provided above was already expired! So,again after surfing around a bit, I found the correct instructions to install BumbleBee here. I followed every step in the first comment and then rebooted my system.Finally I could see the icon og BumbleBee in the top right corner of screen.Click on the icon and you can see “Configure Apps” option. There, you can set the apps that you want to use NVIDIA with.

I have compiled all the issues t in hat I have faced during the process. Hope it will help to someone facing the same issue with NVIDIA.


Apache 2.4.7 and its configuration in Ubuntu 14.04

What is Apache Server?

Apache is a free, open-source web server software developed by a group of 20 programmers, famously know as The Apache Group. It is the most popular web server software used today. Initiation of works on Apache dates back to 1995. Apache helps to deliver content over the internet to the requesting clients. It became the first web server to server more than a 100 million websites in 2009 and surpassed its own record by serving 54.2% of all the websites.

Apache and PHP

Consider an organization. There are 3 parts- The Customers, The Management and The workers or employees. Now when it comes to web, these roles are played respectively by Browser, Apache and PHP. Like a customer who requests for something from the organization, the browser initiates a content request. The management then, receives the request (note the ‘receives’ word) and passes it to the workers. The workers do all the work, process the request, produce the results and then make it ready so that the management can deliver it to the requesting customer. In the same fashion, Apache receives request from the clients / browsers & calls the PHP interpreter which interprets the request, looks for the appropriate requests, generates the html and then Apache sends it back to the customer browser. PHP is one of the most popular language for server side scripting due to its simplicity, open-source nature and “not too steep” learning curve. PHP Apache and MySQL is the one of the most popular web environment since some years.

Configuring Apache (writer is using Ubuntu 14.04):

Apache, probably is the most flexible and easily configurable web sever software. A developer can configure it as per their needs without much hassles.Below I will explain how an Apache server can be configured to create virtual sites.

What are Virtual Sites?

By default, Apache runs based on a set of rules defined in its config files. For example, most of us (specially windows users using wamp or xampp) use http://localhost/<project name> to access projects that are in our local directory, once the Apache server starts running.

By creating virtual sites, you define your set of rules like the ServerName (localhost in above examples), server ip address, port number, allowing or disallowing redirection, email of server administrator and also the directory where Apache should look for your projects.

The Process:

By default, Apache default site configuration resides at:

/etc/apache2/sites-available/000-default.conf

First of all, I will write down the steps in plain language, so that it becomes easy to comprehend and keep track of what actually is happening. Actually, these are the broken down steps for the sake of simplicity. So, here we go:

1. Copy the default configuration file and rename the copy to <name-you-prefer>.conf

2. Edit the ServerName,ServerAlias,ServerAdmin

3. Define the DocumentRoot  where you want Apache to look for your projects.

4. Define access rules to your virtual site.

5. Define the error logs and access logs (if only you want to change the default error log location)

STEP 1:

We do it in the Linux way. In your terminal, type:

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/projects.conf

A copy of the configuration file is created with the name projects.conf . This actually eases our work because we just have to edit things instead of writing each of them.

STEP 2:

a. ServerName: It is the name that you enter in the url.for example: localhost is a server name. I would prefer using, “projects”. So that I can put all my projects in this new site and it kinda looks pretty cool (Well, for me at-least 😀 ).

So, in the projects.conf file, put ServerName projects

b. ServerAlias: It is an alias / alternative name of server name. This means that if I enter alias name instead of server name the effect should be the same as I entered ServerName. That’s why its called ServerAlias, since it is a alias of our server name.

for our example, we will use ServerAlias Projects

c. ServerAdmin: This is the email address that will receive an email if something goes wrong or some issue arise. ServerAdmin shall contain your email address.

ServerAdmin admin@manish-lamichhane.com.np

STEP 3:

DocumentRoot defines the directory where your project resides. For instance its in a folder called projects inside www. Then we have to define it as:

DocumentRoot /var/www/projects/

Note: Make sure you have a folder with projects name that has write permission and your /var/www/ have read permission.

(If you have not done that yet, read further to closing parenthesis.(Use you LISP compiler between your two ears, if you know what I mean ):

1. sudo mkdir -p /var/www/projects/test
(-p creates parents directory if they do not exist)

2. sudo chmod -R 755 /var/www/
( check the properties by looking at permissions of these folders by right clicking them. They shall be accessible to all). For security reasons, they should be made readable only and not writeable.

3. sudo chown -R $USER:$USER /var/www/projects

(-R means recursive, so -R after chown means recursively own all the folders and sub folders inside projects folder)

That’s it. We have a project folder that has write permission and /var/www/ allows read access.

)

Step 4:

Now comes the <Directory>. This will be meaningful to you if you understand the use of .htaccess file. The .htaccess file apply rules to a particular directory. Apache gives precedes to the .htaccess files first. That means the changes or modifications in the .htaccess files override the behaviour of the particular directory that they reside in. If no .htaccess file is present then the rules in this container (i.e. <Directive>) are applied. Rules like removing index.php from url are defined in .htaccess files, and if you want to apply changes through all projects inside the projects/ directory, you have to make changes in this container.

for now keep it as:

<Directory /var/www/projects/ >
    
    Require all granted

</Directory>

This means that projects/ can be accessed from all the requesting clients.However, You can restrict access to this site as well.
for example:

Require not host rougecontent.com

prohibits rougecontent.com from accessing this directory.

Detailed information regarding this section can be found here.

STEP 5: Defining the location of error and access logs.

You can use it as it is if you don’t want a separate configuration file for your site. Or you can create an error and access log inside your projects directory (or anywhere you want) and then give the location in the ErrorLog and Custom log. I have, for this example, created /var/www/projects/logs/error.log and /var/www/projects/logs/access.log

So, summing things up, after following all the above steps, your projects.conf file should look like this:

<VirtualHost *:80>

ServerAdmin webmaster@localhost
ServerName  projects
ServerAlias Projects
DocumentRoot /var/www/projects/public_html/

<Directory /var/www/projects/public_html/ >

Require all granted

</Directory>

ErrorLog /var/www/projects/logs/error.log
CustomLog /var/www/projects/logs/access.log combined

</VirtualHost>

The number 80 means that the virtual host listens to all the requests from port 80.

Now two simple things are remaining.

First: Editing the host file to define projects

gksudo gedit /etc/hosts/

Then, add:

127.0.0.1 projects

The ip that you are defining is called a “Loop-back IP” which tells Apache to look for the host in this machine or in other words, redirects the request to the machine itself whenever you enter http://projects in your browser.

Second: Enable this new site. Type the below command in terminal and then restart apache2 server.

sudo a2ensite projects.conf ( a2 means apache2 ensite means enable site)

sudo service apache2 restart

Note: If there are some errors in your configuration file, they will be shown in the terminal when you attempt to restart the Apache server.Also, by documentation of Apache, you need not disable your default configuration file (000-default.conf) because the virtual site (project.conf) will always take precedence over default site. However, there are cases when the virtual site works only when the default site is disabled. Disabling of a site can be done using the following command:

sudo a2dissite 000-default.conf (or any configuration that you wan t to disable)

As mentioned above, a2 means apache2 dissite means disable site

You may now create any html or php file inside projects/ directory and then access using http://projects/<filename.php>

Hope this article is helpful, specially to the beginners.


Lighting the LAMP in Ubuntu 14.04

If you are like me, who have recently switched from windows to Linux to enjoy more freedom, and experienced that freedom ain’t that cheap, given the wild goose chase that Linux welcomes with,for beginners, then you’re home. Relax and have a seat. Below I will share one of the easiest ways to light the LAMP in Ubuntu 14.04.

The easiest way to install LAMP stack in Ubuntu is by using tasksel.

Tasksel is a multiple related package installer for Ubuntu.

The procedure is pretty simple. First let’s break down the steps:

1. Update your application index by running update command
2. Install tasksel
3. Install LAMP Server using tasksel

That’s right folks! Only three simple commands and then you are good to go.

So, now lets have a look at the associated commands:

1. Running the program update command:

sudo apt-get update

First of all, what we need to understand is, what this command does. It just looks for any necessary updates, dependencies etc of your currently installed programs.

But, if you’ve recently ran this command then, you need not run it again. (Though it would do no ham if you do it).

2. Install tasksel:
sudo apt-get install tasksel

Simple. This command installs tasksel, which will help you install LAMP.

3. Install LAMP Stack:

sudo tasksel install lamp-server

This command installs the lamp stack. During the installation you will be asked to set the root password for mysql. Just that small attention seeking act and tadaaa, you have successfully installed LAMP.

Just a reminder, after tasksel installs, it shows an you options screen,where you can find lamp-server also listed. I tried installing LAMP from there, but it did not work. So I tried the above command and got the results without any hair pulling sessions caused due to shattering of expectations 🙂 .

It would also be good to install phpmyadmin right away, would it not? So,lets again get back to good old terminal and type in:

sudo apt-get install phpmyadmin

Now, the beautiful spontaneity of Linux takes over again and you can see it being installed. In between (again), you will be shown an option screen where you have to select Apache server,(since you are installing phpmyadmin to run with Apache server). After selecting Apache server, a again for the last time, you will be asked to set the password for phpmyadmin, which you have to reply as yes, then set the password,confirm it and then you’re done. PHPMYADMIN and LAMP both installed with a few painless commands.

But again, this will not run phpmyadmin when you hit
http://localhost/phpmyadmin

why? Because, poor Apache server doesnot know about phpmyadmin! So, we will tell Mr.Apache where to find our new guy.

Copy the following line and paste it in your apache2.conf file in /etc/apache2/apache2.conf

Include /etc/phpmyadmin/apache.conf

Then restart the Apache server by:

sudo service apache2 restart

or

sudo service apache2 reload

Now, you can access localhost/phpmyadmin

Login with the password that you created above during installation of phpmyadmin and …..enjoy, play around or whatever you want to do with it 😀 !

You can use the default Apache site to start with. Apart from that,Apache provides high flexibility to developers to configure virtual sites as per the needs. I will write about configuring new virtual sites in my next article.

This is my first article and so there might be some faults in presentation and a bit this and that, to improve which, I will be looking for your feedback. Be in touch!!