月度归档:2013 年十月

安装nginx1.5.6+php5.5.5+mysql5.6

yum install wget
yum install pcre
yum install openssl*
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers make
yum -y install gd gd2 gd-devel gd2-devel

groupadd www

useradd -g www www

ulimit -SHn 65535


tar zxvf pcre-8.30.tar.gz
cd pcre-8.30

./configure –prefix=/usr/local/pcre
make && make install


tar zxvf nginx-1.5.6.tar.gz

cd nginx-1.5.6/

./configure –user=www –group=www –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module –with-pcre=/app/src/pcre-8.32 –with-http_realip_module –with-http_image_filter_module

如果提示:./configure: error: the HTTP image filter module requires the GD library.说明gd-devel没有装,使用yum装就好了。

php利用gd库给图片加透明水印

针对png做一下特殊处理,否则效果达不到,直接上代码:

/**
 * 给图片添加水印
 * @param filepath $src 待处理图片
 * @param filepath $mark_img 水印图片路径
 * @param string $position 水印位置 lt左上  rt右上  rb右下  lb左下 其余取值为中间
 * @param int $quality jpg图片质量,仅对jpg有效 默认85 取值 0-100之间整数
 * @param int $pct 水印图片融合度(透明度)
 *
 * @return void
 */
function water_mark($src, $mark_img, $position = 'rb', $quality = 85, $pct = 30) {
    if(function_exists('imagecopy') && function_exists('imagecopymerge')) {
        $data = getimagesize($src);
        if ($data[2] > 3)
        {
            return false;
        }
        $src_width = $data[0];
        $src_height = $data[1];
        $src_type = $data[2];
 
        $data = getimagesize($mark_img);
        $mark_width = $data[0];
        $mark_height = $data[1];
        $mark_type = $data[2];
 
        if ($src_width < ($mark_width + 20) || $src_width < ($mark_height + 20))
        {
            return false;
        }
        switch ($src_type)
        {
            case 1:
                $src_im = imagecreatefromgif($src);
                $imagefunc = function_exists('imagejpeg') ? 'imagejpeg' : '';
                break;
            case 2:
                $src_im = imagecreatefromjpeg($src);
                $imagefunc = function_exists('imagegif') ? 'imagejpeg' : '';
                break;
            case 3:
                $src_im = imagecreatefrompng($src);
                $imagefunc = function_exists('imagepng') ? 'imagejpeg' : '';
                break;
        }
        switch ($mark_type)
        {
            case 1:
                $mark_im = imagecreatefromgif($mark_img);
                break;
            case 2:
                $mark_im = imagecreatefromjpeg($mark_img);
                break;
            case 3:
                $mark_im = imagecreatefrompng($mark_img);
                break;
        }
 
        //水印位置
        switch ($position)
        {
            case 'lt':
                $x = 10;
                $y = 10;
                break;
            case 'rt':
                $x = $src_width - $mark_width - 10;
                $y = 10;
                break;
            case 'rb':
                $x = $src_width - $mark_width - 10;
                $y = $src_height - $mark_height - 10;
                break;
            case 'lb':
                $x = 10;
                $y = $src_height - $mark_height - 10;
                break;
            default:
                $x = ($src_width - $mark_width - 10) / 2;
                $y = ($src_height - $mark_height - 10) / 2;
                break;
        }
 
        if (function_exists('imagealphablending')) imageAlphaBlending($mark_im, true);
         
        if($mark_type == 3){
            //png单独处理
            imagecopymerge_alpha ( $src_im, $mark_im, $x, $y, 0, 0, $mark_width, $mark_height, $pct );
        }else{
            imageCopyMerge($src_im, $mark_im, $x, $y, 0, 0, $mark_width, $mark_height, $pct);
        }
         
        //die('$src_type='.$src_type.'; $imagefunc='.$imagefunc);
         
        if ($src_type == 2)
        {
            $imagefunc($src_im, $src, $quality);
        }
        else
        {
            $imagefunc($src_im, $src);
        }
    }
}
 
