How to set a default gateway on CentOS

 Hệ thống  Comments Off on How to set a default gateway on CentOS
Sep 042015
 

A default gateway is a remote host or router that your Linux host forwards traffic to when the destination IP address of outgoing traffic does not match any route in your local routing table. Configuring a default gateway on CentOS is quite straightforward.

If you wish to change a default gateway temporarily at run time, you can use ip command.

First things first. To check what default gateway you are using currently:

$ ip route show

192.168.91.0/24 dev eth0  proto kernel  scope link  src 192.168.91.128
169.254.0.0/16 dev eth0  scope link  metric 1002
default via 192.168.91.2 dev eth0 

According to the local routing table shown above, a default gateway is 192.168.91.2, and traffic is forwarded to the gateway via eth0.

In order to change a default gateway to another IP address:

$ sudo ip route replace default via 192.168.91.10 dev eth0

Obviously, a default gateway’s IP address should come from the subnet associated with the interface connected to the default gateway, in this example, 192.168.91.0/24. Otherwise, the command will fail with the following error.

RTNETLINK answers: No such process

Also, keep in mind that the default route change made by ip command will be lost after rebooting.

In order to set a default gateway permanently on CentOS, you will need to update /etc/sysconfig/network accordingly.

$ sudo vi /etc/sysconfig/network

GATEWAY=192.168.91.10

Again, be aware that the IP addressed specified here should match with the subnet (192.168.91.0/24) associated with a default route interface.

Another option to set a default gateway persistently on CentOS is to edit /etc/sysconfig/network-scripts/ifcfg-<default_interface_name>, and add “GATEWAY=<gateway_ip>” there. If the default interface is “eth0”, you will need to edit /etc/sysconfig/network-scripts/ifcfg-eth0. If you choose to use this method, you need to refer to this post to get familiar with this option.

Whether you edit /etc/sysconfig/network or /etc/sysconfig/network-scripts/ifcfg-ethX, don’t forget to restart networkservice as follows, or reboot your CentOS for the change to take effect.

Install Redis on CentOS 6.5

 Hệ thống  Comments Off on Install Redis on CentOS 6.5
Sep 042015
 

Perform an update to ensure you’ve got the latest of everything in the base package.

yum update

Install wget so you can download a few things.

yum install wget

Allow yum to locate/install redis, per this page here.

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm"

Now, install all the prerequisites

yum install tar make automake gcc gcc-c++ git net-tools libcurl-devel libxml2-devel libffi-devel libxslt-devel tcl redis ImageMagick npm mysql-server mysql-devel nginx libyaml libyaml-devel patch readline-devel libtool bison

Enable and start MySQL

chkconfig --level 3 mysqld on
service mysqld start

Secure your MySQL installation by setting a password. replace ‘new-password’ with your secure password.

mysqladmin -u root password 'new-password'
mysqladmin -u root -h YourHost.YourDomain.com password 'new-password'

Open up the necessary firewall ports

vi /etc/sysconfig/iptables
  copy this line.
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
  and add two more with port 80 & 443 as well
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT

Restart the firewall

service iptables restart

Redis – Environment

 Hệ thống  Comments Off on Redis – Environment
Sep 042015
 

Install Redis on Ubuntu

To install the Redis on Ubuntu, go to terminal and type the following commands:

$sudo apt-get update
$sudo apt-get install redis-server

This will install redis on your machine.
Start Redis

$redis-server

Check if redis is working?

$redis-cli

This will open a redis prompt, as shown below:

redis 127.0.0.1:6379>

In the above prompt 127.0.0.1 is your machine’s IP address and 6379 is port on which redis server is running. Now type the PING command as shown below.

redis 127.0.0.1:6379> ping
PONG

This shows that you have successfully installed redis on your machine.

Install Redis Desktop Manager on Ubuntu

To install redis dessktop manager on ubuntu, just download the package fromhttp://redisdesktop.com/downloadOpen the downloaded package and install it.
Redis desktop manager will give you UI to manage your redis keys and data.

OPTIMIZE APACHE FOR WORDPRESS – HIGH TRAFFIC WEBSITES

 Hệ thống  Comments Off on OPTIMIZE APACHE FOR WORDPRESS – HIGH TRAFFIC WEBSITES
Sep 042015
 

