2015/03/28

CloudFlare Plugin install on cpanel

CloudFlare is a performance and security service. With 14 points of presence around the world, a website on CloudFlare typically loads twice as fast, uses 65% less server resources, saves 60% of bandwidth and has an additional layer of security. Hosting Providers get reduced server load, bandwidth savings, mitigation of DDoS attacks and and IPv4/v6 gateway.


The CloudFlare cPanel plugin makes it easy to integrate into your hosting control panel. It takes less than 5 minutes to install on a test server and then the service is available to your end customers with two clicks.


Before proceed to install cloudflare plugin, you should get HOST KEY from cloudflare partners 


https://www.cloudflare.com/certified-partners


cloudflare



Installation

Install cloudflare cpanel plugin Using an SSH client such as Terminal or Putty:


Step 1. Access cPanel for the server using root user by:



ssh root@SERVER IP ADDRESS or SERVER NAME

Step 2.



cd /usr/local/cpanel

Step 3.



curl -k -L https://github.com/cloudflare/CloudFlare-CPanel/tarball/master > cloudflare.tar.gz

Step 4.



tar -zxvf cloudflare.tar.gz

This extracts a directory that includes a UNIQUE ID. For example, the directory will be in this format:
cloudflare-CloudFlare-CPanel-d03f3b8
The UNIQUE ID is only: d03f3b8
The UNIQUE ID is not cloudflare-CloudFlare-CPanel-d03f3b8


Step 5.



cd cloudflare-CloudFlare-CPanel-UNIQUE ID/cloudflare/

Step 6.



./install_cf API HOST KEY mod_cf “YOUR COMPANY NAME”

example for Awesome Hosting Company: ./install_cf 56yt8x9s987dfy4324bnv mod_cf “Awesome Hosting”


Step 7. This will start the installation. cPanel is installed first, followed by mod_cloudflare. Depending on your server, it will take between 15 seconds and 4 minutes. You know it will be done when you see:
CloudFlare module installed successfully


Step 8. CloudFlare is now successfully added to this server. You need to repeat the process for each additional server (unless you have an automatic update script).



Best SysAdmin practices

Now that CloudFlare is installed, you can remove some of the unnecessary remnant files:


Step 9.



cd ../ ../

This takes you back two levels.


Step 10.



rm -rf cloudflare-CloudFlare-CPanel-UNIQUE ID*

To check if it is installed:

cat /etc/cloudflare.json
or
cat /usr/local/cpanel/etc/cloudflare.json

You should see an output with the following:



root@server1 [/usr/local/cpanel]# cat etc/cloudflare.json
{
“host_key”:”32yt5a7b436tuy8974tre -”, (For security purposes, this will not be your host key.)
“host_formal_name”:”Awesome Hosting”,
“host_name”:”api.cloudflare.com”,
“host_uri”:”/host-­gw.html”,
“user_name”:”www.cloudflare.com”,
“user_uri”:”/api_json.html”,
“host_port”:”443”,
“host_prefix”:”cloudflare-­resolve-­to”,
“cp_version”:”1.3.0”
}


Uninstall:


/usr/local/cpanel/bin/unregister_cpanelplugin /usr/local/cpanel/3rdparty/cloudflare.cpanelplugin




Test Websites


To ensure that CloudFlare was properly installed, enable CloudFlare for three test websites from your control panel.


To check if a website is on CloudFlare, use Terminal. Open Terminal, and enter the following dig command.


dig www.mydomain.com


Output without CloudFlare-enabled:


www.mydomain.com 10782 IN CNAME www.mydomain.com


Output with CloudFlare-enabled:


www.mydomain.com 10782 IN CNAME
www.mydomain.com.cdn.cloudflare.net.


If you see ‘.cdn.cloudflare.net’ at the end, then CloudFlare is enabled.

2015/03/27

shell Commands

# Here is a load balancing system for multicore systems
bash file
you also need this code (a dummy function)


# Starting and running a Bash script
A bash script starts with
#!/bin/bash

and if the filename is mybashtest it can be run in two ways
bash mybashtest
. mybashtest



# Reads from keyboard
read myid
echo $myid



# Defining Variables
myid=2
echo $myid


# Reads from keyboard
read myid
echo $myid



# Getting the number of CPUs



$ grep processor /proc/cpuinfo
$cat /proc/cpuinfo | grep processor | wc -l

NUMCPU=`cat /proc/cpuinfo | grep processor | wc -l | awk '{ print $1 } '`
echo $NUMCPU




# Checking permissions
$ le -l
$ chmod #helps you change that



# Job Queing



$ nice 					# runs commands with modified scheduling priority
$ atd # run jobs queued for later execution
$ ps -ef |grep java # shows the processes with java in their name
$ free # displayes free and used memory

two linux scheduling packages openpbs.org and gridengine.sunsource.net


# Running in the background
$ nohup java -cp . automatedAgentApplet.autoAgentTerminal &



# Load Balancing



shows the top two processes
ps -eo pcpu,pid -o comm= | sort -k1 -n -r | head -2

