2015/08/15

server responded no further authentication methods available حل


make sure you have proper SSH keys installed in your local computer for staring the SFTP connection to the server. If not, try adding the key or enable SSH password authentication via the section Home >> Security Center >> SSH Password Authorization Tweak in the WHM.


2015/04/15

خطوات حماية NGINX هامة وزيادة الأمان (كويب سيرفر) وتحسين الشبكة

مبدئياً ماهو ال Nginx ومميزاته ؟
ال Nginx يعمل كويب سيرفر خفيف جدا - بروكسى للمواقع الكبيرة والتى تعمل ب Apache - بروكسى لل E-Mail ايضا .. يعمل على كل الأنظمة ( Unix-Linux-Mac OS X- Microsoft Windows -Solaris) ,, يستخدم بالمواقع الكبرى مثل Wordpress - sourceforge ...

زى اى برنامج له اعدادات وملفات اساسية

مسار الإعدادات

رمز Code:

/usr/local/nginx/conf/


ملف الكونفج الخاص به

رمز Code:

/usr/local/nginx/conf/nginx.conf


مسار اللوج

رمز Code:

/usr/local/nginx/logs/


يستخدم ال Nginx HTTP بورت 80
يستخدم ال Nginx HTTPs بورت 443

الخطوات التالية لزيادة الأمان والحماية وتقليل نسبة الخطورة على الويب سيرفر:


1- نفعل SELinux
انظر
تفعيل وضبط SELinux والإستفادة من حمايتها
افتراضيا SELinux لاتحمى nginx وهو ويب سيرفر ولكن هايتم عمل دا من خلال عمل كومبايل

رمز Code:

yum -y install selinux-policy-targeted selinux-policy-devel



رمز Code:

cd /opt
wget 'http://garr.dl.sourceforge.net/project/selinuxnginx/se-ngix_1_0_10.tar.gz'


نفك الضغط

رمز Code:

tar -zxvf se-ngix_1_0_10.tar.gz



رمز Code:

cd se-ngix_1_0_10/nginx
make



رمز Code:

/usr/sbin/semodule -i nginx.pp


- نقفل السيستم

رمز Code:

getsebool -a | less
getsebool -a | grep off
getsebool -a | grep o


هانشوف الاعداد اللى يكون on نخليه off ده طبعا لإختيارك أيضاً


2- تقوية الشبكة وتحديد الصلاحيات بقدر الإمكان من خلال ملف sysctl.conf

رمز Code:

vi /etc/sysctl.conf


ضبط الإعدادات كالتالى :

رمز Code:

# Avoid a smurf attack
net.ipv4.icmp_echo_ignore_broadcasts = 1

# Turn on protection for bad icmp error messages
net.ipv4.icmp_ignore_bogus_error_responses = 1

# Turn on syncookies for SYN flood attack protection
net.ipv4.tcp_syncookies = 1

# Turn on and log spoofed, source routed, and redirect packets
net.ipv4.conf.all.log_martians = 1
net.ipv4.conf.default.log_martians = 1

# No source routed packets here
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0

# Turn on reverse path filtering
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1

# Make sure no one can alter the routing tables
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0

# Don't act as a router
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0


# Turn on execshild
kernel.exec-shield = 1
kernel.randomize_va_space = 1

# Tuen IPv6
net.ipv6.conf.default.router_solicitations = 0
net.ipv6.conf.default.accept_ra_rtr_pref = 0
net.ipv6.conf.default.accept_ra_pinfo = 0
net.ipv6.conf.default.accept_ra_defrtr = 0
net.ipv6.conf.default.autoconf = 0
net.ipv6.conf.default.dad_transmits = 0
net.ipv6.conf.default.max_addresses = 1

# Optimization for port usefor LBs
# Increase system file descriptor limit
fs.file-max = 65535

# Allow for more PIDs (to reduce rollover problems); may break some programs 32768
kernel.pid_max = 65536

# Increase system IP port limits
net.ipv4.ip_local_port_range = 2000 65000

# Increase TCP max buffer size setable using setsockopt()
net.ipv4.tcp_rmem = 4096 87380 8388608
net.ipv4.tcp_wmem = 4096 87380 8388608

# Increase Linux auto tuning TCP buffer limits
# min, default, and max number of bytes to use
# set max to at least 4MB, or higher if you use very high BDP paths
# Tcp Windows etc
net.core.rmem_max = 8388608
net.core.wmem_max = 8388608
net.core.netdev_max_backlog = 5000
net.ipv4.tcp_window_scaling = 1


احفظ واقفل الملف

إختيارية (تطبق على أى سيرفر ): هذه خطوات أخرى لتحسين الشبكة للسيرفرات التى تتعامل بنقل ملفات كبيرة وتحتاج الى زيادة ال Buffer لأن الذاكرة دائما ( TCP) تحسب تلقائى من ذاكرة النظام ككل وغالباً بتكون قليلة .

ازاى نعرف القيم المحددة للارسال والاستقبال وتغيير هذه الاعدادات لتوفير سرعة افضل للشبكة ككل .. كالتالى :

معرفة حجم الذاكرة المخصصة ككل

رمز Code:

cat /proc/sys/net/ipv4/tcp_mem


معرفة اقصى كمية من الممكن أن تستقبل (ذاكرة)

رمز Code:

cat /proc/sys/net/core/rmem_default
cat /proc/sys/net/core/rmem_max


معرفة أقصى كمية من الممكن ان ترسل

رمز Code:

cat /proc/sys/net/core/wmem_default
cat /proc/sys/net/core/wmem_max


الخطوة القادمة غير ضرورية للسيرفرات اللى ليس عليها ضغط .. لأن الافتراضى بيكون128k ودا غالبا بيكون كافى لويب سيرفر وphp وخلاص ومفيش ضغط .. التعديل دا هايزيد استهلاك الذاكرة لذا اكتفى بالخطوة السابقة باعدادات ملف sysctl.conf كما هى .

رمز Code:

echo 'net.core.wmem_max=12582912' >> /etc/sysctl.conf
echo 'net.core.rmem_max=12582912' >> /etc/sysctl.conf


ايضا هانحتاج لزيادة الحجم الأدنى والبداية والأقصى بالبايت

رمز Code:

echo 'net.ipv4.tcp_rmem= 10240 87380 12582912' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_wmem= 10240 87380 12582912' >> /etc/sysctl.conf