function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct) {
    $opacity = $pct;
    // getting the watermark width
    $w = imagesx ( $src_im );
    // getting the watermark height
    $h = imagesy ( $src_im );
    // creating a cut resource
    $cut = imagecreatetruecolor ( $src_w, $src_h );
    // copying that section of the background to the cut
    imagecopy ( $cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h );
    // inverting the opacity
    $opacity = 100 - $opacity;
    // placing the watermark now
    imagecopy ( $cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h );
    imagecopymerge ( $dst_im, $cut, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $opacity );
}

记录一个linux优化脚本[转]

此脚本用于初始化linux服务器的各项配置,适用于新装linux服务器
该脚本还未试验,欢迎搬走并留下试验结果

#!/bin/bash
#Created by kerryhu
#此脚本为系统初始化脚本
#用于新装linux的相关配置工作,比如禁掉 iptable 和 SELinux 及 ipv6、优化系统内核、停掉一些没有必要的系统服务等。
#此脚本尤其适合大批新装的CentOS 系列的服务器

cat<<EOF
+———————————————————————–+
|    = = = Welcome to CentOS System init = = =            |
+———————————————————————–+
+—————————by kerry————————————+
EOF

#set ntp
yum -y install ntp
echo "* 3 * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2 >&1">>/etc/crontab
service crond restart
#set ulimit
echo "ulimit -SHn 102400" >> /etc/rc.local
#set locale
#true > /etc/sysconfig/i18n
#cat >>/etc/sysconfig/i18n<<EOF
#LANG="zh_CN.GB18030"
#SUPPORTED="zh_CN.GB18030;zh_CN:zh:en_US.UTF-8:en_US:en"
#SYSFONT="latartcyrheb-sun16"
#EOF
#set sysctl
true > /etc/sysctl.conf
cat >> /etc/sysctl.conf <<EOF
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_backets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_windows_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmen_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 1024 65535
EOF
/sbin/sysctl -p
echo "sysctl set OK!!"
#close ctrl+alt+del
sed -i "s/ca::ctrlaltdel:\/bin\/shutdown -t3 -r now/#ca::ctrlaltdel:\/sbin\/shutdown -t3 -r now/" /etc/inittab
#set purview
chmod 600 /etc/passwd
chmod 600 /etc/shadow
chmod 600 /etc/group
chmod 600 /etc/gshadow
#disable ipv6
cat << EOF
+———————————————————————–+
|    = = = Welcome to Disable IPV6 = = =                |
+———————————————————————–+
EOF
echo "alias net -pf -10 off" >> /etc/modprobe.conf
echo "alias ipv6 off" >> /etc/modprobe.conf
/sbin/chkconfig –level 35 ip6tables off
echo "ipv6 is disabled!"
#disable selinux
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
echo "selinux is disabled,you must reboot!"
#vim
sed -i "8 s/^/alias vi ='vim'/" /root/.bashrc
echo 'syntax on' > /root/.vimrc
#zh_cn
sed -i -e 's/^LANG=.*/LANG="en"/'  /etc/sysconfig/il8n
#init_ssh
ssh_cf="/etc/ssh/sshd_config"
sed -i -e '74 s/^/#/' -i -e '76 s/^/#/' $ssh_cf
#sed -i "s/#Port 22/Port 65535/" $ssh_cf
sed -i "s/#UseDNS yes /UseDNS no/" $ssh_cf
#client
sed -i -e '44 s/^/#/' -i -e '48 s/^/#/' $ssh_cf
service sshd restart
echo "ssh is init is ok…………."
#chkser
#tunoff services
#———————————————————————————-
cat << EOF
+———————————————————————–+
|    = = = Welcome to Tunoff services = = =                |
+———————————————————————–+
EOF
#———————————————————————————-
for i in 'ls /etc/rc3.d/S* '
do
   CURSRV= 'echo $i |cut -c 15-'
echo $CURSRV
case $CURSRV in
   crond | irqbalance | microcode_ctl | network | random | sshd | syslog | local)
   echo "Base services,Skip!"
   ;;
   *)
       echo "change $CURSRV to off"
       chkconfig –level 235 $CURSRV off
       service $CURSRV stop
   ;;
esac
done
echo "service is init is ok……………"