Archive for Linux分享

apache 2.4 Version get real ip

apache 2.4 version has been added by default mod_remoteip ,Check the configuration if found not resolve deleted,please delete#.

1.The following added to the apache configuration in the rearmost:

RemoteIPHeader X-Forwarded-For
RemoteIPInternalProxy 127.0.0.1/24
#CloudFlare IP Ranges
RemoteIPInternalProxy 103.21.244.0/22
RemoteIPInternalProxy 103.22.200.0/22
RemoteIPInternalProxy 103.31.4.0/22
RemoteIPInternalProxy 104.16.0.0/12
RemoteIPInternalProxy 108.162.192.0/18
RemoteIPInternalProxy 131.0.72.0/22
RemoteIPInternalProxy 141.101.64.0/18
RemoteIPInternalProxy 162.158.0.0/15
RemoteIPInternalProxy 172.64.0.0/13
RemoteIPInternalProxy 173.245.48.0/20
RemoteIPInternalProxy 188.114.96.0/20
RemoteIPInternalProxy 190.93.240.0/20
RemoteIPInternalProxy 197.234.240.0/22
RemoteIPInternalProxy 198.41.128.0/17 #CDN of your IP,Can be repeated to add

2.Modify the configuration information below

  1. #Modify log format,Plus the log format%a,Then you can restart apache:
  2. LogFormat “%h %a %l %u %t ”%r” %>s %b ”%{Referer}i” \”%{User-Agent}i”” combined
  3. LogFormat “%h %a %l %u %t ”%r” %>s %b ” common
  4. LogFormat “%h %l %u %t \”%r” %>s %b ”%{Referer}i” \”%{User-Agent}i” %I% O” combined

Comments off

The maximum number of connections is too large,Causes SSH to fail to log in

pam_limits(login:session): Could not set limit for ‘nofile’: Operation not permitted

COULD NOT SET LIMIT FOR ‘NOFILE’: How to deal with OPERATION NOT PERMITTED

If you need to allow users to use large file resources, you need to modify the kernel's file resource limit first
Modify the number of files that the user can open generally directly modify the nofile of limits.conf,However, if you modify this value to millions, it is likely that ssh cannot be logged in.、System abnormal
Because it is very likely that the number of files that can be opened by the user exceeds the number of files that can be opened by the kernel
The correct modification method is as follows:
Modify the number of files that can be opened by the kernel first,Modify the number of files that the user can open
The specific location of the kernel limit is:
/proc/sys/fs/file-max-the number of files that can be opened by all processes at the system level
/proc/sys/fs/nr_open-defines the maximum allowable modification of file-max,file-max cannot exceed this value
Modify /etc/sysctl.conf to increase:
fs.file-max =***
fs.nr_open = ***
You can modify the configuration of the kernel
After modification,Then modify /etc/security/limits.conf
* soft nofile *** * hard nofile ***
Also change here /etc/security/limits.d/90-nproc.conf

Comments off

ovz source

yum remove -y kernel-firmware-2.6.32-696.30.1.el6.noarch
wget ie.archive.ubuntu.com/centos/6/cr/x86_64/Packages/kernel-firmware-2.6.32-754.el6.noarch.rpm

rpm -ivh kernel-firmware-2.6.32-754.el6.noarch.rpm

Comments off

Linux continuously execute multiple commands

Had previously been using a "shell + expect" combination。

Later in the course of,Expect more and more that this stuff is too far behind,The following reasons:

1. It has stopped issuing new official version;

2. Debug inefficient,In many cases the code to go with the way people think Mom。

then,It was later decided to use a scripting language python all done。

Practice has proved that,python development efficiency is very high,Indeed "rough fast fierce"。

stop,Digress。。。

In my Automation case in,You need to check whether a command is executed successfully (assuming command checklog,Successful return 0,Failure to return 1)。

Under normal circumstances,In the next sentence checklog,Direct "echo $?”,Judgment 0,1To。

but,Because the execution environment of the command prompt, 0 and 1,So pexpect not judge "echo $?"the result of。

later,Wondering wondering,My mind just emerge above knowledge points,I tried it,Fix the problem it is hereby Mark。

# Checklog expect the successful implementation
checklog && echo success
pexpect.expect(‘success’)

# Checklog execution failed expectations
checklog || echo failure
pexpect.expect(‘failure’)

Brush up the knowledge:
1. Command is the semicolon ";"Separated,These commands will be executed sequentially down;
2. Command is "&&"Separated,These commands will be executed sequentially down,Stop command execution encountered an error;
3. Commands are double pipe "||"Separated,These commands will be executed sequentially down,Stop command is successful encounter,All commands will not be executed later;