OPTIMIZE APACHE FOR WORDPRESS – HIGH TRAFFIC WEBSITES

This article will help you to tweak your apache server and can aceept high traffic, but let’s talk about the insides and possibilities first. Optimizing apache matters the server hardware so if you checking the solution for Shared Hosting then this article won’t help you, should check my other articles for the low traffic website optimization.

Practically it’s seen that many people finding solution for optimizing wordpress but didn’t check the requirement to do so. If you have traffic more than 1M/Month and VPS has Memory of 2GB with 2 Cores CPU and running WHM then it’s complicated to switch to more traffic, since WHM is not made to accept high traffic due to buffer delay between CPU Cores, Memory, Mysql Database & HTTP Server. Usually stat shows how much traffic your WHM can manage with specific hardware requirement and how much you can tweak to accept more traffic. The stat is based on overall monthly traffic (Including all Hosted sites on your WHM)

Traffic Memory (GB) CPU Cores Tweak Possible Traffic
25K to 50K 2 2 75K
1M to 2M 4 4 3M
3M to 5M 8 8 6M
7M to 10M 12 12 11.5M
12M to 15M 16 16 17M

* Database Size matters, with above figure Database Size not calculated.

* More than 17M – You should better switch to Dedicated

 

To tweak for more traffic find this line in your apache, the following config is default with WHM you can edit the nos according to your CPU Cores & Memory. I assume that you might have 2GB Memory and 2 CPU Cores and the apache httpd.conf may have following values.

You could find the file at the following destination /usr/local/apache/conf/httpd.conf

Note: You might found blank entries between <IfModule prefork.c></IfModule> and you can add following lines between tag and change as per your requirement.

<IfModule prefork.c>

StartServers 3 (Change it as per your CPU Cores)

MinSpareServers 3 (Change it as per your CPU Cores)

MaxSpareServers 10 (Do not change)

ServerLimit 50  (Control the maximum value for MaxClients)

MaxClients 50  (Limit on the number of simultaneous requests)

MaxRequestsPerChild 2000 (Number of requests a child server OR each Domain will handle)

</IfModule>

Also Find Following & Change OR if not mentioned in your httpd.cof then add them

KeepAlive Off

(KeepAlive allows your visitors to use multiple requests over the same TCP connection, this helps improve latency because your visitors can request your webpage, images, and javascripts all over one connection. You can safely reduce this value. If your site has lots of images, java scripts and bigger database then you should keep this on)

 

KeepAliveTimeout 15

(If you leave KeepAlive turned on you should change the default KeepAliveTimeout value. This prevents unused connections from staying open for excessive amounts of time.)

 

MaxKeepAliveRequests 100

(If you leave KeepAlive on you should increase MaxKeepAliveRequests. Setting this higher allows more requests per connection and increases the performance and stability)

Once changes done. Restart the HTTP Server (Recommended Restart Server), to changes take affect.

If you have any queries, questions feel free to ask about Optimize Apache For WordPress – High Traffic Websites

Description

Practically it’s seen that many people finding solution for optimizing wordpress but didn’t check the requirement to do so. If you have traffic more than 1M/Month and VPS has Memory of 2GB with 2 Cores CPU and running WHM then it’s complicated to switch to more traffic, since WHM is not made to accept high traffic due to buffer delay between CPU Cores, Memory, Mysql Database & HTTP

25 Apache Performance Tuning Tips

 Hệ thống  Comments Off on 25 Apache Performance Tuning Tips
Sep 042015
 

We all know and love Apache.  Its great, it allows us to run websites on the Internet with minimal configuration and administration.
However, this same ease of flexibility and lack of tuning, is typically what leads Apache to becoming a memory hog.  Utilizing these easy to understand tips, you can gain a significant performance boost from Apache.

Apache Specifics

1. Remove unused modules – save memory by not loading modules that you do not need, including but not limited to mod_php, mod_ruby, mod_perl, etc.

