Friday, November 22, 2013

Apache prefork vs worker mpm

Apache===> multithreaded Vs multiprocess

Apache comes in a few different flavors. The two most common are pre-forked (multi-process) and multi-threaded (worker).

The pre-forked flavor runs several copies of itself and each copy is designed to serve one visitor at a time. The multi-threaded model runs one, sometimes a few, copies of itself but each copy has several threads and each of those threads can serve one visitor at a time.

So, if you had 20 simultaneous requests to your server, the pre-forked version would need 20 copies of itself running to serve them all. In the same situation, the multi-threaded version might have only 1 copy running with 20 internal threads to serve the same requests.
Which one better?

Let’s outline what the pros and cons of each of the two choices are and that will hopefully help determine, based on what you’ll be serving up, which is better for you.

The multi-threaded version often faster and takes less memory. However, any additional modules running inside Apache must fully support a multi-threaded environment. Modules that are not 100% thread-safe can cause Apache to crash or behave strangely.

The pre-forked version takes more memory. However, the pre-forked version also alleviates the need for modules to be fully thread-safe.

One of the most common add-on modules, PHP, has some thread-safely problems. To be fair, the core of PHP is supposed to be fine in a multi-threaded Apache. However, some of the third-party libraries used by PHP are not thread-safe. This has the downside of needing to use the pre-forked version of Apache if you plan to use PHP running from inside Apache as a module (using mod_php, which is by far the most common way of running PHP).

In general, I recommend using the multi-threaded version of Apache only if you are confident that all of the rest of your software stack will support it. If it won’t, or you’re just unsure, then you should run the pre-forked version. Using more memory is definitely better than having things crash or be otherwise unstable.

When running PHP via mod_php, choose pre-forked. When running only static files (html, jpg, etc), choose multi-threaded. If passing on to a backend application server like Mongrel (for Ruby on Rails), the multi-threaded version works fine.

If you’re mixing and matching uses and even one use, in one virtual host, requires the pre-forked version, then pre-forked will need tobe your choice.
Installing each version

On Debian or Ubuntu, the pre-forked version can be installed like this:

sudo apt-get install apache2-mpm-prefork

For the multi-threaded version, install this package instead:

sudo apt-get install apache2-mpm-worker
Optimizing Apache to fit your server

Apache’s default settings for number of processes to run and maximum simultaneous clients to serve are a bit too high. Unless you have one of the biggest Servers, you’ll want to change them. Even for bigger servers it probably makes sense to review these and change them to fit your workload.
Pre-forked version

Again, on Debian and Ubuntu:

sudo nano /etc/apache2/apache2.conf

Find the section labeled “prefork”. There are 5 settings here:

StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0

By default, this tells Apache, when you start, create 5 copies of yourself, keep at least 5 around, don’t keep more than 10 idle servers, you may have up to 150 copies of yourself (1 to serve each client), and each child copy may live indefinitely (no maximum requests per child).

150 copies is too many for a small server. So let’s adjust these a bit:

StartServers 2
MinSpareServers 2
MaxSpareServers 6
MaxClients 20
MaxRequestsPerChild 0

The most important setting here is MaxClients. This is the maximum number of copies of Apache that will run at once. The rest are generally just somewhat proportional to this one number.

These are fairly conservative and have high odds of working for smaller environments. It is possible, if running enough RAM-hungry stuff, that even these are too high. If you’re running a medium-to-large sized server, these may be too small.

Go ahead and save the file and exit.
Multi-threaded version

As noted above, Apache’s default will use a lot of memory. Apache itself will use less here than in the pre-forked version, but it can still easily be too much.

sudo nano /etc/apache2/apache2.conf

Find the section labeled “worker”. There are 6 settings here:

StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0

In this case, Apache reads this as start 2 copies of yourself to begin with, each capable of serving 25 clients, cap the number of clients at 150 (which would be 6 copies of Apache at 25 clients each), and keep spare capacity between 25 and 75 threads, again with no limit on the lifespan of a child copy of Apache.

Let’s adjust these downward a bit:

StartServers 2
MaxClients 30
MinSpareThreads 7
MaxSpareThreads 15
ThreadsPerChild 15
MaxRequestsPerChild 0

MaxClients and ThreadsPerChild are the most important here as they will determine how many copies of Apache are running at once.

These are designed to work, in most cases, with even smaller servers. They are likely too conservative for larger servers in higher-traffic environments.

Save the file and exit.
Finishing up

After the above changes have been made, be sure to do a full restart on Apache:

sudo service apache2 restart
- See more at: http://blog.hemantthorat.com/apache-prefork-vs-worker-mpm/#sthash.KAsNCEBj.dpuf

Linux commands



1. scp from remote host to local host
#scp your_username@remotehost.com:test.txt /local/dir

2. To sort files based on size
#find / type f -size +100000k -exec ls -lh {} \;

3. Add an Existing user to a group
 #gpasswd -a userNamer groupName

and check using #groups userName

4. To take backup of a single database


# mysqldump -u root -p database_name > database_name.sql
 
5. To restore a single database
 
# mysql -u root -p database_name < database_name.sql
 
Make sure you have a database in the name "database_name" before executing this command.
 
6. Mysql command to check database size
 
# SELECT table_schema AS "Database name", SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema; 
 

Friday, November 15, 2013

How to reset/break root and other user's password in Ubuntu 12.04 & 12.10


Do the following procedure to Reset:


1) Restart Machine 

2) HOLD Shift Button ( You will get message “GRUB Loading“)

3) Select the Kernel ( Don’t select Recovery Mode)

4) Press the e key to edit the entry