Comments off

linux network speed test

wget https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
chmod +x speedtest.py
./speedtest.py
Show
root@cn2:~# ./speedtest.py
Retrieving speedtest.net configuration…
Testing from QuadraNet (104.129.8.16)…
Retrieving speedtest.net server list…
Selecting best server based on ping…
Hosted by Interoute VDC (The Angels, THAT) [1.30 km]: 1.825 ms
Testing download speed…………………………………………………………………….. Downstream
Download: 97.70 Mbit/s
Testing upload speed…………………………………………………………………………………… Uplink
Upload: 94.82 Mbit/s

Comments off

semget: No space left on device DA can not start apache

This relates to semaphores on your system (you’ve run out). Run the following to clear them out:

ipcs | grep apache | awk ‘{print $2}’ > sem.txt
for i in `cat sem.txt`; do { ipcrm -s $i; }; done;

If this becomes a common occurance, then you may need to change your ipcs semaphore limits.
Set the following in your /etc/sysctl.conf:

kernel.msgmni = 1024
kernel.sem = 250 256000 32 1024

and reboot your system to load in those values.

Comments off

Protected: Screen some ip

This content is password protected. To view it please enter your password below:

Comments off

proxmox lxc change password

1.In the parent machine lxc-attach -n 101

2.passwd

3.exit

Comments off

Linux Firewall Configuration,Open port 80、3306port

1) After the restart to take effect
Open: chkconfig iptables on
shut down: chkconfig iptables off

2) With immediate effect,After the restart failure
Open: service iptables start
shut down: service iptables stop

 

vi /etc/sysconfig/iptables

-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT (allow 80 port through the firewall)
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT (allow port 3306 through the firewall)
Special Note:Many users add these two rules to the last line of firewall configuration,Cause the firewall fails to start,Right should be added to the default port 22. This rule below

After adding a good firewall rules are as follows:

######################################
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-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 3306 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
#####################################

/etc/init.d/iptables restart
#Finally, reboot the firewall configuration to take effect

 

 

systemctl stop iptables firewall service iptables save systemctl restart iptables

Comments

centos single card Cadogan ip

#写入以下内容

DEVICE=eth0                   //绑定IP段的网卡名称
ONBOOT=yes                    //开机启用此网卡
BOOTPROTO=static              //协议为静态
IPADDR_START=192.168.0.101    //网段的起始IP
IPADDR_END=192.168.0.120      //网段的截止IP
NETMASK=255.255.255.255       //子网掩码
CLONENUM_START=0              //这个数字是网卡别名的开始位置,For example, here eth0 refers 3:0,And IP192.168.0.101 will IPADDR_START set bound to eth0:0on,以此类推
NO_ALIASROUTING=yes           //这个参数的作用是数据包始终通过eth0进出,Do not take the card aliases (such as eth0:0),Setting this parameter can speed up the response of the route,It is strongly recommended that you configure。

Comments

iftop

Installation iftop
Installation 1、Compile and install
If you can compile and install the iftop official website to download the latest source package。

Before installing the need to have installed the required basic compilation environment,For example, make、gcc、autoconf等。Installation iftop also need to install libpcap and libcurses。

On CentOS install the required dependencies:

yum install flex byacc libpcap ncurses ncurses-devel libpcap-devel

On Debian install the required dependencies:

apt-get install flex byacc libpcap0.8 libncurses5

Download iftop

wget http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz

tar zxvf iftop-0.17.tar.gz

cd iftop-0.17

./configure

make && make install

Comments

High load,Automatic restart mysql,apache

#!/bin/sh
# crontab: */3 * * * * /root/loadavg_restart_apache.sh >> /Wise / People / Ristart_apacheklog
sync
sync
echo 3 > /proc/sys/vm/drop_caches
TOP_SYS_LOAD_NUM=5
SYS_LOAD_NUM=`uptime | awk ‘{print $(NF-2)}’ | sed ‘s/,//’`
echo $(date +”%y-%m-%d”) `uptime`
if [ `echo “$TOP_SYS_LOAD_NUM < $SYS_LOAD_NUM”|bc` -eq 1 ]
then
sync
echo “#0#” $(date +”%y-% m-% d% H:%M:%S”) “pkill httpd” `ps -ef | grep httpd | wc -l`
echo “#0#” $(date +”%y-% m-% d% H:%M:%S”) “pkill mysql” `ps -ef | grep mysql | wc -l`
service httpd stop
service mysql stop
sleep 8
pkill httpd
pkill mysql