ايضا يمكن تفعيل window scaling وده بيكون اختيار لتوسيع نافذة النقل

رمز Code:

echo 'net.ipv4.tcp_window_scaling = 1' >> /etc/sysctl.conf


تفعيل ايضا التالى

رمز Code:

echo 'net.ipv4.tcp_sack = 1' >> /etc/sysctl.conf


لا نستفيد ايضا بان TCP يعمل كاش لاتصالات مقفولة للفترات .. لان الكاش فى الحالات دى له اتجاهين والغرض من الكاش معروف ان لما الاتصال يتم مرة اخرى يستخدم اللى موجود بالفعل من اول مرة اتصل وتم عمل الكاش له ودا المفروض فى المجمل بيسرع الاداء .. ولكن فى معظم الأوقات بيسبب ضعف فى اداء الشبكة بشكل كبير ... لذلك انا اوقفه

رمز Code:

echo 'net.ipv4.tcp_no_metrics_save = 1' >> /etc/sysctl.conf


الآن اعادة تحميل الاعدادات

رمز Code:

sysctl -p


اذا حبيت تشوف التعديلات

رمز Code:

tcpdump -ni eth0


3- نرجع لل NGINX ونلغى الموديولات الغير مطلوبة

رمز Code:

./configure --without-http_autoindex_module --without-http_ssi_module
make
make install


اذا تحب تلغى اكثر ضيف مع اول سطر
نفذا التالى وشوف ايه الموديولات اللى تحب تفعيلها او تعطيلها ونفذ

رمز Code:

./configure --help | less


تقدر تعمل كومبيل الان له لكن قبل ذلك اضف ذلك فى nginx.conf

رمز Code:

server_tokens off


دا طبعا لإلغاء ظهور نسخة السيرفر المستخدمة فى صفحات الخطأ المعروفة .

4- التحكم فى الهجمات الفلوو المتكرر

رمز Code:

vi /usr/local/nginx/conf/nginx.conf


عدل الخيارات التالية كما تريد او كما تراها

رمز Code:

  client_body_buffer_size  1K;
client_header_buffer_size 1k;
client_max_body_size 1k;
large_client_header_buffers 2 1k;


لكن اذا سيرفرك به مواقع كتير مثل المنتديات والمدونات خليها 4k او 8 لأن اذا الحجم كان اكبر من القيمة هايعطيله صفحة خطأ Request Entity Too Large" (413) ده برده للعلم .

الاختيار الرابع بيساعد فى المكافحة ضد العناكب السيئة وال DoS

ايضا تعديل قيم الفصل او اغلاقه للاتصال .. وده بيحسن فى الاداء بشكل عام وبيقطع الاتصال الزائد عن الحد بيه وبيحافظ على سرعة مناسبة جدا

رمز Code:

  client_body_timeout   10;
client_header_timeout 10;
keepalive_timeout 5 5;
send_timeout 10;


الخطوة السابقة التعديل على القيم فيها حسب ماتناسب احتياجات سيرفرك ( أهل مكة أدرى بشعابها )

5- تحديد وغلق الاتصالات من اى بى واحد لبورت 80 لفترة اذا تكرر 15 مرة فى فترة بلغت 60 ثانية

رمز Code:

/sbin/iptables -A INPUT -p tcp --dport 80 -i eth0 -m state --state NEW -m recent --set
/sbin/iptables -A INPUT -p tcp --dport 80 -i eth0 -m state --state NEW -m recent --update --seconds 60 --hitcount 15 -j DROP
service iptables save


* دائما راجع ملفات اللوج وتظل متابع دائما

رمز Code:

grep "/login.php??" /usr/local/nginx/logs/access_log
grep "...etc/passwd" /usr/local/nginx/logs/access_log
egrep -i "denied|error|warn" /usr/local/nginx/logs/error_log


بعض النقاط ايضا .. دائما يكون الويب سيرفر بيوزر بمفرده مش للرووت .. الصلاحيات ايضا لايمكن ان تدع هذا المسار بتصريحات write او اذا كان فى يوزر له بيكون المسار باسمه على سبيل المثال nginx

رمز Code:

find /nginx -user nginx



رمز Code:

find /usr/local/nginx/html -user nginx



رمز Code:

ls -l /usr/local/nginx/html/


بتدى الصلاحية بشكل عادى جدا

حذف الباك اب للملفات التى انشأت من vi او اى محرر اخر

رمز Code:

# find /nginx -name '.?*' -not -name .ht* -or -name '*~' -or -name '*.bak*' -or -name '*.old*'
# find /usr/local/nginx/html/ -name '.?*' -not -name .ht* -or -name '*~' -or -name '*.bak*' -or -name '*.old*'


اذا اردتم ايضا شل سكربت به بعض اوامر iptables للحماية ايضا وتقليل الصلاحيات بشكل كبير من الممكن ارفقه لمن يريد .

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

تحياتى

حماية وتأمين tmp ب nodev, nosuid وجعل /tmp كملف نظام

السلام عليكم ورحمة الله وبركاته

درس حماية جديد وانا شخصياً شايفه مهم جدا .. وهو تأمين مسار tmp بالاختيارات nodev, nosuid,noexec
مسارات التخزين المؤقتة مثل /tmpاو /var/tmp او /dev/shm دول اللى بيوفروا مساحة لملفات الاختراق اللى بتوفر للمخترق المنفذ اللى يمر منه للسيرفر .

*حماية خاصة ل /tmp وجعله كملف نظام يخلى انه من الصعب جدا اختراقه

رمز PHP:

mkdir -p /root/images/
dd if=/dev/zero of=/root/images/tmpfile.bin bs=1 count=0 seek=4G


ثم

رمز PHP:

mkfs.ext4 /root/images/tmpfile.bin



رمز PHP:

mount -o loop,rw,nodev,nosuid,noexec /root/images/tmpfile.bin /tmp
chmod 1777 /tmp


الخطوة اللى فاتت .. عملنا ملف جديد اصبح ملف نظام واضفنا له الاختيارات الثلاثة
ننفذ التالى

رمز PHP:

mount -o rw,noexec,nosuid,nodev,bind /tmp /var/tmp


 

رمز PHP:

vi /etc/fstab


هانعدل على ال /tmp كالتالى