2. Use mod_disk_cache NOT mod_mem_cache – mod_mem_cache will not share its cache amongst different apache processes, which results in high memory usage with little performance gain since on an active server, mod_mem_cache will rarely serve the same page twice in the same apache process.
3. Configure mod_disk_cache with a flat hierarchy – ensure that you are using CacheDirLength=2 and CacheDirLevels=1 to ensure htcacheclean will not take forever when cleaning up your cache directory.
4. Setup appropriate Expires, Etag, and Cache-Control Headers – to utilize your cache, you must tell it when a file expires, otherwise your client will not experience the caching benefits.
5. Put Cache on separate disk – place your cache on a separate physical disk for fastest access without slowing down other processes.
6. Use Piped Logging instead of direct logging – directly logging to a file has issues when you want to rotate the log file.  It must restart apache to use the next log file.  This will cause significant slowness for your users during the restart.  Particularly if you are using Passenger or some other app loader.
7. Log to a different disk than disk serving pages – put your logs on physically different disks than the files you are serving.
8. Utilize mod_gzip/mod_deflate – gzip your content before sending it off and then the client will ungzip upon receipt, this will minimize the size of file transfers, it generally will help all user experience.
9. Turn HostnameLookups Off – stop doing expensive DNS lookups.  You will rarely ever need them and when you do, you can look them up after the fact.
10. Avoid using hostname in configs – if you have HostnameLookups off, this will prevent you from having to wait for the DNS resolve of the hostnames in your configs, use IP addresses instead.
11. Use Persistent Connections – Set KeepAlive On and then set KeepAliveTimeout and KeepAliveRequests.  KeepAliveTimeout is how long apache will wait for the next request, and KeepAliveRequests is the max number of requests for a client prior to resetting the connection.  This will prevent the client from having to reconnect between each request.
12. Do Not set KeepAliveTimeout too high – if you have more requests than apache children, this setting can starve your pool of available clients.
13. Disable .htaccess – i.e. AllowOverride None  This will prevent apache from having to check for a .htaccess file on each request.
14. Allow symlinks – i.e. Options +FollowSymLinks -SymLinksIfOwnerMatch.  Otherwise, apache will make a separate call on each filename to ensure it is not a symlink.
15. Set ExtendedStatus Off – Although very useful, the ExtendedStatus will produce several system calls for each request to gather statistics.  Better to utilize for a set time period in order to benchmark, then turn back off.
16. Avoid Wildcards in DirectoryIndex – use a specific DirectoryIndex, i.e. index.html orindex.php, not index

OS Specifics

17. Increase Swappiness – particularly on single site hosts this will increase performance.  On linux systems increase /proc/sys/vm/swappiness to at least 60 if not greater.  This will try to load as many files as possible into the memory cache for faster access.

18. Increase Write Buffer Size – increase your write buffer size for tcp/ip buffers.  On linux systems increase /proc/sys/net/core/wmem_max and /proc/sys/net/core/wmem_default. If your pages fit within this buffer, apache will complete a process in one call to the tcp/ip buffer.
19. Increase Max Open Files – if you are handling high loads increase the number of allowed open files.  On linux, increase /proc/sys/fs/file-max and run ulimit -H -n 4096.

Application Specifics

 

20. Setup Frontend proxy for images and stylesheets – allow your main web servers to process the application while images and stylesheets are served from frontend webservers
21. Use mod_passenger for rails – mod_passenger is able to share memory and resources amongst several processes, allowing for faster spawning of new application instances.  It will also monitor these processes and remove them when they are unnecessary.
22. Turn off safe_mode for php – it will utilize about 50-70% of your script time checking against these safe directives.  Instead configure open_base_dir properly and utilize plugins such as mod_itk.
23. Don’t use threaded mpm with mod_php – look at using mod_itk, mod_php tends to segfault with threaded mpm.
24. Flush buffers early for pre-render – it takes a relatively long time to create a web page on the backend, flush your buffer prior to page completion to send a partial page to the client, so it can start rendering.  A good place to do this is right after the HEAD section – so that the browser can start fetching other objects.
25. Use a Cache for frequently accessed data – memcached is a great for frequently used data and sessions.  It will speed up your apache render time as databases are slow.

And one more tip.  Your Apache performance is only as good as your benchmarks measuring it.  If you can’t get numbers or a graph to show that your performance has increased or load decreased, then you don’t know if your tuning has done you any good.  A great way to ensure that you are performing better than before is to use these techniques to hook up apache monitoring to Monitis hosted monitoring.
Do you know more tips? Disagree with some of the tips? Please share your comments bellow.