Posts

How to implement Log File Rotation in Linux Servers

NB: We are using CentOS Servers Switch to root user cd /etc/logrotate.d/  (by default we will be having this directory in our server) create a new file project-logs   vi project-logs Add the following piece of code to this file             /folder-path-of-your-log/*.log {                size=10M                missingok                rotate 20                compress                delaycompress                notifempty                copytruncate               daily           }       5.   logrotate -f /etc/logrotate.d/        This will create new log files once the log file size reaches 10MB. NOTE:    When you first setup a daily logrotate.d entry, it will not rotate the first day . Next day onwards you can see the changes.

How to SSH to remote server without entering password each time.

ssh -copy-id  example_user@www.example.com and give password once. Then you will be able to ssh without password next time onwards. Make sure you have a ssh key generated in your local machine. This works for Linux only (not Mac, Windows etc.) For Mac you need to first setup ssh-copy-id command & then copy the ssh key sudo curl https://raw.githubusercontent.com/beautifulcode/ssh-copy-id-for-OSX/master/ssh-copy-id.sh -o /usr/local/bin/ssh-copy-id sudo chmod +x /usr/local/bin/ssh-copy-id ssh-copy-id -i /path/id_rsa.pub example_user@www.example.com   Now you have your ssh-key copied to your server. You can now try your normal ssh login command without entering password

Server Fine Tuning Scripts

Provides a instant view of running resource usage https://community.rackspace. com/products/f/25/t/647 Apache Tuning scripts https://github.com/ gusmaskowitz/apachetuner (bash script) https://github.com/ gusmaskowitz/apachebuddy.pl (perl script that supercedes apachetuner) MySQL Tuning script https://github.com/major/ MySQLTuner-perl Resource usage logging https://github.com/rackerlabs/ recap

Capistrano Deployment in Rails 3 (via the rvm-capistrano gem)

Go to your project path. Add   gem 'rvm-capistrano' to your Gemfile Run bundle install for installing the gem Run the command  capify . This will create [add] writing './Capfile' [add] writing './config/deploy.rb' [done] capified! Modify the setting in your ./config/deploy.rb, sample settings is provided below  require "rvm/capistrano" set :application, "My Test App" # Your application name set :domain, "testapp.com" # Domain name for your app set :repository, "git@github.com:test/test.git" # The code repository url set :user, "test_user" # The ssh user that has access to your server default_run_options[:pty] = true set :use_sudo, false set :scm, :git set :deploy_via, :remote_cache set :deploy_to, "/home/test/test_project_production" # Server path to which the code is to be deployed role :web, domain # Your HTTP

How to fetch the no: of weekly inserted records in MySQL

Image
SELECT   COUNT(*) AS reports_in_week,   DATE_ADD(created_at, INTERVAL(1-DAYOFWEEK(created_at)) DAY) as start_day,   DATE_ADD(created_at, INTERVAL(7-DAYOFWEEK(created_at)) DAY) as end_day FROM   your_table_name GROUP BY   YEAR(created_at) + .01 * WEEK(created_at) The desired output will be.

How to add Startup Script for MySQL or any other services in Centos/RedHat

Note: Perform the below steps as root user 1) Find out the name of service’s script from /etc/init.d/ directory e.g. mysqld or httpd 2) Add it to chkconfig chkconfig --add mysqld 3) Make sure it is in the chkconfig chkconfig --list mysqld 4) Set it to autostart chkconfig mysqld on Note: To stop a service from auto starting on boot chkconfig mysqld off If you have IPTables you need to flush them  and save that, So that on every reboot we get a flushed iptable. 1) iptables -F 2)  service iptables save

How to redirect a URL in NGINX

How to redirect a http://test.com to http://www.com Your main server block will be like server {             listen       80;             server_name  www.test.com;             client_max_body_size   10M;             client_body_buffer_size   128k;             root       /home/test/test/public;             passenger_enabled on;             rails_env production;             error_page   500 502 503 504  /50x.html;             location = /50x.html {                     root   html;             }     } Then add a new server block with the below code. server {         server_name test.com;         return 301 $scheme://www.test.com$request_uri; } You are done!