رمز PHP:

/root/images/tmpfile.bin   /tmp   ext4    rw,noexec,nosuid,nodev,bind    0 0


نضيف ايضا

رمز PHP:

/tmp /var/tmp none rw,noexec,nosuid,nodev,bind 0 0


نبحث عن السطر الخاص ب/tmp

رمز PHP:

UUID=0aef28b9-3d11-4ab4-a0d4-d53d7b4d3aa4 /tmp                    ext4    defaults        1 2


نضيف فى الاختيارات الخاصة اللى قولنا عليها يكون كالتالى

رمز PHP:

UUID=0aef28b9-3d11-4ab4-a0d4-d53d7b4d3aa4 /tmp                    ext4    defaults,nodev,nosuid,noexec        1 2


نضيفهم ايضا ل /dev/shm
نبحث عن

رمز PHP:

tmpfs                   /dev/shm                tmpfs   defaults        0 0


نغير انها تكون

رمز PHP:

tmpfs                   /dev/shm                tmpfs   defaults,nodev,nosuid,noexec        0 0


ايضا نحمى التمب ونضيف السطر التالى

رمز PHP:

/tmp /var/tmp none rw,noexec,nosuid,nodev,bind 0 0


نحفظ ونقفل الملف
دلوقتى نفعل الاختيارات من غير مانعمل ريبوت للسيرفر نفذ التالى :

رمز PHP:

mount -o rw,noexec,nosuid,nodev,bind /tmp/ /var/tmp/
mount -o remount,noexec,nosuid,nodev /tmp
mount -o remount,noexec,nosuid,nodev /dev/shm


ونأكد اللى عملناه بالتالى

رمز PHP:

mount
mount | less
mount | egrep --color -w '^(tmpfs|/tmp)|/tmp'


بعض النقاط :
nodev - عدم ترجمة الرموز اوحجب الادوات الخاصة بملف النظام
noexec - عدم السماح بتنفيذ اى مر مباشرة بملف النظام المنشأ
nosuid - الغاء فاعلية محدد المستخدم او المجموعة

لكم تحياتى

كيفية الترقية من MySQL الى استخدام MariaDB بدون مشاكل

السلام عليكم ورحمة الله وبركاته

قد أعلنت العملاقة ريدهات بأنه من بداية الاصدار RHEL7 سوف يتم استخدام MariaDB بدلا من MySQL في وجود صدمة ل Oracle اللى كانت بتعتمد كتير جدا بالاتفاق مع ريدهات على استخدامها ل MySQL .

لقيت ان مفيش حد اتكلم عن الموضوع دا هنا رغم أهميته والامكانيات الممتازة ل MariaDB ..
للعلم: ان المؤسس ل MariaDB هو نفسه مؤسس MySQL ولكنه كان باع MySQL الى شركة صن وده فى حد ذاته سبب التطوير الكبير فى MariaDB .

أيضا لابد ان يكون تم التحديث لنسخة ال MySQL
MariaDB تعمل بنفس الاصدار الى 5.5 .. بمعنى عندك نسخة الداتابيز 5.2 يبقى تنزلها MariaDB 5.2

انا هافترض ان الكل محدث الى 5.5 .

*- ناخد باك اب من كل قواعد البيانات الموجودة عندنا .. وهانحفظها فى نفس المسار اللى موجودين فيه

رمز PHP:

mysqldump --all-databases --user=root --password --master-data > backupdatabase.sql


هايطلب الباسورد بعدها ندخله ونكمل

رمز PHP:

service mysqld stop
chkconfig mysqld off


الامر هايعمل نسخة من ملف /etc/my.cnf باسم /etc/my.cnf.rpmsave

رمز PHP:

yum remove mysql* mysql-server mysql-devel mysql-libs



رمز PHP:

rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm



رمز PHP:

yum --enablerepo=remi-test --disablerepo=remi install compat-mysql55


نجهز متطلبات MariaDB حتى يتم التركيب بدون مشاكل او أخطاء

رمز PHP:

vi /etc/yum.repos.d/mariadb.repo


نضع داخله

رمز PHP:

# MariaDB 5.5 CentOS repository list
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1


نحفظ ونقفل الملف .. ثم تحديث النظام

رمز PHP:

yum update


ثم نبدا تركيب MariaDB

رمز PHP:

yum install MariaDB-devel MariaDB-client MariaDB-server -y


ننفذ التالى لتشغيل الخدمة مرة اخرى

رمز PHP:

service mysql start
chkconfig mysql on


هانعمل باسورت لرووت MySQL

رمز PHP:

/usr/bin/mysql_secure_installation


هاتمشى مع الخطوات .. بتغيير الباسورد وحذف داتا بيز test واليوزر anonymous ايضا.. والغاء دخول الرووت من خارج السيرفر ( اختيارى) لحد فى النهاية هانوصل للرسالة

رمز Code:

All done!  If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!


نسترجع اعداداتنا تانى

رمز PHP:

cp /etc/my.cnf.rpmsave /etc/my.cnf


هانعمل overwrite

نسترجع القواعد تانى

رمز PHP:

mysql -u root -p < backupdatabase.sql


ثم

رمز PHP:

service mysql restart


كده نبقى رقينا واستفدنا بخدمة لسيرفر داتابيز كويس .. ندخل نشيك على القواعد

رمز PHP:

mysql -u root -p



رمز PHP:

MariaDB [(none)]> show databases;



رمز PHP:

MariaDB [(none)]> status;



رمز PHP:

MariaDB [(none)]> use dbname;


تحياتى للجميع

تفعيل وضبط SELinux والإستفادة من حمايتها


السلام عليكم ورحمة الله وبركاته

SELinux هى اداة حماية لكيرنل بتحجم المدى المسموح لدخول الملفات من البرامج وتحديد أى فعل مناسب

SELinux لها ثلاث حالات :

- SELINUX=enforcing ( تطبيق قوانين SELinux مباشرة بدون تحذير او انظار )
- SELINUX=permissive (تطبيق قوانين SELinux ولكن تظهر تحذير بذلك )
- SELINUX=disabled ( الغاء تفعيل SELinux بالكامل )

قبل كل شىء .. خد باك اب من اى تعديل هاتعمله فى أى شىء


1- تركيب ملحقات ال SELinux

رمز Code:

yum install policycoreutils setroubleshoot


2- تشغيل SELinux فى وضع permissive

رمز Code:

vi /etc/selinux/config


نحدث البيانات كالتالى

رمز Code:

SELINUX=permissive
SELINUXTYPE=targeted


احفظ الملف واقفله ونعمل ريبوت للسيرفر

3- نتأكد ان SELinux لم تتعارض مع شىء ولم توقف شىء

رمز Code:

grep "SELinux is preventing" /var/log/messages


المفروض مايطلع معك أى أخطاء ومن الأفضل ان يتم عمل Relabel للملفات بالنظام ككل

الأوامر التالية لعمل relabel
- لاسترجاع اوامر الحماية الافتراضية ل /home

رمز Code:

restorecon -Rv -n /home


نفذ ايضا

رمز Code:

 touch /.autorelabel
reboot


4- تفعيل وضع enforcing

رمز Code:

vi /etc/selinux/config


التعديل لتكون

رمز Code:

SELINUX=enforcing


* نتأكد من عدم الغاء تفعيل SELinux من ال Grub loader

رمز Code:

egrep -i 'selinux=0|enforcing=0' /boot/grub/grub.conf


اذا وجدت السطور التالية تحذفها وتحفظ الملف وتعمل ريبوت

رمز Code:

selinux=0 or enforcing=0


للتأكد من التفعيل

رمز Code:

sestatus


مثال على النتيجة

رمز Code:

SELinux status:                 enabled
SELinuxfs mount: /selinux
Current mode: enforcing
Mode from config file: enforcing
Policy version: 24
Policy from config file: targeted


كيف أعرف قائمة بالبورتات المفتوحة ؟

رمز Code:

semanage port -l
semanage port -l | less
##لو عاوز تشوف بورت معين وليكن 80###
semanage port -l | grep -w 80


كيفية فتح بورت 8181

رمز Code:

semanage port -a -t http_port_t -p tcp 8181


كيف أعرف الخدمات الغير محمية ؟؟

رمز Code:

ps -eZ | egrep "initrc" | egrep -vw "ps|tr|egrep|awk|bash" | tr ':' ' ' | awk '{ print $NF }'


SELinux اداة معقدة لكنها مهمة .. ممكن تاخد وقت فى تصليح الأخطاء لكن بالتعامل الجيد ممتازة

بعض الأدوات للتعرف على المشاكل

رمز Code:

ps -Z -p 
ls -Z fn اسم الملف
ausearch
restorecon
semodule
audit2allow
Log files: /var/log/audit/audit.log and /var/log/setroubleshoot/setroubleshootd.log



التحويل من CentOS الى CloudLinuX مع السى بانل


السلام عليكم ورحمة الله وبركاته

CloudLinux سيستم ممتاز بيمتاز بالأمان والاداء العالى .. الغالبية يستخدمه لأغراض حماية عالية
CloudLinux سيستم مدفوع على عكس CentOS يجب الحصول على ترخيص لتشغيله بشكل دائم على السيرفر .. له دعم هائل من ريدهات .. تحديثات مستمرة
له العديد من الامكانيات .. LVE - CageFS -ApacheModule
يدعم ايضا ال Xen - KVM - VMWare

بعد الحصول على الترخيص للاى بى من السى بانل

رمز PHP:

/usr/local/cpanel/cpkeyclt



رمز PHP:

/usr/local/cpanel/bin/cloudlinux_system_install -k


نعمل ريبووت للسيرفر

رمز PHP:

reboot


ثم كومبايل للاباتشى من جديد

رمز PHP:

 /usr/local/cpanel/scripts/easyapache --build


كده انتهينا

لو بترخيص مباشر من كﻻود لينكس
https://cln.cloudlinux.com/clweb/buy.html

رمز PHP:

wget http://repo.cloudlinux.com/cloudlinux/sources/cln/cpanel2cl



رمز PHP:

sh cpanel2cl -k <key>


استبدل <key> برقم ترخيصك

رمز PHP:

reboot



رمز PHP:

/scripts/easyapache --build



تركيب CafeFS على CloudLinux لعزل كل مستخدم عن باقى السيرفر

السﻻم عليكم ورحمة الله وبركاته

اليوم .. تركيب CageFS اللى يعتبر اساس دعاية CloudLinux بالبدايات و LVE ايضا
هو عبارة عن نظام تخيلى يفصل كل يوزر على السيرفر بعيدا عن اى يوزر اخر .. بمعنى اسهل لو اخترق موقع ميقدرش يدخل على يوزر تانى ويتنقل بداخل السيرفر
ايضا بيمنع من قدرة اى يوزر من معرفة حتى تواجد يوزر اخر على السيرفر ومعرفة اسم اليوزر الخاص به
ايضا مفيش مشاكل منه مع اى برنامج او خدمات على السيرفر مثل :

رمز Code:

•	Apache (suexec, suPHP, mod_fcgid, mod_fastcgi)
• LiteSpeed Web Server
• Cron Jobs
• SSH


يتطلب تركيبه مساحة 8G ووجود LVE
ايضا
نبدأ :

رمز PHP:

yum install cagefs



رمز PHP:

/usr/sbin/cagefsctl --init


استخدامه :

يمكن تفعيل النظام لأى يوزر او كل اليوزرات الموجودة على السيرفر
لتفعيل للكل :

رمز PHP:

/usr/sbin/cagefsctl --enable-all


لتعطيل للكل :

رمز PHP:

/usr/sbin/cagefsctl --disable-all


للتفعيل ليوزر معين :

رمز PHP:

/usr/sbin/cagefsctl --enable [username]


لعرض الأعضاء الغير مفعل لهم النظام :

رمز PHP:

/usr/sbin/cagefsctl --list-disabled


العيوب :
* بيقوم النظام بتحميل اعدادات البى اتش بى من مسار مختلف .. اى نعم هى نفس الاعدادات بالملف الاصلى لكن اذا عدلت بالملف الاصلى php.ini لابد من تنفيذ الأمر

رمز PHP:

cagefsctl --update


*lastlog لن تعمل نهائيا ( باعتقادى ﻻيوجد احد يستخدمه كثيرا )

