Published December 16, 2018 by

Install Redmine in Ubuntu using Shell Script


Redmine is a project management tool that allows users to manage projects flexibly while offering robust tracking tools and an extensive library of plug-ins. This free and open source solution offers an alternative to paid project management tools and includes support for wikis, forums, calendars, and data visualization tools.

This guide will show you how to install and set up Redmine on Ubuntu using a single shell script.


Install Redmine

What this script does:
  1. Install Apache Web server
  2. Install MySQL
  3. Install Redmine
For Install Redmine Create a file named redmine.sh
 sudo vim redmine.sh  

Insert Below script in a redmine.sh file and save.
 #!/bin/bash  
   
 #######################################  
 # Bash script to install a Redmine Project Management Tool in ubuntu  
 # Author: Subhash (serverkaka.com)  
   
 # Check if running as root  
 if [ "$(id -u)" != "0" ]; then  
   echo "This script must be run as root" 1>&2  
   exit 1  
 fi  
   
 # Check port 80 is Free or Not  
 netstat -ln | grep ":80 " 2>&1 > /dev/null  
 if [ $? -eq 1 ]; then  
    echo go ahead  
 else  
    echo Port 80 is allready used  
    exit 1  
 fi  
   
 # Ask value for mysql root password   
 read -p 'db_root_password [secretpasswd]: ' db_root_password  
 echo  
   
 # Update System  
 apt-get update  
   
 # Install Apache and mod-passenger  
 apt-get install apache2 libapache2-mod-passenger -y  
   
 # Install MySQL database server  
 export DEBIAN_FRONTEND="noninteractive"  
 debconf-set-selections <<< "mysql-server mysql-server/root_password password $db_root_password"  
 debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $db_root_password"  
 apt-get install mysql-server mysql-client -y  
 unset DEBIAN_FRONTEND  
   
 # Installing and configuring the Ubuntu Redmine package  
 apt-get install redmine redmine-mysql -y  
   
 # Install bundler gem  
 gem update  
 gem install bundler  
   
 # Configuring Apache  
 cd /etc/apache2/mods-available/   
 rm passenger.conf  
 wget https://s3.amazonaws.com/serverkaka-pubic-file/redmine/passenger.conf  
   
 # create a symlink to connect Redmine into the web document space  
 ln -s /usr/share/redmine/public /var/www/html/redmine  
   
 # Configuring Apache  
 cd /etc/apache2/sites-available/  
 rm 000-default.conf  
 wget https://s3.amazonaws.com/serverkaka-pubic-file/redmine/000-default.conf  
   
 # Create and set the ownership of a Gemfile.lock file so that apache's www-data user can access it  
 touch /usr/share/redmine/Gemfile.lock  
 chown www-data:www-data /usr/share/redmine/Gemfile.lock  
   
 # Adjust the Firewall  
 ufw allow 80/tcp  
   
 # Restart Apache  
 service apache2 restart  
   
 # Set auto start tomcat as a system boot  
 sudo systemctl enable apache2  
   
 echo "Redmine is successfully installed. For Access Redmine Go to http://localhost/redmine/  

Give execute permission to redmine.sh file
 sudo chmod +x redmine.sh  

Finally, now run the redmine.sh file
 sudo ./redmine.sh  

After successfully script execute, Go to a browser and hit http://localhost/redmine OR http://ip_address/redmine

For login press sign in button



When it asks for login and password provide default credentials. Your default login is admin and Password is also admin.


Now Redmine is ready to use.

Take Backup of Redmine

Below script is take auto backup for Redmine files and database
 #!/bin/bash  
   
 /usr/bin/mysqldump -u root -p<password> redmine_default | gzip > /path/to/backups/redmine_db_`date +%y_%m_%d`.gz  
 rsync -a /var/lib/redmine/default/files /path/to/backups/files  
Before run backup script, insert proper database password and Backup path.


Reference: https://github.com/SubhashPatel?tab=repositories
Read More
Published December 16, 2018 by

How to Increase EBS Volume Size of AWS EC2 Linux Instance

If we face data limitations in our EC2 instance's volume, we can modify or resize it.

In this tutorial, I will show you how to increase the EBS volume size in AWS using a Linux instance.

First, stop EC2 instance:


You can also perform this step in running instance without stopping it, but if possible to take downtime, then I suggest stopping the instance. 

Select instance>>Actions>>Insatnce State>>Stop

Read More
Published December 15, 2018 by

Install LAMP stack in Ubuntu using Shell Script


Read More
Published December 15, 2018 by

Install and Configure Latest WordPress in CentOS using Shell Script