reflects the CPU load
USAGE=`ps -eo pcpu,pid -o comm= | sort -k1 -n -r | head -1 | awk '{ print $1 } '`
echo $USAGE

PID=`ps -eo pcpu,pid -o comm= | sort -k1 -n -r | head -1 | awk '{print $2 }'`
PNAME=`ps -eo pcpu,pid -o comm= | sort -k1 -n -r | head -1 | awk '{print $3 }'`


Inform the admin if the first CPU is not busy enough (<40%)
USAGE=`ps -eo pcpu,pid -o comm= | sort -k1 -n -r | head -1 | awk\
'{ print $1 } '`
USAGE=${USAGE%%.*}
[ $USAGE -lt 40 ] && mail -s "CPU is working in less than 40% capacity"

more: http://www.sandervanvugt.nl/nl/artikelen/linux-advanced-bash-scripting-managing-cpu-hogs





# Sending email after the process is finished



you need mailutils install that with sudo agp-get install mailutils
you also need to install postfix in order to use remote mail servers, it's easy
this command simply sends you an email
ifconfig | awk '{print $2}' | head -2 | tail -1 | sed 's/addr://' | mail -s "MY IP" mylinuxdesktop@gmail.com


echo "Please enter the process ID to monitor:"
read PID
while [ -e /proc/$PID ] ; do
sleep 600 # chage it to 30 or any other time in seconds (600 seconds=10 minutes!)
done
echo "Process done" | mail -s "process finished" someone@example.com



this little programm emails you whenever the top process is beeing finished
save it to a file on the server i.e "mailme"
run it in nohup: $nohup bash mailme&

PID=`ps -eo pcpu,pid -o comm= | sort -k1 -n -r | head -1 | awk '{print $2 }'`
while [ -e /proc/$PID ] ; do
sleep 600 # chage it to 30 or any other time in seconds (600 seconds=10 minutes!)
done
ifconfig | awk '{print $2}' | head -2 | tail -1 | sed 's/addr://' | mail -s "Process done" mylinuxdesktop@gmail.com





# I use the following terminal / bash commands extensively
collected from the Internet



break    Exit from a loop
cal Display a calendar
cat Display the contents of a file
cd Change Directory
chgrp Change group ownership
chmod Change access permissions
chown Change file owner and group
clear Clear terminal screen
cmp Compare two files
comm Compare two sorted files line by line
cp Copy one or more files to another location
cron Daemon to execute scheduled commands
df Display free disk space
diff Display the differences between two files
diff3 Show differences among three files
dircolors Colour setup for `ls'
echo Display message on screen
egrep Search file(s) for lines that match an extended expression
eject Eject removable media
expr Evaluate expressions
eval Evaluate several commands/arguments
find Search for files that meet a desired criteria
free Display memory usage
grep Search file(s) for lines that match a given pattern
ifconfig Configure a network interface
kill Stop a process from running
locate Find files
ls List information about file(s)
man Help manual
mkdir Create new folder(s)
more Display output one screen at a time
netstat Networking information
nice Set the priority of a command or job
nohup Run a command immune to hangups
passwd Modify a user password
ps Process status
read read a line from standard input
rsync Remote file copy (Synchronize file trees)
split Split a file into fixed-size pieces
su Substitute user identity
sudo Execute a command as another user
top List processes running on the system
traceroute Trace Route to Host
vi Text Editor
watch Execute/display a program periodically
whoami Print the current user id and name (`id -un')
Wget Retrieve web pages or files via HTTP, HTTPS or FTP
. Run a command script in the current shell
### Comment / Remark

2015/03/26

How to terminate/delete a cPanel account through SSH

 

How to terminate/delete a cPanel account through SSH?


There is script in WHM/cPanel server to terminate/delete an already created account from back-end.



# /scripts/killacct username

Example



# /scripts/killacct crybit
Are you sure you want to remove the account "crybit" [y/N]? y
Running pre removal script (/usr/local/cpanel/scripts/prekillacct)......Done
Collecting Domain Name and IP......Done
......................
......................
......................
Updating ftp passwords for crybit
Purging ftp user crybit
Ftp password files updated.
Ftp vhost passwords synced
crybit account removed

Thanks

2015/03/24

Download Android 5.1 Lollipop SDK 22


Google has just rolled out the Android 5.1 Lollipop SDK for API 22 via SDK Manager for developers, which comprises of the typical documentation, samples, source code and an assortment of system images for all major hardware architectures.


According to the official Android Developers blog, the updated Lollipop version or Android 5.1 brings improved stability, enhanced control of notifications and improved performance over the previous Lollipop release.


In addition, Android 5.1 introduces quick settings tweaks with improved animation and quick access to Wi-Fi hotspots and Bluetooth devices via Settings app, added support for HD voice and dual SIM, revamped screen pinning, advanced Device Protection and no mute mode with volume controls.


Coming back to the SDK for API 22 package, Google has detailed the new features ported into the Android 5.1 APIs on the developer portal, which is reportedly the shortest in Android's recent history.