- النظام عبارة عن تمبلت .. اى تعديل لابد من عمل التحديث .. لكن بيتيح السهولة فى الاضافة والتعديل . بمعنى ان زى اى تمبلت له ملفات بامتداد معين .. انا ممكن اكريت ملف بنفس الامتداد واحط فيه اعداداتى اللى احتاجها ( طبعا محتاجة ادارى فاهم ) .. على سبيل المثال
هانعمل ملف لعملاء الشل بإسم openssh-conf.cfg ومحتواه هايكون :

رمز PHP:

[openssh-clients]
comment=OpenSSH Clients
paths=/etc/ssh/ssh_config, /bin/hostname, /usr/bin/scp, /usr/bin/sftp, /usr/bin/slogin, /usr/bin/ssh, /usr/bin/ssh-add, /usr/bin/ssh-agent, /usr/bin/ssh-copy-id, /usr/bin/.ssh.hmac, /usr/bin/ssh-keyscan, /usr/libexec/openssh/sftp-server, /etc/environment, /etc/security/pam_env.conf
devices=/dev/ptmx


وﻻزم بعد اى تعديل ننفذ الأمر

رمز PHP:

/usr/sbin/cagefsctl --update


ممكن اضيف عن طريقة اى RPM انا بحتاجها بسهولة جدا ( الاضافة تكون لداخل النظام نفسه )

رمز PHP:

cagefsctl --addrpm ffmpeg


بعدها انفذ

رمز PHP:

cagefctl --update


ايضا لمراعاة مسارات التمب والمساحة اللى بيشغلها في cagefs نظام حذف تلقائى كرون

رمز PHP:

cagefsctl --set-tmpwatch='/usr/sbin/tmpwatch -umclq 720'


رقم 720 دا عدد الساعات اللى تمر على الملف قبل حذفه .. دا معناه ان اى ملف بالتمب لم يتم استخدامه لمدة شهر هايتم حذفه تلقائيا .

اذا اردت عدم الانتظار للكرون كل شهر .. يمكنك التتنفيذ فورا

رمز PHP:

cagefsctl --tmpwatch


لحذفه نظام CageFS :

رمز PHP:

/usr/sbin/cagefsctl --remove-all
yum remove cagefs


طبعا انا مخترعتش الحاجات دى .. كل دا موجود كده كده على الموقع الرسمى cloudlinux.com

أتمنى الإفادة للجميع

طريقة الترقية الى الاصدار الجديد CentOS 7

السلام عليكم ورحمة الله وبركاته

طريقة الترقية الى الاصدار الحديث من Red Hat فى توزيعة CentOS 7
اصدار 7 به اختلافات كثيرة من ريدهات هذه المرة .. طفرة فى التعامل مع اضافات وتطوير بالنتورك

نقوم بالتالى لعمل الترقية ( الذى يعتبر اضافة لم تكن موجودة وهى الترقية اونلاين عن طريق اداة جديدة وهى redhat-upgrade-tool )

رمز PHP:

mkdir -p /root/upgrade
cd /root/upgrade
wget  http://dev.centos.org/centos/6/upg/x86_64/Packages/preupgrade-assistant-1.0.2-33.el6.x86_64.rpm http://dev.centos.org/centos/6/upg/x86_64/Packages/preupgrade-assistant-contents-0.5.13-1.el6.noarch.rpm http://dev.centos.org/centos/6/upg/x86_64/Packages/preupgrade-assistant-ui-1.0.2-33.el6.x86_64.rpm http://dev.centos.org/centos/6/upg/x86_64/Packages/python-rhsm-1.9.7-1.el6.x86_64.rpm http://dev.centos.org/centos/6/upg/x86_64/Packages/redhat-upgrade-tool-0.7.22-1.el6.noarch.rpm


نركب شىء جديد منهم وهو pre upgrade assistant

رمز PHP:

yum localinstall preupgrade-assistant-*
preupg



رمز PHP:

yum localinstall redhat-upgrade-tool-0.7.22-1.el6.noarch.rpm python-rhsm-1.9.7-1.el6.x86_64.rpm



رمز PHP:

rpm --import http://ftp.plusline.de/centos/7.0.1406/os/x86_64/RPM-GPG-KEY-CentOS-7



رمز PHP:

redhat-upgrade-tool --network 7.0 --instrepo http://ftp.plusline.de/centos/7.0.1406/os/x86_64/ --force


هانعمل ريستارت بعد هذه الخطوة

لتجنب ظهور رسالة خطأ بخصوص ال RPMs

رمز PHP:

cd /mnt/var/lib/rpm



رمز PHP:

rm __*


ونعمل ريستارت ايضا

ثم للتأكد

رمز PHP:

cat /etc/centos-release


تحياتى للجميع

طريقة تثبيت PageSpeed Module ,Apache, Nginx

السلام عليكم ورحمة الله وبركاته

طريقة اضافة موديل PageSpeed المقدم من شركة جوجل لتسريع الويب سيرفر سواء كان Apache او Nginx
مع الاباتشى اسمه mod_pagespeed
مع الnginx اسمه ngx_pagespeed


1- طريقة اضافته مع الاباتشى :

رمز PHP:

yum install at
rpm -U mod-pagespeed-*.rpm


2- طريقة الاضافة مع Nginx :

رمز PHP:

yum install gcc-c++ pcre-dev pcre-devel zlib-devel make


تركيب الموديول فقط

رمز PHP:

  cd ~
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.6.29.5-beta.zip
unzip release-1.6.29.5-beta.zip
cd ngx_pagespeed-release-1.6.29.5-beta/
wget https://dl.google.com/dl/page-speed/psol/1.6.29.5.tar.gz
tar -xzvf 1.6.29.5.tar.gz


تركيب الموديول مع الدعم وبتتأكد الاول من احدث نسخة اصدرت من nginx

رمز PHP:

 cd ~
wget http://nginx.org/download/nginx-1.4.1.tar.gz
tar -xvzf nginx-1.4.1.tar.gz
cd nginx-1.4.1/
./configure --add-module=$HOME/ngx_pagespeed-release-1.6.29.5-beta
make
make install


ملفات الكونفج الخاصة بالموديول
* بالاباتشى تكون بالمسار التالى

رمز PHP:

/etc/httpd/conf.d/pagespeed.conf


اما بالنسبة ل nginx فبيكون فى الملف المعتاد للكونفج بالمسار

رمز PHP:

/usr/local/nginx/conf/nginx.conf


