الجمعة، 17 سبتمبر 2010

تحسين اداء رام السيرفر How to optimize ram of server Flush cache on the ram using linux system.

Often servers always need more RAM.
For those who have a server lowcost certainly will have little ram.
Cache RAM is certainly very high performance, part of the RAM that the operating system uses to temporarily store a copy of the data just read from storage devices. In this way, if the same data are again, the processor can obtain it more quickly.

You can see in Megabytes usage of the RAM by the command:
free -m


Too bad if you use the whole RAM just for the cache no longer room for other applications.

This command will prevent you reboot the server to clear the ram.
echo 3 > /proc/sys/vm/drop_caches


This command, if put in cronjob every 24 hours for example, can help the servers that have limited RAM and need to use it to run applications that generate operations always different and require no cache.

How to optimize ram of server Flush cache on the ram using linux system.

Often servers always need more RAM.
For those who have a server lowcost certainly will have little ram.
Cache RAM is certainly very high performance, part of the RAM that the operating system uses to temporarily store a copy of the data just read from storage devices. In this way, if the same data are again, the processor can obtain it more quickly.

You can see in Megabytes usage of the RAM by the command:
free -m


Too bad if you use the whole RAM just for the cache no longer room for other applications.

This command will prevent you reboot the server to clear the ram.
echo 3 > /proc/sys/vm/drop_caches


This command, if put in cronjob every 24 hours for example, can help the servers that have limited RAM and need to use it to run applications that generate operations always different and require no cache.

How to Testing the Hard Disk from SSH Using S.M.A.R.T information and testing read/write speed

Not everyone is familiar with the Linux shell.
Although many people use it in their server for economic reasons.

Often have the feeling that the hard disk is damaged.
To test the status of the disk in SSH, here are the various commands.

SMART Disk Monitoring Daemon.

smartd is a the software that use the SMART information to analysis, report and monitorate the disk.

That software can be installed on Linux, Windows, Solaris and *BSD.
Much distro come with smartd alrady installed on it.

To use it;
smartctl -i /dev/sda

With the argument -i we see the information of the version of the smartd, if the disk are compatible, the model of the disk.. (on that case the disk is /dev/sda)

My OutPut:
root@ethel [~]# smartctl -i /dev/hda
smartctl version 5.38 [x86_64-redhat-linux-gnu] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/

Smartctl open device: /dev/hda failed: No such file or directory
root@ethel [~]# smartctl -i /dev/sda
smartctl version 5.38 [x86_64-redhat-linux-gnu] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/

=== START OF INFORMATION SECTION ===
Device Model:     WDC WD7500AADS-00M2B0
Serial Number:    WD-WCAV51911761
Firmware Version: 01.00A01
User Capacity:    750,156,374,016 bytes
Device is:        Not in smartctl database [for details use: -P showall]
ATA Version is:   8
ATA Standard is:  Exact ATA specification draft version not indicated
Local Time is:    Tue Dec  8 03:41:36 2009 CET
SMART support is: Available - device has SMART capability.
SMART support is: Enabled


To see if have any errors, run:
smartctl -l error /dev/sda


To test the disk, you can run 2 test, short and long.

the short take only 2min
smartctl -t short /dev/sda


The long test can take also more than 180min..
smartctl -t long /dev/sda


For see health and test result, run that command:
smartctl -Hc /dev/sda


My OutPut:
root@ethel [~]# smartctl -Hc /dev/sda
smartctl version 5.38 [x86_64-redhat-linux-gnu] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

General SMART Values:
Offline data collection status:  (0x85) Offline data collection activity
                                        was aborted by an interrupting command from host.
                                        Auto Offline Data Collection: Enabled.
Self-test execution status:      (   0) The previous self-test routine completed
                                        without error or no self-test has ever
                                        been run.
Total time to complete Offline
data collection:                 (15600) seconds.
Offline data collection
capabilities:                    (0x7b) SMART execute Offline immediate.
                                        Auto Offline data collection on/off support.
                                        Suspend Offline collection upon new
                                        command.
                                        Offline surface scan supported.
                                        Self-test supported.
                                        Conveyance Self-test supported.
                                        Selective Self-test supported.