The most noteworthy feature for third-party Android developers includes support for multiple SIM cards. It also adds support for Carrier Services such as enabling cellular providers to build apps that modify provisioning tasks like setting up the correct IP addresses for data connections.


Interested users with developer accounts can download the latest version of Android SDK via SDK manager and install the same using the steps outlined below, courtesy Android Police.




  • Go to the root folder of the SDK and open the /tools folder

  • Run the android.exe or executable on standalone SDK tool

  • If you are running Android Studio, go to Tools > Android > SDK Manager or if using Eclipse go to Window > Android SDK Manager

  • The update list may take a moment to populate and then API 22 SDK should appear in the list

  • You can now select the API 22 from the list and download the same via SDK Manager


شرح تركيب Varnish



برنامج فارنيش , هو برنامج تسريع المواقع الديناميكية على السيرفر , من خلال عمل حفظ نسخة كاش في ذاكره السيرفر RAM .

و تستعمله شركات كبرى مثل Facebook, Twitter, Vimeo, Tumblr و غيرها الكثير ...

على عكس امثاله من برامج الكاش Cache ما يميز فارنش هو حفظ المعلومات في ذاكرة السيرفر , و هذا يجعل اسرع بكثير من تخزينها في الاقراص الصلبه حتى و ان كان القرص الصلب من نوع SSD السريع جدا

من فوائده و لماذا يجب تركيبه على السيرفر

1. تقليل الحمل عن السيرفر , و خاصة المعالج CPU
2. جعل تصفح المواقع اسرع بكثير و ذلك بتخزين كاش لملفات المواقع في الذاكره مثل ملفات CSS & JS

برنامج فارنش يعمل مع برامج الويب و ليس بديل لها
بما معناه اننا سنقوم بتركيب فارنش ليعمل مع Apache web server


و الان للتركيب ادخل الشيل عن طريق برامج SSH المتنوعه و اشهرها Putty

رمز Code:

rpm --nosignature -i https://repo.varnish-cache.org/redhat/varnish-4.0.el6.rpm



رمز Code:

yum install varnish


الان يجب ان يكون عندك الناتج كالتالي لكن ستكون لديك النسخه 4.0 بالصوره موجوده نسخه 3.0

تركيب الصاروخ Varnish من المصدر و عمل اعداداته| ضاعف اداء سيرفرك


الان تم تركيب البرنامج على السيرفر و سنقوم بضبط الاعدادات

رمز Code:

nano /etc/sysconfig/varnish


ابحث عن

رمز Code:

DAEMON_OPTS="-a :6081 \


و استبدلها بـ

رمز Code:

DAEMON_OPTS="-a :80 \


ما قمنا به هو تعديل المنفذ او البورت لجعل فارنش يعمل على منفذ الويب 80 الرئيسي

الان قم بعمل حفظ
Control+O
و خروج
Control+X

و الان سنقوم بجعل الاباتشي يعمل على المنفذ 8080

رمز Code:

nano /etc/varnish/default.vcl


ابحث عن

رمز Code:

backend default {
.host = "127.0.0.1";
.port = "80";
}


استبدل رقم المنفذ 80 بــ 8080 ليكون الناتج مثل التالي

رمز Code:

backend default {
.host = "127.0.0.1";
.port = "8080";
}


و الان نقوم بعمل تعديلات على ملف اعدادات الاباتشي

رمز Code:

nano /etc/httpd/conf/httpd.conf


ابحث عن السطر

رمز Code:

 “Listen 80″


و استبدله بهذا

رمز Code:

127.0.0.1:8080


شوف المثال بالصوره

تركيب الصاروخ Varnish من المصدر و عمل اعداداته| ضاعف اداء سيرفرك

تركيب الصاروخ Varnish من المصدر و عمل اعداداته| ضاعف اداء سيرفرك

و نبحث عن هذا السطر

تركيب الصاروخ Varnish من المصدر و عمل اعداداته| ضاعف اداء سيرفرك


نستبدل بهذا

رمز Code:

NameVirtualHost 127.0.0.1:8080


و الان ننزل بنفس الملف الى اعدادات المواقع الموجود و نغير المنفذ الى 8080

مثل

تركيب الصاروخ Varnish من المصدر و عمل اعداداته| ضاعف اداء سيرفرك

و اخيرا نقوم بعمل اعادة تشغيل للفرانش و الاباتشي

رمز Code:

service httpd restart



رمز Code:

service varnish restart


تركيب الصاروخ Varnish من المصدر و عمل اعداداته| ضاعف اداء سيرفرك

انتهى التركيب و كل شي شغال الان على فارنش

فارنش يستخدم 256mb من الذاكره عند تركيبه , يجب عليك تغيير هذا على حسب سيرفرك

اذا كان في بس اس ربما عليك انقاص الحجم و اذا كان سيرفر خاص و لديك عدد جيد من الرامات تستطيع اضافة 2 جيجا او اكثر ليستعملها فارنش على حسب سيرفرك


كاتب الموضوع Slims