Read More
Published December 15, 2018 by

Install and Configure Latest WordPress in Ubuntu using Shell Script

Read More
Published December 14, 2018 by

How to Reduce EBS volume size of AWS EC2 Linux Instance

In this tutorial, I will show you how to reduce EBS volume size in AWS using an Ubuntu Linux instance. In this example, I have 25GB root volume and try to decrease it to 8GB.

1. Login to AWS management consoles and stop the instance.
Read More
Published November 18, 2018 by

Install Let's Encrypt SSL with Apache on CentOS


In this tutorial, we are learning, with step-by-step instructions on how to install Let’s Encrypt SSL certificate with Apache on CentOS. Let’s Encrypt is an open SSL Certificate Authority (CA) that offers free domain-validated (DV) certificates for your websites. SSL Certificates are used to establish a secure encrypted connection between a web server and a user’s web browser. The SSL certificates that have been issued by Let’s Encrypt are valid for 90 days and are trusted by most web browsers today.

Step 1: Install CertBot
 $ yum -y install epel-release  
 $ yum install httpd mod_ssl python-certbot-apache  


Step 2: Set Up the SSL Certificate

Install Let’s Encrypt SSL certificate on your domain (change ‘yourdomain.com’ with your actual domain):
$ sudo certbot --apache -d example.com  

If you want to install a single certificate that is valid for multiple domains or subdomains, you can pass them as additional parameters to the command. The first domain name in the list of parameters will be the base domain used by Let’s Encrypt to create the certificate, and for that reason we recommend that you pass the bare top-level domain name as first in the list, followed by any additional subdomains or aliases
$ sudo certbot --apache -d example.com -d www.example.com  

Step 3: Renew the SSL certificate


Insert below command for renewing SSL certificate.
$ sudo certbot renew

Step 4: Auto-Renew the SSL certificate with a cronjob

Create a cronjob so the SSL certificate is renewed automatically. Run:
$ crontab -e  

and add the following line.
0 0 1 * * /usr/bin/certbot renew >> /var/log/letsencrypt-renew.log  

Save and close that file and restart cron service for the changes to take effect.
$ /sbin/service crond restart  

Open https://yourdomain.com in a web browser, and check whether Let’s Encrypt SSL is installed properly.


Read More
Published November 16, 2018 by

Install Let's Encrypt SSL with Apache on Ubuntu


In this tutorial, we are learning, with step-by-step instructions on how to install Let’s Encrypt SSL certificate with Apache on Ubuntu. Let’s Encrypt is an open SSL Certificate Authority (CA) that offers free domain-validated (DV) certificates for your websites. SSL Certificates are used to establish a secure encrypted connection between a web server and a user’s web browser. The SSL certificates that have been issued by Let’s Encrypt are valid for 90 days and are trusted by most web browsers today.

Step 1 — Install the Let's Encrypt Client
 $ sudo add-apt-repository ppa:certbot/certbot  
 $ sudo apt-get update  
 $ sudo apt-get install python-certbot-apache  

Step 2: Set Up the SSL Certificate

Install Let’s Encrypt SSL certificate on your domain (change ‘yourdomain.com’ with your actual domain):
 $ sudo certbot --apache -d example.com  

If you want to install a single certificate that is valid for multiple domains or subdomains, you can pass them as additional parameters to the command. The first domain name in the list of parameters will be the base domain used by Let’s Encrypt to create the certificate, and for that reason we recommend that you pass the bare top-level domain name as first in the list, followed by any additional subdomains or aliases
 $ sudo certbot --apache -d example.com -d www.example.com  

Step 3: Auto-Renew the SSL certificate with a cronjob

Create a cronjob so the SSL certificate is renewed automatically. Run:
 $ crontab -e  

and add the following line.
 0 0 1 * * /usr/bin/letsencrypt renew >> /var/log/letsencrypt-renew.log  

Save and close that file and restart cron service for the changes to take effect.
 $ service cron restart  

Open https://yourdomain.com in a web browser, and check whether Let’s Encrypt SSL is installed properly.


Read More
Published November 16, 2018 by

Send an Email Alert When System Disk Space Gets Low

Step 1: Get Disk Space

 df -h  

Step 2: Next filter out file system and find out the percentage of space

 (df / | grep / | awk '{ print $5}' | sed 's/%//g')  

Step 3: Write a shell script