SMART capabilities:            (0x0003) Saves SMART data before entering
                                        power-saving mode.
                                        Supports SMART auto save timer.
Error logging capability:        (0x01) Error logging supported.
                                        General Purpose Logging supported.
Short self-test routine
recommended polling time:        (   2) minutes.
Extended self-test routine
recommended polling time:        ( 181) minutes.
Conveyance self-test routine
recommended polling time:        (   5) minutes.
SCT capabilities:              (0x303f) SCT Status supported.
                                        SCT Feature Control supported.
                                        SCT Data Table supported.


For test write and read speed, run that command:
root@ethel [/home]# dd if=/dev/zero of=fakedisk bs=10k count=1000
1000+0 records in
1000+0 records out
10240000 bytes (10 MB) copied, 0.0188848 seconds, 542 MB/s


And for recive any alert of your disk, that command send you an email when there are any worng test..
/dev/sdb -m you@rv89.eu


For the moment, that's all ;)

How to Limit Bandwidth Speed on cPanel Domain Limit Bandwidth Speed of domain on WHM/cPanel Server

Hello,

I'm writing nothing new.. but i think not all know that.

When we have same user that leech or use full connection speed all the same time, they take slow other site cause the less disponibility of the connection speed used all by they domain.

Can limit the connection speed of each user!
With Bandwidth Module (Mod_bandwidth)

Connecting by shell on ssh, can use that module using the fallow sintax:

/scripts/setbwlimit --domain=rv89.eu --limit=10240000


That command have limit the domain rv89.eu to using max speed 1MB/s (10240000 byte)

*Be sure you have arlady installed Mod Bandwidth on (Main >> Software >> EasyApache (Apache Update))

Recover MySQL root Password

You can recover MySQL database server password with following five easy steps.

Step # 1: Stop the MySQL server process.
Step # 2: Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password.
Step # 3: Connect to mysql server as the root user.
Step # 4: Setup new mysql root account password i.e. reset mysql password.
Step # 5: Exit and restart the MySQL server.
Here are commands you need to type for each step (login as the root user):

Step # 1 : Stop mysql service

# /etc/init.d/mysql stopOutput:
Stopping MySQL database server: mysqld.

Step # 2: Start to MySQL server w/o password:

# mysqld_safe --skip-grant-tables &Output:
[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started

Step # 3: Connect to mysql server using mysql client:

# mysql -u rootOutput:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

Step # 4: Setup new MySQL root user password

mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

Step # 5: Stop MySQL Server:

# /etc/init.d/mysql stopOutput:
Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended

[1]+  Done                    mysqld_safe --skip-grant-tables

Step # 6: Start MySQL server and test it

# /etc/init.d/mysql start
# mysql -u root -p

Setup Nginx as HTTP Deamon with vhosts

Posted Image


nginx [engine x] is a HTTP server and mail proxy server written by me (Igor Sysoev).

Nginx vs Apache2

In this Setup, Nginx is used for replace apache.

Installing by Portsnap
cd /usr/ports/www/nginx-devel/
make install clean


Select this Options
HTTP_MODULE 
HTTP_CACHE_MODULE
HTTP_REWRITE_MODULE
HTTP_SSL_MODULE
HTTP_STATUS_MODULE


Create vhost directory:
mkdir /usr/local/etc/nginx/vhosts


Our config files have been setup to help keep our server secure and prevent people from "snooping" around the server to find exploits and holes. This is just part of a multilayer security setup and will not prevent people from hacking your server. These confg files are rather self explanatory feel free to change as needed.

/usr/local/etc/nginx.conf
user     www www;
worker_processes   8;
pid     /var/run/nginx.pid;
events {
 worker_connections  8192;
}
http {
 include    mime.types;
 default_type   application/octet-stream;
 ## Log Cache
 open_log_file_cache max=1000 inactive=20s min_uses=2 valid=1m;
 ## Log Format
 log_format   main '$remote_addr - $remote_user [$time_local] $request '
      '"$status" $body_bytes_sent "$http_referer" '
      '"$http_user_agent" "$http_x_forwarded_for"';
 ## Logs
 #access_log /var/log/nginx-access.log main;
 #access_log off;
 error_log  /var/log/nginx-error.log debug gzip buffer=32k;
 ## Compression
 gzip   on;
 gzip_min_length 1100;
 gzip_buffers  16 8k;
 gzip_http_version 1.0;
 gzip_comp_level 1;
 gzip_proxied  any;
 gzip_types  text/plain text/css text/javascript text/xml text/php
    application/x-javascript application/xml application/xml+rss;
 ## Size Limits
 client_body_buffer_size   8k;
 client_header_buffer_size 256k;
 client_max_body_size      10m;
 large_client_header_buffers 256 256k;
 ## Timeouts
 client_body_timeout   5;
 client_header_timeout 5;
 keepalive_timeout     75 20;
 send_timeout          5;
 ## General Options
 ignore_invalid_headers   on;
 limit_zone gulag $binary_remote_addr 1m;
 recursive_error_pages    on;
 sendfile                 on;
 server_name_in_redirect off;
 server_tokens           off;
 ## TCP options  
 tcp_nodelay on;
 tcp_nopush  on;
 ## Run all config files in our vhost directory
 include /usr/local/etc/nginx/vhosts/*.conf;
}


Now create a vHost in /usr/local/etc/nginx/vhosts directory.
You must replace the domain rv89.eu to your domain.
server {
 listen  *:80;
 server_name rv89.eu;
 root          /usr/local/www/rv89.eu;
 #access_log /var/log/rv89.eu.access.log main;
 error_log /var/log/rv89.eu.error.log debug;
 #error_page 404 = /error/404.html;
 #error_page 502 503 504 = /error/50x_error.html;
 #location    /error/50x_error.html {
 #    internal;
 #}
 ## directory and index file
 location / {
 root   /usr/local/www/rv89.eu;
 autoindex off;
 index   index.php index.html index.htm;
 }
 ## php-fpm config
 location ~ \.php$ {
  fastcgi_index index.php;
  fastcgi_pass 127.0.0.1:9000;
  include    fastcgi_params;
  fastcgi_param CONTENT_TYPE $content_type;
  fastcgi_param CONTENT_LENGTH $content_length;
  fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  fastcgi_param SCRIPT_FILENAME /usr/local/www/rv89.eu$fastcgi_script_name;
  fastcgi_param REQUEST_URI $request_uri;
  fastcgi_param DOCUMENT_URI $document_uri;
  fastcgi_intercept_errors on;
 }
 ## Cache of images
 location ~* \.(jpg|jpeg|gif|css|png|js|ico)$ {
  root          /usr/local/www/rv89.eu;
  access_log off;
  expires 30d;
  break;
 }
 ## Serve an empty 1x1 gif _OR_ an error 204 (No Content) for favicon.ico
 location = /favicon.ico {
 #empty_gif;
  return 204;
 }
 ## If the file exists as a static file serve it directly without running all the other rewite tests on it
 if (-f $request_filename) { 
  break; 
 }
 ## Only allow GET and HEAD request methods
      if ($request_method !~ ^(GET|HEAD)$ ) {
         return 444;
      }
}


Now edit the file /etc/rc.conf

And add:
nginx_enable="YES"


Run
rehash


Start The WebServer Nginx
/usr/local/etc/rc.d/nginx start


You have install your server. Next guide will be dedicate to installing PHP on Nginx

How to install application with portsnap Installing an application on FreeBSD using Portsnap

Posted Image
Hello All,

This time we learn an easey mode to install same applications on FreeBSD.
BSD use a Portsnap archive, like apt-get for debian/ubuntu, yum for fedore/centos, emerge for gentoo..

Well, frist need to update the archive
portsnap fetch


And Extract it
portsnap extract


Now we have the full archive of applications rady to download and install on /usr/ports/.

To install an application, like nano, just find the directory where are the installation files.
whereis nano


And we find: /usr/ports/editors/nano

Now just go in this directory and install the application.
cd /usr/ports/editors/nano

make install clean


Now the application are installed. After the installation for take effect run:
rehash