الموديول يفعل تلقائيا مع الاباتشى بمجرد التركيب ...
اما بالنسبة ل nginx فيجب اضافة بعض السطور فى كل جزء به

رمز PHP:

server


اضافة الكود التالى فى كل جزء به server بملف الكونفج الخاص ب nginx

رمز PHP:

pagespeed on;

# تأكيد مسار الكاشx.
pagespeed FileCachePath /var/ngx_pagespeed_cache;

location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" {
add_header "" "";
}
location ~ "^/ngx_pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; }
location /ngx_pagespeed_message { allow 127.0.0.1; deny all; }


لتفعيل الموديول mod_pagespeed .. من ملف pagespeed.conf
بأوله نجعل الخيار

رمز PHP:

ModPagespeed on


من الممكن ايضا تعطيله من كونفج الاباتشى نفسه ولكن ليس باستخدام on او off

رمز PHP:

ModPagespeed unplugged


بالنسبة ل nginx للتفعيل او ايقافه من ملف nginx.conf
فى اى بلوك يخص http او server نضيف

رمز PHP:

pagespeed on;


بكده يكون انتهى التركيب وطريقة التحكم الاساسية بالموديول ... الخطوة القادمة فقط لمن لدية خبرة كافية للتعديل على الويب سيرفر ( حتى مايعطل شىء )

امكانيات الموديول كثيرة وله اختيارات عديدة ايضا .. فى ملف http.conf على سبيل المثال

رمز PHP:

ModPagespeed On
ModPagespeedInheritVHostConfig on
ModPagespeedFileCachePath "/var/cache/mod_pagespeed/"
ModPagespeedEnableFilters combine_css,combine_javascript

AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html

NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example1.com
ModPagespeedMapRewriteDomain cdn.example1.com *example.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example2.org
ModPagespeedMapRewriteDomain cdn.example2.org *example.org
# الغاء الدمج ل css هنا
ModPagespeedDisableFilters combine_css
</VirtualHost>


الخيارات المفعلة بشكل عام للمودويول .. والتحكم بها بشكل خاص ب virtual hosts

ايضا نفس الطريقة بال nginx

رمز PHP:

http {
pagespeed On;
pagespeed FileCachePath "/var/cache/ngx_pagespeed/";
pagespeed EnableFilters combine_css,combine_javascript;

server {
listen 80;
server_name www.example1.com;
root /www/example1;
pagespeed MapRewriteDomain cdn.example1.com *example.com;
}

server {
listen 80;
server_name www.example2.org;
root /www/example2;
pagespeed MapRewriteDomain cdn.example2.org *example.org;
# هنا ايضا تعطيل دمج ال css لهذا الموقع فقط
pagespeed DisableFilters combine_css;
}

server {
listen 80;
server_name www.example3.org;
root /www/example3;

# لاحظ هنا تعطيل الموديول لهذا الموقع
pagespeed off;
}


لكم تحياتى

2015/04/14

حماية ووردبريس

أهلا وسهلاً بكم


يتضمن هذا الدرس :


1- إعادة تسمية مجلد wp-content
2- إعادة تسمية مجلد wp-admin
3- حذف وسم generator من الهيدر



وطبعاً فائدة الثلاثة اعلاه هي حماية المدونة

وأنت تتساءلون لماذا حذف generator بشأن حذف الوسم , فهذا الوسم يعطي معلومات عن رقم اصدار النسخة المستخدمة
أولاً هذا غير مهم لأي شخص
ثانياً في حال اكتشف الهاكر ثغرة في احد النسخ وعرف انك تستخدمها فسوف يستطيع اختراقها ولذلك علينا حذف ذاك الوسم.

نبدأ الآن مع القسم الأول من الدرس:


إعادة تسمية مجلد wp-content :

1- افتح ملف اسمه wp-config.php

2- أضف الكود التالي في اخر الملف :

 


رمز PHP:

define('WP_CONTENT_FOLDERNAME', 'wp-content');
define('WP_CONTENT_DIR', ABSPATH . WP_CONTENT_FOLDERNAME );
define('WP_CONTENT_URL', 'http://domain.ext/'.WP_CONTENT_FOLDERNAME);
define('WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
define('WP_PLUGIN_URL', WP_CONTENT_URL.'/plugins');



 


عليك :

1- طبعا مع تغيير كلمة domain.ext الى اسم دومينك , مثال : mosa3ed.com
2- في السطر الاول من الكود عليك تغيير كلمة wp-content الموجودة بين علامتي تنصيص '' الى اي اسم تريده , مثال : mosa3ed-media
3- تغيير اسم مجلد wp-content الى ماتم اختياره في الكود اعلاه


لبعض النسخ وخصوصاً اصحاب نسخ 3.1.3 وما فوق:

1- فتح ملف default-constants.php الموجود في مجلد /wp-includes/
2- استبدال كل كلمات wp-content الى اسم المجلد اللي تريده.
3- تغيير اسم مجلد wp-content الى ما اخترته.


ملاحظة: عليك التأكد ان كل الإضافات تعمل بشكل سليم وان كانت بعضها لا تعمل فافعل الاتي :

افتح ملفات الإضافة عبر محرر النصوص من اي نوع واستبدل كلمة wp-content باس المجلد الجديد دائماً .


القسم الثاني من الدرس:

إعادة تسمية مجلد wp-admin :

يمكنك فعل هذا بطريقتين :

1- الاولى هي عن طريق ملف الهتكسس .htaccess ووضع جدار ناري حول ملف wp-admin وحجب الدخول المباشر لملف login.php
2- الطريقة الثانية هي عن طريق إضافة صغيرة تدعى Devbits ويمكنك تحميلها من هنا:

WordPress › Stealth Login � WordPress Plugins




القسم الثالث والأخير:


حذف وسم generator من الهيدر:

1- افتح ملف functions.php الموجود في المجلد wp-includes
2- اضف الكود التالي مباشرةً بعد <?php :


رمز PHP:

remove_action(‘wp_head’, ‘wp_generator’);





---------------------------------

Done.

2015/04/09

How to do network profiling with dig




dig (domain information groper) is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server(s) that were queried. Most DNS administrators use dig to troubleshoot DNS problems because of its flexibility, ease of use and clarity of output. Other lookup tools tend to have less functionality than dig.


Although dig is normally used with command-line arguments, it also has a batch mode of operation for reading lookup requests from a file. A brief summary of its command-line arguments and options is printed when the -h option is given. Unlike earlier versions, the BIND 9 implementation of dig allows multiple lookups to be issued from the command line.


Unless it is told to query a specific name server, dig will try each of the servers listed in /etc/resolv.conf.


When no command line arguments or options are given, dig will perform an NS query for “.” (the root).


It is possible to set per-user defaults for dig via ${HOME}/.digrc. This file is read and any options in it are applied before the command line arguments.


The IN and CH class names overlap with the IN and CH top level domains names. Either use the -t and -c options to specify the type and class, use the -q the specify the domain name, or use “IN.” and “CH.” when looking up these top level domains.




Example use



Basic



$ dig google.com

; <<>> DiG 9.7.0-P1 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52035
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;google.com. IN A

;; ANSWER SECTION:
google.com. 89 IN A 64.233.181.104

;; Query time: 26 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Mon Jul 5 13:00:32 2010
;; MSG SIZE rcvd: 44


Mail



$ dig -t mx google.com

; <<>> DiG 9.7.0-P1 <<>> -t mx google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63606
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;google.com. IN MX

;; ANSWER SECTION:
google.com. 900 IN MX 200 google.com.s9a2.psmtp.com.
google.com. 900 IN MX 100 google.com.s9a1.psmtp.com.
google.com. 900 IN MX 300 google.com.s9b1.psmtp.com.
google.com. 900 IN MX 400 google.com.s9b2.psmtp.com.

;; Query time: 18 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Mon Jul 5 13:00:40 2010
;; MSG SIZE rcvd: 162




How to analyze Apache log for security with Scalp



Scalp! is a log analyzer for the Apache web server that looks for security problems. It reads the Apache log and perform log analysis for possible attacks against rulesets provided by PHP-IDS project. It is available for download from it’s Google code page.

Scalp! is currently written in Python though the writer claims he’s now working on C++ version of it. Current Python can only analyze a maximum of 10000 lines of log, and seems to be a bit slow. The C++ version is aimed to overcome the problems.

When being run without any parameters, Scalp will look for access_log and default_filter.xml files in the current directory, and produce the report to the standard output. access_log is the Apache log file, and default_filter.xml is the filter rules available from the PHPIDS project. Running the program as the following will use the Apache log file at /var/log/apache2/access.log and the PHPIDS ruleset from ~/default_filter.xml;
$ python scalp.py --log /var/log/apache2/access.log --filters ~/default_filter.xml

To overcome the 10000 lines limitation of the program, a Linux program called split can be run as in the example below as a log splitter, and Scalp! is then run against all the splitted log;
$ split -l 10000  /var/log/apache2/access.log

How to redirect non-www URL to www in Apache



If both www and non www domain of your website (http://example.com and http://www.example.com) serve the same website, and you want people going to http://example.com to automatically be redirected to http://www.example.com, there's a few way that you can do so with Apache




.htaccess




First of all, make sure mod_rewrite is installed and enabled for your Apache installation. Once it is, add a file named .htaccess in your website's root directory and add the following lines;
RewriteEngine On
RewriteCond %{HTTP_HOST} ^!example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]


Virtualhost




You can also change your website's Virtualhost setting for the redirect.
<VirtualHost *:80>
ServerName example.com
Redirect permanent / http://www.example.com/
</VirtualHost>

You'll need to restart Apache for this method to work


How to disable directory listing in Apache



If no DirectoryIndex (normally configured as index.html, index.htm, index.php, welcome.html) present in a directory, and if mod_autoindex is enabled (which by default is normally enabled), Apache would list the directory contents, as the following;



While useful for some cases, you would want to disable this feature (perhaps for security reason). There are few ways to do this.




Disable mod_autoindex




The easiest way is probably to disable the autoindex module entirely. This would affect all the sites hosted on the server, which could be both good and bad.

The module is called autoindex, and can be disabled by the a2dismod command, as in the following example.
sudo a2dismod autoindex


Directory's Options directive




The option could be applied per-directory, via the Directory's Option directive as the following.
<Directory /var/www/mysite>
Options -Indexes
</Directory>

Notice that it's -Indexes and not +Indexes

This could be set in your Apache's configuration file.


.htaccess




The above method would also work by adding a .htaccess file with the following content that you want directory listing to be disabled.
Options -Indexes

Changes should take effect when apache is restarted.


How to configure Apache reverse proxy



Apache's reverse proxy is an act of an Apache webserver providing content from other webserver transparently. This is useful in many instances such as caching and mirroring, but it's mostly used to serve websites that are hosted behind NAT or a firewall. A reverse proxy server routes connection addressed to the internal server, and the client sees the reverse proxy server itself as the origin server.


For example, Apache can be configured to serve URL's such as http://www.example.com/webapp to actually get the content from http://192.168.0.10/myapp, which is hosted from an internal network. This happens transparently and the user initially requesting http://www.example.com/webapp need not to be aware of what happens in the background.




Enable proxy modules




Apache require 2 modules enabled for this reverse proxy to work. These modules are proxy and proxy_http. To enable them, run the following command at the terminal.
sudo a2enmod proxy_http

That will enable both proxy and proxy_http, as proxy module is actually a dependency to the proxy_http module. This is confirmed by the output of the above command.
Considering dependency proxy for proxy_http:
Enabling module proxy.
Enabling module proxy_http.

Once the module is enabled, you can start configuring the reverse proxy settings.


Configure reverse proxy




From the previous example, we would like our public facing webserver at http://www.example.com to host our internal site of http://192.168.0.10/myapp to be available as http://www.example.com/webapp

You'll need to add the following lines to your Apache's configuration file.
For Ubuntu, the file could be /etc/apache2/sites-enabled/000-default

ProxyRequests Off

ProxyPass /webapp http://192.168.0.10/myapp
ProxyPassReverse /webapp http://192.168.0.10/myapp


Restart Apache




For the changes to take effect, the Apache webserver need to be re-started. Run the following command at the terminal to do that.
sudo /etc/init.d/apache2 restart


How to change Apache user and group


Apache web server normally runs as the user nobody, www-data or apache. These users usually has limited permission on the system, and doesn't normally has shell login. This is good for security reason, but if for whatever reason you are required to run Apache as different user and group, you have the option to do that.


What you'll need to do is to change the User and Group directive in Apache configuration file. In Ubuntu the main configuration file is /etc/apache2/httpd.conf.


The following configuration will run Apache as the user nobody, and group nobody.



User nobody
Group nobody

You can change that to other user and group available in the system.



This could be a big security risk, especially to those changing the user to root

You will need to restart Apache first for the changes to take effect.



sudo /etc/init.d/apache2 restart

The check if the your changes work, run ps as the following;



ps aux | grep apache

Which should give you output imilar to the following;



root      1188  0.0  0.1 162184  6664 ?        Ss   Mar29   0:02 /usr/sbin/apache2 -k start
nobody 1197 0.0 0.1 162184 5668 ? S Mar29 0:00 /usr/sbin/apache2 -k start
nobody 1198 0.0 0.1 162184 5916 ? S Mar29 0:00 /usr/sbin/apache2 -k start
nobody 1200 0.0 0.1 162184 5684 ? S Mar29 0:00 /usr/sbin/apache2 -k start
nobody 1201 0.0 0.1 162184 5684 ? S Mar29 0:00 /usr/sbin/apache2 -k start
nobody 1202 0.0 0.1 162184 5684 ? S Mar29 0:00 /usr/sbin/apache2 -k start

Notice that Apache runs as the user nobody.



unable to execute dex gc overhead limit exceeded gc overhead limit exceeded


Eclipse will throw GC overhead limit exceeded error when it runs out of memory, normally while performing memory-consuming operations such as building workspace on big projects.


The error would look something like this;




An internal error occurred during: "Building workspace".
GC overhead limit exceeded

To fix this problem, you'll need to allocate more memory to your Eclipse instance. To do this, locate the eclipse.ini file in your Eclipse's installation directory. The content would be something similar to the following;



-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20140116-2212
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.6
-XX:MaxPermSize=256m
-Xms40m
-Xmx512m

To increase the memory allocation for your Eclipse instance, edit the number in the following lines accordingly.



-Xms512m
-Xmx1024m

These options are passed to Java when launching Eclipse. Xms specifies the initial memory allocation pool, and Xmx specifies maximum memory allocation pool for Java Virtual Machine (JVM). The number is the amount of memory, in Megabytes.


You can also increase the value of MaxPermSize, as the following;



-XX:MaxPermSize=1024m

MaxPermSize or Permanent Generation defines the memory allocated to keep compiled class files.


Restart Eclipse for the changes to take effect.



2015/04/06

افتراضي التحول من MySQL الى MariaDB فى اصدارات cPanel الجديدة

السلام عليكم ورحمة الله وبركاته

بعد صدور النسخة النهائية من cPanel 11.48 وبعد سرد مابها من اختلافات وتطويرات
كان من اهمها دعم الشركة MariaDB بدلا من MySQL لقواعد البيانات وهو تحول مهم ومفيد لسيرفراتنا جدا فى الاداء .. وانصح الجميع وبشدة الاستغناء عن MySQL .

شرح اليوم عن استبدال MySQL ب MariaDB من خلال اوامر متعلقة بسكربت cPanel نفسه
قد قمت من قبل بشرح الاستبدال بالفعل فى الاصدارات الماضية وهذه الطريقة مختلفة بعض الشىء

اول شىء وأهم شىء دائما .. ناخد باك اب لاى ملف ومسار ما سنعدل عليه

رمز PHP:

cp -Rf /var/lib/mysql /var/lib/mysql-old
mv /etc/my.cnf /etc/my.cnf-old


نقوم بحذف الباكجات الخاصة ب MySQL

رمز PHP:

/scripts/update_local_rpm_versions --edit target_settings.MySQL55 uninstalled
/scripts/update_local_rpm_versions --edit target_settings.MySQL56 uninstalled



رمز PHP:

/scripts/check_cpanel_rpms --fix --targets=MySQL55,MySQL56


سنضيف الريبو الخاص ب MariaDB من اجل تحميل السيرفر وملحقاته
نفتح الملف بالامر التالى

رمز PHP:

vi /etc/yum.repos.d/MariaDB.repo


ونضع بداخله

رمز PHP:

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5.41/centos6-amd64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1


نفتح ملف

رمز PHP:

vi /etc/yum.conf


نبحث عن السطر الموجود به

رمز PHP:

exclude=


ونقوم بحذف كل من php* و mysql*

الان نقوم بتسطيب السيرفر وملحقاته
ننفذ كل سطر على حده

رمز PHP:

yum install MariaDB-server MariaDB-client MariaDB-devel php-mysql
/etc/init.d/mysql start
mysql_upgrade
/etc/init.d/mysql restart


ثم نقوم بعمل بيلد للاباتشى للاطمئنان بأن كل شىء يعمل بشكل سليم وموديولات PHP تم تحميلها بنجاح .

رمز PHP:

/scripts/easyapache --build


تحياتى للجميع .

2015/04/02

شرح نقل جميع مواقع سيرفر معين الى سيرفر اخر

السلام عليكم ,,

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

تابع ,,

طبق ,,

وقف الاباتشي عالسيرفر حتى توخد باك ابات حديثة وما تكون رايح منها مشاركات اثناء النقل ,,



رمز Code:

/etc/init.d/httpd restart


طبق التالي لاخذ باك اب لجميع مواقع السيرفر :



رمز Code:

for i in `ls /var/cpanel/users`;do /scripts/pkgacct $i; Done


الان باك ابات جميع مواقع السيرفر موجودة بالمسار : /home بالسيرفر القديم ,,
لنقلها للجديد ,,

افتح السيرفر الجديد ,, وطبق :



رمز Code:

cd /home; scp -r -P PORT *.tar.gz root@LOCALHOST:/home


PORT = بورت الـشل للسيرفر الجديد
LOCALHOST = اي بي السيرفر الجديد .
طبعا باقي الامر واضح ,,

راح يظهر لك تاكيد عند الدخول لاول مرة اكتب yes ومن ثم تابع واكتب باسورد الروت ,, وانتظر لحين تحميل كافة الباك ابات ,, ومبروك عليك النقل ,,

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



رمز Code:

for i in `ls /home/*.tar.gz`;do /scripts/restorepkg --force $i;done


دمتم بود ,,

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