If you don't want to step up to a full monitoring solution such as Nagios you can create your own scripts for monitoring the things that you want to monitor, such as disk space. The following script alerts you when your root partition is almost full.

 #!/bin/bash  
 CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')  
 THRESHOLD=90  
   
 if [ "$CURRENT" -gt "$THRESHOLD" ] ; then  
   mail -s 'Disk Space Alert' it.subhashpatel@gmail.com << EOF  
 Your root partition remaining free space is critically low. Used: $CURRENT%  
 EOF  
 fi
The script sends an email when the disk usage rises above the percentage specified by the THRESHOLD variable (90% here).

To run it daily, for example, save the script to the file disk-alert.sh in /opt directory, change the email to your email, and add the following line at the end of /etc/crontab file.

 @daily /opt/disk-alert.sh  
Read More
Published November 13, 2018 by

How to Setup AWS S3 Access From Specific IPs


Recently we were testing with AWS VPC, and a requirement for our project was that we needed to allow nodes within a VPC access to S3 buckets, but deny access from any other IP address. Specifically, this was accessing of data that was going to be secured using AWS IAM keys. We needed to make sure that even with the AWS access key and secret key, data could only be retrieved while inside the VPC. Adding yet another layer of security to our existing model.

By default, accounts are restricted from accessing S3 unless they have been given access via policy. However, S3 is designed by default to allow any IP address access. So to block IP's you would have to specify denies explicitly in the policy instead of allows.

Allow Access to Specific IP Addresses
 <div class="code">  
 {  
   "Id": "S3PolicyId1",  
   "Statement": [  
     {  
       "Sid": "IPDeny",  
       "Effect": "Deny",  
       "Principal": {  
         "AWS": "*"  
       },  
       "Action": "s3:*",  
       "Resource": "arn:aws:s3:::bucket/*",  
       "Condition": {  
         "IpAddress": {  
           "aws:SourceIp": "54.240.143.188/32"  
         }  
       }  
     }  
   ]  
 }  
 </div>  

Restrict Access to Specific IP Addresses
 {  
  "Version": "2012-10-17",  
  "Id": "S3PolicyId1",  
  "Statement": [  
   {  
    "Sid": "IPAllow",  
    "Effect": "Allow",  
    "Principal": "*",  
    "Action": "s3:*",  
    "Resource": "arn:aws:s3:::bucket/*",  
    "Condition": {  
      "NotIpAddress": {"aws:SourceIp": "54.240.143.188/32"}   
    }   
   }   
  ]  
 }  
This could be used as well for added layers of security with your existing applications that use/access S3 - not just nodes within a VPC. I hope this helps someone out there from any undue stress when trying to securing your S3 access.
Read More

,

Published October 09, 2018 by

AWS Data Lifecycle Manager for Automatic EC2 EBS Snapshots


Amazon Data Lifecycle Manager for EBS Snapshots provides a simple, automated way to back up data stored on Amazon EBS volumes. You can define backup and retention schedules for EBS snapshots by creating lifecycle policies based on tags. With this feature, you no longer have to rely on custom scripts to create and manage your backups.

To get started Go To Lifecycle Manager in EC2 service via AWS Console.


Click on Create Snapshot Lifecycle Policy.


Filling details in snapshot policy according to your requirement.
Click on Create Policy.

Now our automatic EBS snapshot Lifecycle is created and it takes a snapshot of selected EBS volumes according to policy.


You can also Modify or Delete Lifecycle Policy.


A Snapshot will be taken within one hour from the start time. and you can see it in Snapshots tab in EC2 service.

Read More
Published September 19, 2018 by

Connect AWS RDS MySQL instance with phpMyAdmin

In this tutorial, we will learn how to connect AWS RDS MySQL server with phpMyAdmin.


Follow below steps to configure:


Step 1:
Install Apache Web Server
sudo apt-get update -y
sudo apt-get install apache2 -y
sudo systemctl start apache2.service
Verify that Apache was installed without errors by accessing it from your local browser. Enter http://SERVER_IP/

Step 2:
Install PHP
sudo apt-get install php -y
sudo apt-get install -y php-{bcmath,bz2,intl,gd,mbstring,mcrypt,mysql,zip} 
sudo apt-get install libapache2-mod-php  -y
Step 3:
Restart Apache
systemctl restart apache2.service
Step 4:
Install and configure phpMyAdmin
cd /var/www/html/
Download phpMyAdmin from an authorized website using wget command
wget https://files.phpmyadmin.net/phpMyAdmin/4.7.3/phpMyAdmin-4.7.3-all-languages.zip
Unzip phpMyAdmin
unzip phpMyAdmin-4.7.3-all-languages.zip
Rename phpMyAdmin and go to phpMyAdmin folder
mv phpMyAdmin-4.7.3-all-languages phpmyadmin
cd phpmyadmin
Edit the configuration file for phpMyAdmin.
vim config.sample.inc.php
Below is a default file
/* Server parameters */ 
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
Now, edit this file according to below file
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'RDS MYSQL ENDPOINT';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
Save file and Close.