sleep 8
for i in 1 2 3
do
if [ `pgrep mysql | -The toilet -l` 0 ]
then
/sbin/service mysql start

sleep 30
echo “#1#” $(date +”%y-% m-% d% H:%M:%S”) “start mysql” `ps -ef | grep mysql | wc -l`

be

if [ `pgrep httpd | -The toilet -l` 0 ]
then

service httpd start

service wdapache start

sleep 30

echo “#1#” $(date +”%y-% m-% d% H:%M:%S”) “start httpd” `ps -ef | grep httpd | wc -l`
be

done
else
if [ `pgrep mysql | -The toilet -l` 0 ]
then
/sbin/service mysql start

sleep 30
echo “#2#” $(date +”%y-% m-% d% H:%M:%S”) “start mysql” `ps -ef | grep mysql | wc -l`

be

if [ `pgrep httpd | -The toilet -l` 0 ]
then

service httpd start

 

sleep 30

echo “#2#” $(date +”%y-% m-% d% H:%M:%S”) “start httpd” `ps -ef | grep httpd | wc -l`
be

be

The above documents,Save /root/loadavg_restart_apa_my.sh

Then

crontab -e

Add to

*/3 * * * * /root/loadavg_restart_apa_my.sh >> /Wise / People / Ristart_ap_mayklog

*/3 ***** It represents three minutes,/root / loadavg_restart_apa_my.sh you can customize。

Comments

directadmin recovery

Step 1

Run System Backup on the old server.

Admin Tools >> System Backup

 

We will be backuping home directories and mysql db’s manually so Uncheck and unselect the following options on System Backup

Add user home directories to directory list below

Backup httpd data

Backup MySQL Databases

Check and Select

Backup DNS data

Backup Directories and Files listed below

All directories/files listed in bottom section of the System Backup

now click on the Run System Backup Now icon . The backup will be stored mostly in /home/backup ( it will depend upon how you have set it in DA )

Step 2

rsync the system backup to the Newserver.

root@old:~# rsync -avurz -e ssh –delete /home/backup root@Newserver_IP:/home/backup

Step 3

On the Newserver restore the system backups one by one manually.

For example, for restoring your /etc/virtual directory,

root@new:~# cd / etc
root@new:~# tar xvzfp /home/backup/<backup_date>/custom/etc/virtual.tar.gz

Please check here for the complete paths and files used on a DirectAdmin system.

( Do take extra care while restoring /etc/passwd /etc/shadow /etc/group etc.. )

Step 4

Synchronise the home directory

root@old:~# rsync -avurz -e ssh –delete /home root@Newserver_IP:/home

Step 5

Backup and restore the mysql DB’s

On Oldserver

root@old:~# cat /usr/local/directadmin/conf/mysql.conf

Get the da_admin password from the above file

root@old:~# mysqldump -u da_admin -p –all-databases > /root/all_databases.sql

root@old:~# scp /root/all_databases.sql root@Newserver_IP:/root

On Newserver

root@new:~# cat /usr/local/directadmin/conf/mysql.conf

root@new:~# mysql -u da_admin -p < /root/all_databases.sql

Step 6

Use the ipswap script to change the Oldserver IP’s

root@new:~# cd /usr/local/direactadmin/scripts/

root@new:~# ./ipswap.sh Oldserver_IP Newserver_IP

Step 7

Update the nameservers to the Newserver IP’s.

Step 8

To resolve all the queries correctly to the new server . You will have to setup the multi server dns clustering on the new server

Comments

Protected: SSH,Firefox and Putty browse the Internet

This content is password protected. To view it please enter your password below:

Enter your password to view comments.

ovz

In a situation when a lot of disk space were freed on an in-ploop filesystem, use ploop balloon discard to optimize the ploop image size.

ploop balloon discard[–automount] [–to-free size] [–min-block min_size] [–defrag] DiskDescriptor.xml

Iteratively try to relocate and discard unused blocks from a ploop image, reducing its size.

Note that ploop device and its inner file system should be mounted. If not, one can use –automount option to automatically mount ploop for the duration of the operation.

Option –defrag can be used to run a filesystem defragmentation utility (currently e4defrag2 on ext4 only) before the main operation.

Option –to-free can be used to specify a maximum disk space to be freed. In other words, stop the process once freed space exceeded requested size. Default is 0, meaning to try to free as much space as possible.

Option –min-block can be used to specify a minimum size of an extent to free. The smallest possible extent is 1 cluster (currently 1 MB), one can specify higher value to speed up the whole discarding operation.

Note that the same functionality is available by means of vzctl compact command.

Comments

« Previous entries Next Page » Next Page »