5) Select the line starting with the word “linux”

6) Append the init=/bin/bash to the end of the linux line.

(I have to append "rw init=/bin/bash" on one 12.04.5 LTS Sony machine and the step 7 was not needed) 7) Now Press F10 to boot with provided option.

Now You need to mount File System ( / ) into Read-Write Mode

8) Type the command
#mount -o remount,rw /

Now execute passwd command to Reset root password.
9) For root User passwd 

Other User passwd

Cloud computing explained

Here I would like to explain  cloud computing simply for newbies.




Cloud computing is the next stage in the Internet's evolution, providing the means through which everything — from computing power to computing infrastructure, applications, business processes to personal collaboration — can be delivered to you as a service wherever and whenever you need.
The “cloud” in cloud computing can be defined as the set of hardware, networks, storage, services, and interfaces that combine to deliver aspects of computing as a service. Cloud services include the delivery of software, infrastructure, and storage over the Internet (either as separate components or a complete platform) based on user demand. (See Cloud Computing Models for the lowdown on the way clouds are used.)
Cloud computing has four essential characteristics: elasticity and the ability to scale up and down, self-service provisioning and automatic deprovisioning, application programming interfaces (APIs), billing and metering of service usage in a pay-as-you-go model. (Cloud Computing Characteristics discusses these elements in detail.) This flexibility is what is attracting individuals and businesses to move to the cloud.
The world of the cloud has lots of participants:
  • The end user who doesn’t have to know anything about the underlying technology.
  • Business management who needs to take responsibility for the governance of data or services living in a cloud. Cloud service providers must provide a predictable and guaranteed service level and security to all their constituents. (Find out what providers have to consider in Cloud Computing Issues.)
  • The cloud service provider who is responsible for IT assets and maintenance.



     



    Cloud computing is offered in different forms: public clouds, private clouds, and hybrid clouds, which combine both public and private. (You can get a sense of the differences among these kinds of clouds in Deploying Public, Private, or Hybrids Clouds.)
    Cloud computing can completely change the way companies use technology to service customers, partners, and suppliers. Some businesses, such as Google and Amazon, already have most of their IT resources in the cloud. They have found that it can eliminate many of the complex constraints from the traditional computing environment, including space, time, power, and cost.


    The goal of cloud computing is to apply traditional supercomputing, or high-performance computing power, normally used by military and research facilities, to perform tens of trillions of computations per second, in consumer-oriented applications such as financial portfolios, to deliver personalized information, to provide data storage or to power large, immersive computer games.
    To do this, cloud computing uses networks of large groups of servers typically running low-cost consumer PC technology with specialized connections to spread data-processing chores across them. This shared IT infrastructure contains large pools of systems that are linked together. Often, virtualization techniques are used to maximize the power of cloud computing.


     See a simple video






    Cloud Computing in the Data Center and for Small Business

    Cloud computing has started to obtain mass appeal in corporate data centers as it enables the data center to operate like the Internet through the process of  enabling computing resources to be accessed and shared as virtual resources in a secure and scalable manner.
    For a small and medium size business (SMB), the benefits of cloud computing is currently driving adoption. In the SMB sector there is often a lack of time and financial resources to purchase, deploy and maintain an infrastructure (e.g. the software, server and storage).
    In cloud computing, small businesses can access these resources and expand or shrink services as business needs change. The common pay-as-you-go subscription model is designed to let SMBs easily add or remove services and you typically will only pay for what you do use.









Thursday, November 14, 2013

How to set gnome-terminal to start bash as a login shell, doesn't read .bashrc



*bash started as an interactive login shell: reads ~/.profile 
*bash started as an interactive non-login shell: reads ~/.bashrc 


Read the bash manual about startup files for more details. Personally, I think that this behaviour is strange and I have not yet found a rationalization for this design decision. Some explanation for the terminology: an interactive shell is a shell with which you can interact, that means you can type commands in it. A non-interactive shell is a shell with which you cannot interact. Non-interactive shells are usually started to run shell scripts. A login shell is a shell which is started when you login to your system, or when you start bash using the --login option. A non-login shell is a shell which is started after the login process, and without the --login option. Configuring gnome-terminal to start bash as a login shell means it will start bash using the --login option. Most shells you see are interactive non-login shells. This is especially true if you are running a graphical shell like gnome, because then gnome is the login shell. Any bash session started inside gnome is a non-login shell (unles started using --login). If you want to see a real interactive login shell then go to a virtual console (using Ctrl+Alt+F1) and then log in using your username and password. That is a real interactive login bash shell. You can go back to the graphical shell using Ctrl+Alt+F7. Usually you want bash to always read ~/.bashrc in an interactive shell. Here is how I recommend to do that: Create a ~/.bash_profile file. If bash is started as a login shell it will first look for ~/.bash_profile before looking for ~/.profile. If bash finds ~/.bash_profile then it will not read ~/.profile. Put the following lines in ~/.bash_profile: [ -f "$HOME/.profile" ] && source "$HOME/.profile" [ -f "$HOME/.bashrc" ] && source "$HOME/.bashrc" Now if bash is started as an interactive login shell it will read the following files: ~/.bash_profile ~/.profile ~/.bashrc and if bash is started as an interactive non-login shell: ~/.bashrc You should put stuff which is bash specific in ~/.bashrc and stuff which is not bash specific in ~/.profile. For example PATH goes in ~/.profile and HISTCONTROL goes in ~/.bashrc. Note that ~/.profile is not bash specific. Other text based shells (for example sh or ksh) and graphical shells (gnome) also read ~/.profile. That is why you should not put bash specific stuff in ~/.profile.