You can get 'RDS MYSQL ENDPOINT' from AWS RDS console. 


Step 5:
Restart Apache
systemctl restart apache2.service
Step 6:
Open inbound port 3306 in RDS Security group for access MySQL to phpMyAdmin. you can give which IP where phpMyAdmin is installed in Security group.

Step 7:
Access phpMyAdmin from your local browser. Enter http://SERVER_IP/phpMyAdmin 
enter username and password of your RDS. and access it.
Read More
Published September 09, 2018 by

Git - Delete Branches

Below are some steps to clean branches from the git repository to remove the clutter.

Delete a Local branch

To delete the local branch in Git using the command, we can use one of the followings:

# git branch -d branch_name
# git branch -D branch_name

As you can see above, we have 2 different arguments, one with small case d and one with capital case D.

The -d option stands for –delete, which would delete the local branch. The -D option stands for –delete –force, which deletes the branch even if there are uncommitted changes.

Delete a remote branch

To delete a remote branch, we can use the following command:

# git push {remote_name} –delete {branch_name}

Above command can also be used if we want to delete git tags.
Read More
Published September 09, 2018 by

Check Code Quality in Jenkins

With Jenkins Checkstyle plugin we can generate a report of code quality.

Install Checkstyle Plugin in Jenkins

Go to Dashboard -> Manage Jenkins -> Manage Plugins and select Available tab. Find "Checkstyle" and install it.


Once a plugin is installed Click on Job Configure


In Post-build Actions add Publish Checkstyle analysis results.



Your pom file has to be configured to use this checkstyle report.

Click on Save.

Click on Build Now


If there are any errors and warnings, it will be shown and categorized.




Read More
Published September 09, 2018 by

Pull Source Code from Code Repository in Jenkins

In this tutorial, we learn How to Pull Source Code from the Code Repository in Jenkins Job. This option will enable Jenkins to monitor code repository and as soon as some changes are committed on the repository, Jenkins will initiate project build for the project.

Under project click Configure



Under Source Code Management choose your Code Repository and paste Repository URL.



Under Build Triggers tick on Poll SCM and specify a time interval for checking the repository for changes if you want else skip it. (this step is optional)

Click on Save.

Crontab format



Click Build Now


See job log in console output.


Read More
Published August 18, 2018 by

Add Jenkins Slave node in Linux system

Jenkins uses a Master-Slave architecture to manage distributed builds. In this architecture, Master and Slave communicate through TCP/IP protocol.



In this tutorial, we learn how to add Jenkins slave node in Linux machine.


Step 1: Enable agent on TCP port


Go to Manage Jenkins > Configure Global Security




Scroll down and find Agents Section and click on Fixed port or random port.


Step 2: Add node


Go to Manage Jenkins > Manage Nodes



Click on New Node and give Node name.



Configure the Node parameter according to your requirements and Save. (Choose Launch method 'Launch slave agent via SSH') and other details like below screenshot.


Step 3: Activate Node

Now you can see Slave node is added successfully. But it is offline. To activate the slave node Click on Launch agent.


Go to Jenkins Master and Check, Now Jenkins Successfully connected with the slave node.


Now you can create a distributed job and build on the slave node.
Read More
Published August 17, 2018 by

Add Jenkins Slave node in Windows system

Jenkins uses a Master-Slave architecture to manage distributed builds. In this architecture, Master and Slave communicate through TCP/IP protocol.



In this tutorial, we learn how to add Jenkins slave node in windows machine.

Step 1: Enable agent on TCP port

Go to Manage Jenkins > Configure Global Security


Scroll down and find Agents Section and click on Fixed port or random port.

Step 2: Add node

Go to Manage Jenkins > Manage Nodes


Click on New Node and give Node name.



Configure the Node parameter according to your requirements and Save. (choose Launch method 'Launch agent via Java Web Start') and other details like below screenshot.



Now you can see Slave node is added successfully. But it is offline. To activate the slave node download Launch file.



Step 3: Activate Node

For activate slave node login into slave node's machine and copy Launch file here and Run it.

After, Successfully connected it shows one small pop-up for connection. Click on File > Install as a service



Go to Jenkins Master and Check, Now Jenkins Successfully connected with the slave node.


Now you can create a distributed job and build on the slave node.
Read More