常用模块自动化安装脚本

本文涉及的产品
云数据库 Tair(兼容Redis),内存型 2GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
简介:

python_mod_install.sh

#!/bin/bash

# 1.安装客户端

#wget https://pypi.python.org/packages/source/r/redis/redis-2.9.1.tar.gz

tar zxvf redis-2.9.1.tar.gz

cd redis-2.9.1/

python setup.py install

cd ..

mysql_python.sh

#!/bin/bash

#pip install MySQL-python

tar xzvf MySQL-python-1.2.3.tar.gz

cd MySQL-python-1.2.3

sed -i 's#mysql_config.path = "mysql_config"#mysql_config.path = "/usr/local/mysql/bin/mysql_config"#' setup_posix.py

python setup.py build

python setup.py install


redis.sh

#!/bin/bash

mkdir /usr/local/redis/

cp redis-2.8.6.tar.gz /usr/local/redis/redis-2.8.6.tar.gz

cd /usr/local/redis/

tar xzvf redis-2.8.6.tar.gz

cd /usr/local/redis/redis-2.8.6

make

sysctl vm.overcommit_memory=1

#/usr/local/redis/redis-2.8.6/src/redis-server /usr/local/redis/redis-2.8.6/redis.conf &

#vim /etc/sysctl.conf

ln -s /usr/local/redis/redis-2.8.6/src/redis-cli /bin/redis-cli


diskmon.sh


#!/bin/bash



function sendNotify()

{

                title=$1

                text=$2


                timestamp=$(date '+%s')

                key=$(echo -n "WEBDUDU_INTERFACE_9237426476824${timestamp}"|md5sum|cut -d ' ' -f1)


                ip=$(/sbin/ip -oneline route get 110.13.121.208|awk '{print $7}')

                ip2=$(ifconfig -a|awk '/(cast)/ {print $2}'|cut -d':' -f2|head -1)


                text="${text} ip:${ip}_${ip2}"


                curl -d "type=web&timestamp=${timestamp}&key=${key}&title=${title}&context=${text}&type=web

                "                               "http://dundun.haoren.com/frontend/Interface/sendWarnMsg"

}





# 单位K

limit=$((2*1024*1024))

free=$(df |grep -w ".*\/"|awk '{print $(NF-2)}')


#echo $limit

#echo $free


if [ $free -lt $limit ]; then

        echo "太小"

        freeM=$(($free/1024))

        text="磁盘剩余空间不足2G,为${freeM}M"

        title="磁盘空间偏小"

        sendNotify $title $text

else

        echo "当前空间充足"


fi


install_service.sh

#!/bin/sh

./sys_ini.sh

./nginx_install.sh

./install_mysql.sh

cd mod/

./mod_install.sh

cd ..

./php_install.sh

cd /opt/lnmp/memcahed

./mem.sh

cd ..

/bin/cp -rf /opt/lnmp/conf/php.ini /usr/local/lib/

/bin/cp -rf /opt/lnmp/conf/nginx.conf /usr/local/nginx/conf/

/bin/cp -rf /opt/lnmp/conf/fcgi.conf /usr/local/nginx/conf/

/bin/cp -rf /opt/lnmp/conf/php-fpm.conf /usr/local/php/etc/ 


drwxr-xr-x 2 root root     4096 11月  3 2010 conf

-rwxr-xr-x 1 root root     2520 2月  14 2008 install_mysql.sh

-rwxr-xr-x 1 root root      378 10月 18 2010 install_service.sh

drwxr-xr-x 2 root root     4096 10月 18 2010 memcahed

drwxr-xr-x 2 root root     4096 10月 18 2010 mod

-rw-r--r-- 1 root root 24433261 12月  9 2008 mysql-5.0.45.tar.gz

drwxr-xr-x 8 1000 1000     4096 8月  19 12:27 nginx-0.8.15

-rw-r--r-- 1 root root   605698 9月  14 2009 nginx-0.8.15.tar.gz

-rwxr-xr-x 1 root root      652 10月 18 2010 nginx_install.sh

drwxrwxrwx 7 1169 1169     4096 8月  19 12:27 pcre-7.9

-rw-r--r-- 1 root root  1191330 6月  26 2009 pcre-7.9.tar.gz

-rw-r--r-- 1 root root   204248 3月   9 2010 php-5.2.8-fpm-0.5.10.diff.gz

-rw-r--r-- 1 root root 12427411 12月  9 2008 php-5.2.8.tar.gz

-rwxr-xr-x 1 root root      681 11月  3 2010 php_install.sh

-rwxr-xr-x 1 root root     1224 2月  14 2008 sys_ini.sh


sys_ini.sh

#!/bin/bash

/sbin/chkconfig anacron off 

/sbin/chkconfig autofs off

/sbin/chkconfig cups off

/sbin/chkconfig gpm off

/sbin/chkconfig iiim off

/sbin/chkconfig isdn off

/sbin/chkconfig nfs off

/sbin/chkconfig nfslock off

/sbin/chkconfig pcmcia off

/sbin/chkconfig portmap off

/sbin/chkconfig rhnsd off

/sbin/chkconfig rpcgssd off

/sbin/chkconfig xfs off

/sbin/chkconfig xinetd off

/sbin/chkconfig sendmail off

/sbin/chkconfig mysqld off

/sbin/chkconfig httpd off


service anacron stop

service autofs stop

service cups stop

service gpm stop

service iiim stop

service isdn stop

service nfs stop

service nfslock stop

service pcmcia stop

service portmap stop

service rhnsd stop

service rpcgssd stop

service xfs stop

service xinetd stop

service sendmail stop

service httpd stop

service mysqld stop 


echo "*       soft    nofile  40960" >>/etc/security/limits.conf

echo "*       hard    nofile  65535" >>/etc/security/limits.conf

echo "session    required     pam_limits.so">>/etc/pam.d/login


HOSTIP=`more /etc/sysconfig/network-scripts/ifcfg-eth0 |grep IPADDR|awk -F= '{print $2}'`;echo "exec echo -ne \"\033]0;\${USER}@$HOSTIP:\${PWD/#\$HOME/~}\007\"" >/etc/sysconfig/bash-prompt-xterm;chmod +x /etc/sysconfig/bash-prompt-xterm


php_install.sh

#!/bin/bash

tar zxvf php-5.2.8.tar.gz

gzip -cd php-5.2.8-fpm-0.5.10.diff.gz | patch -d php-5.2.8 -p1

cd php-5.2.8

./configure --prefix=/usr/local/php --with-gd --with-jpeg-dir --with-zlib --with-png --with-freetype-dir --enable-magic-quotes --with-iconv --with-mbstring --with-mysql=/usr/local/mysql --enable-track-vars --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-ftp --with-config-file-path=/usr/local/lib --with-libxml-dir --with-openssl --enable-maintainer-zts 

cp php.ini-recommended /usr/local/lib/php.ini

make -j 4 

make install

cd ./ext/mbstring/

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make

make install

nginx_install.sh

#!/bin/sh


#1、安装Nginx所需的pcre库

tar zxvf pcre-7.9.tar.gz

cd pcre-7.9/

./configure

make && make install

cd ../


#2、安装Nginx

tar zxvf nginx-0.8.15.tar.gz

cd nginx-0.8.15/

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module 

make && make install

cd ../


#3、创建Nginx日志目录

#mkdir -p /usr/local/nginx/logs

#chmod +w /usr/local/nginx/logs


#4、创建Nginx配置文件

#cp /usr/local/nginx/conf/nginx.conf  /usr/local/nginx/conf/nginx.old

#rm -f /usr/local/nginx/conf/nginx.conf

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


#5、启动Nginx

#ulimit -SHn 51200

#/usr/local/nginx/sbin/nginx

#/usr/local/php/sbin/php-fpm start


install_mysql.sh


#!/bin/bash


#首先确定你是root用户


tar zxf mysql-5.0.45.tar.gz


cd  mysql-5.0.45



#根据体统类型选择编译方式

#i386体系结构的

#CFLAGS="-O3 -mcpu=pentiumpro" CXX=gcc CXXFLAGS="-O3 -mcpu=pentiumpro -felide-constructors -fno-exceptions -fno-rtti" ./configure --with-raid --enable-thread-safe-client --enable-assembler  --with-server-suffix =" for >>>MySQL Database of Zebra by Yhc<<<" --without-debug --with-extra-charsets=complex --without-isam --prefix=/usr/local/mysql --without-bench

#64位系统,x86_64

CFLAGS="-O3 -m64" CXX=gcc CXXFLAGS="-O3 -m64 -felide-constructors -fno-exceptions -fno-rtti" ./configure --with-raid --enable-thread-safe-client --enable-assembler  --with-server-suffix =" for >>>MySQL Database of Zebra by Yhc<<<" --without-debug --with-extra-charsets=complex --without-isam --without-server --prefix=/usr/local/mysql --without-bench --with-archive-storage-engine 


#然后根据CPU数量进行编译

make -j 4 && make install


#添加用户

groupadd mysql && useradd -g mysql mysql


#创建目录

mkdir /usr/local/mysql/data && mkdir /usr/local/mysql/run && mkdir /usr/local/mysql/log && mkdir /usr/local/mysql/var


#更改mysql目录所有者

#chgrp mysql -R /usr/local/mysql && chown mysql -R /usr/local/mysql

#增加打开文件数量

ulimit -n 2048


#添加PATH

echo "PATH=\"/usr/local/mysql/bin:\$PATH\"" >> /etc/profile && export PATH="/usr/local/mysql/bin:$PATH"


#strip可执行文件

strip /usr/local/mysql/libexec/mysqld


#添加LIB PATH

echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf && ldconfig


#将my.cnf文件cp到/etc目录下

/bin/cp -r /usr/local/mysql/share/mysql/my-huge.cnf  /etc/my.cnf && chown mysql:mysql /etc/my.cnf  

cd /usr/local/mysql/bin

ln -s ./mysql ./test_mysql

ln -s ./mysqladmin ./adminmysql

ln -s ./mysql_install_db ./install_db_mysql

ln -s ./mysqld_safe ./safe_mysqld

#初始化Mysql表

cd /usr/local/mysql/bin

./install_db_mysql --user=mysql

chown -R root /usr/local/mysql && chown -R  mysql /usr/local/mysql/var && chgrp -R mysql /usr/local/mysql  

pkill -9  mysql

#su - mysql -c "mysqld_safe --skip-name-resolve --open-files-limit=20480 &"


#完成后,删除空的用户名帐号。

#/usr/local/mysql/bin/mysql -uroot -e "use mysql;delete from user where "User"='';"


#为本地帐户创建密码

#/usr/local/mysql/bin/mysql -uroot -e "set password for root@"localhost" = password('123456');"

#/usr/local/mysql/bin/mysql -uroot -p123456 -e "use mysql;update user set Password=password('123456') where "Host"='localhost.localdomain';flush privileges;"


#关闭服务器

#su - mysql -c "mysqladmin -u root -pPASSWORD shutdown"



mod_install.sh

#!/bin/sh

tar zxf libpng-1.2.8-config.tar.gz

cd libpng-1.2.8-config

./configure

make

make install


cd ..


tar jxf freetype-2.1.10.pre-20050511.tar.bz2

cd freetype-2.1.10.pre-20050511

./configure

make

make install


cd ..


tar zxf jpegsrc.v6b.tar.gz

cd jpeg-6b

./configure --enable-shared

make

make install-lib


-rw-r--r-- 1 root root 1030233 8月   3 2005 freetype-2.1.10.pre-20050511.tar.bz2

-rw-r--r-- 1 root root  616196 8月  12 2005 jpegsrc.v6b.tar.gz

-rw-r--r-- 1 root root  695097 8月   3 2005 libpng-1.2.8-config.tar.gz

-rwxr-xr-x 1 root root     309 2月  14 2008 mod_install.sh


memcacheInstall.sh

#!/bin/bash

tar xzvf libevent-1.4.8-stable.tar.gz

cd libevent-1.4.8-stable

./configure --prefix=/usr

make 

make install


cd ..

tar zxvf memcached-1.2.6.tar.gz

cd memcached-1.2.6

./configure --with-libevent=/usr

make

make install


cd ..

tar zxvf  memcache-2.2.4.tgz

cd memcache-2.2.4

/usr/local/php/bin/phpize

./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config  --with-zlib-dir

make 

make install


-rw-r--r-- 1 root root 488054 12月  9 2008 libevent-1.4.8-stable.tar.gz

-rw-r--r-- 1 root root  35389 12月  9 2008 memcache-2.2.4.tgz

-rw-r--r-- 1 root root 217651 12月  9 2008 memcached-1.2.6.tar.gz

-rwxr-xr-x 1 root root    425 2月  14 2008 mem.sh



mysql_python.sh


#!/bin/bash

tar xzvf setuptools-0.6c11.tar.gz

cd setuptools-0.6c11

python setup.py build

python setup.py install


cd ..

tar xzvf MySQL-python-1.2.3.tar.gz

cd MySQL-python-1.2.3

sed -i 's#mysql_config.path = "mysql_config"#mysql_config.path = "/usr/local/mysql/bin/mysql_config"#' setup_posix.py

python setup.py build

python setup.py install


pythonInstallupdate2.7.6.sh

#!/bin/bash

tar xzvf Python-2.7.6.tgz

cd Python-2.7.6

./configure --prefix=/usr/local/python2.7.6

make 

make install

mv /usr/bin/python /usr/bin/python.bak

ln -s /usr/local/python2.7.6/bin/python2.7 /usr/bin/python





drwxrwxr-x  6 zgam zgam    4096 9月   8 16:31 MySQL-python-1.2.3

-rwxrwxrwx  1 root   root      70305 4月  10 2014 MySQL-python-1.2.3.tar.gz

-rwxrwxrwx  1 root   root        341 4月  10 2014 mysql_python.sh

drwxr-xr-x 18   1000   1000     4096 9月  12 20:43 Python-2.7.6

-rwxrwxrwx  1 root   root   14725931 4月  10 2014 Python-2.7.6.tgz

-rwxrwxrwx  1 root   root        216 9月  12 18:44 python.sh

drwxrwxr-x  7    506    506     4096 9月   8 16:31 setuptools-0.6c11

-rwxrwxrwx  1 root   root     256862 4月  10 2014 setuptools-0.6c11.tar.gz



syncKey.sh


#!/bin/bash


set timeout 30


for i in `cat ./serverlist.ini |grep "=" |grep -v "#"|awk -F= '{print $2}'`

do

    echo $i

    ssh root@$i "echo "ssh-rsa CWHJmjNtDc9XLJuDk/1UFlFUwfsUTfyVDSCyDvpHw== root@IM-SJ01-Server11" >> /root/.ssh/authorized_keys"    


done


#set timeout 5

#for i in `cat ./serverlist.ini |grep "="|awk -F= '{print $2}'`

#do

#       echo $i

#       expect<<-END

#       spawn ssh root@$i ""

#       expect "Are you sure you want to continue connecting (yes/no)?"

#       send "yes\n"

#       interact

#       expect eof

#       exit

#       END

#done


runredis.sh

#!/bin/bash

/usr/local/redis/redis-2.8.6/src/redis-server /usr/local/redis/redis-2.8.6/redis.conf &

#vim /etc/sysctl.conf


setupPerlModule.sh


mkdir -p /usr/lib/perl5/site_perl/5.8.5/Config/

mv ./IniFiles.pm /usr/lib/perl5/site_perl/5.8.5/Config/

mkdir -p /usr/lib64/perl5/site_perl/5.8.5/x86_64-linux-thread-multi/List/

mv ./MoreUtils.pm /usr/lib64/perl5/site_perl/5.8.5/x86_64-linux-thread-multi/List/


setupPerlModule64.sh

mkdir -p /usr/lib64/perl5/Config/

mv ./IniFiles.pm /usr/lib64/perl5/Config/

mkdir -p /usr/lib64/perl5/List/

mv ./MoreUtils.pm /usr/lib64/perl5/List/




RunServer.sh

#!/bin/sh


##研发环境启动,停止,重起服务器的脚本

##停止所有服务  ./RunServer stop

##开始所有服务 ./RunServer start

##重启所有服务 ./RunServer reboot

## 无参数重启所有服务 ./RunServer


#需要启动的服务器列表,按先后顺序排列

#1)尽量与DB配置保持一致;

#2)Super类服务器先启;

#3)依赖少的服务器/被依赖的服务器先启;

SERVERLIST='ToolSuperServer  GameGatewayServer VMGatewayServer

            LoginRewardServer PushMsgServer FreeItemServer WebLoginServer'


SERVERLIST_REVERSE=

for serv in $SERVERLIST

do

        SERVERLIST_REVERSE=${serv}" "$SERVERLIST_REVERSE

done


#Start servers

dowork()

{


    #启动gatewayserver前启用网关, 不需要重启服务器后操作gmclient启用网关

    mysql -uroot -D zebra_im_haoren -e "update SERVERLIST set INUSE=1 where type=42;"


        for serv in $SERVERLIST

        do

                echo "starting $serv/IM$serv"

                /home/haoren/IMTESTVERSION/release/IM$serv -d

                sleep 1

        done

        echo

        echo "ps x | grep \"Server -d\""

        ps x | grep "Server -d"

        echo -n ""

        echo "Start Server Failed:"

        for serv in $SERVERLIST

        do

                COUNT=`ps x|grep "Server -d"|grep "IM$serv"| wc -l`

                if [ $COUNT -eq 0 ]

                then

                        echo "failed /home/haoren/IMTESTVERSION/release/IM$serv -d"

                fi

        done

}


stopwork()

{

        tmpcount=1

        for serv in $SERVERLIST_REVERSE

        do if [ ${tmpcount} -eq 1 ] 

                then    

                        echo -n "stoping IM$serv "

                        tmpcount=$[tmpcount-1]

                fi    


                pkill control_server -u `whoami`

                pkill -9 IM${serv:0:10} -u `whoami`

                while test -f  RunServer.sh

                do      #确保结束第一个进程后再结束第二个,方便MonitorServer监控

                        echo -n "..."

                        COUNT=`ps x|grep "Server -d"|grep "IM$serv"| wc -l`

                        if [ $COUNT -eq 0 ]

                        then

                                break

                        fi

                        sleep 1

                done

                echo "OK"

                tmpcount=1


        done

        echo

}

echo "--------------------------------------------------"

echo "--------------------START-------------------------"

echo "--------------------------------------------------"

case $1 in 

        stop)

        stopwork

        ;;

        start)

        dowork

        ;;

        reboot)

        stopwork

        sleep 3

        dowork

        ;;

        *)

        stopwork

        sleep 1

        dowork

        ;;

esac

echo "--------------------------------------------------"

echo "----------------------DONE------------------------"

echo "--------------------------------------------------"


getComputerInfo.sh

#!/bin/bash


eth0_=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d : -f2 | awk '{print $1}'`

eth1_=`/sbin/ifconfig eth1 | grep 'inet addr:' | cut -d : -f2 | awk '{print $1}'`

hname=`hostname`

computerid=`cat /usr/local/company/haoren/.zcbm.txt`

productName=`dmidecode | grep 'Product name'`

process=`ps ax | grep "IM" | grep "Server" | grep -v "grep"`

cpuNum=`cat /proc/cpuinfo | grep processor | wc -l`

cpuPower=`echo $(grep 'model name' /proc/cpuinfo | uniq | awk -F : '{print $2}' | sed 's/^[ \t ]*//g' | sed 's/ \+/ /g') | cut -d "@" -f2`

memInfo=`free -m | grep Mem | awk '{print $2}'`

disk=`fdisk -l | grep 'Disk' | awk -F, '{print $1}' | sed 's/Disk identifier.*//g' | sed '/^$/d' | cut -d ":" -f2`


echo $process"| |"$eth0_"|"$eth1_"| |"$productName"|"$cpuNum"*"$cpuPower"|"$memInfo"MB|"$disk"|"$hname"|"$computerid"|"


route.sh


#!/bin/sh

echo "set ip_forward -> 1"

echo "1" > /proc/sys/net/ipv4/ip_forward

echo "set rt_tables"

sed -i -e '/10 DX/d' /etc/iproute2/rt_tables

sed -i -e '/20 WT/d' /etc/iproute2/rt_tables

echo '10 DX' >> /etc/iproute2/rt_tables

echo '20 WT' >> /etc/iproute2/rt_tables

echo "clean GW_DX & GW_WT"

IF_DX="eth0"

IF_WT="eth1"

GW_DX="183.150.241.29"

GW_WT="12.65.97.1"

WAN_DX="183.150.241.240"

WAN_WT="12.65.97.82"


ip route del default via $GW_DX table DX 2>&1>/dev/null

ip route del default via $GW_WT table WT 2>&1>/dev/null

ip rule del from $WAN_DX pref 10 table DX 2>&1>/dev/null

ip rule del from $WAN_WT pref 20 table WT 2>&1>/dev/null


ip route add default via $GW_DX table DX

ip route add default via $GW_WT table WT

ip rule add from $WAN_DX pref 10 table DX

ip rule add from $WAN_WT pref 20 table WT


ip route flush cache


install-memcached-20140716.sh

#!/bin/bash

#安装libevent

tar zxvf libevent-1.4.14b-stable.tar.gz

cd libevent-1.4.14b-stable

./configure --prefix=/usr/local/

make

make install

#ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib64/


cd ..


#安装memcached

tar zxvf  memcached-1.2.6.tar.gz

cd memcached-1.2.6 

./configure --prefix=/usr/local/ --with-libevent=/usr/local/

make

make install


#运行memcached时候用root账号运行,格式:

#./memcached -d -u root -m 2048 -l 172.17.13.253 -p 11211 


install-mysql.sh


#!/bin/bash


#首先确定你是root用户


tar zxfv mysql-5.1.34.tar.gz

cd  mysql-5.1.34



#根据体统类型选择编译方式

#i386体系结构的

#CFLAGS="-O3 -mcpu=pentiumpro" CXX=gcc CXXFLAGS="-O3 -mcpu=pentiumpro -felide-constructors -fno-exceptions -fno-rtti" ./configure --with-raid --enable-thread-safe-client --enable-assembler  --with-server-suffix =" for >>>MySQL Database of Zebra by Yhc<<<" --without-debug --with-extra-charsets=complex --without-isam --prefix=/usr/local/mysql --without-bench

#64位系统,x86_64

#CFLAGS="-O3 -m64" CXX=gcc CXXFLAGS="-O3 -m64 -felide-constructors -fno-exceptions -fno-rtti" ./configure --with-raid --enable-thread-safe-client --enable-assembler  --with-server-suffix =" for >>>MySQL Database of Zebra by Yhc<<<" --without-debug --with-extra-charsets=complex --without-isam --without-server --prefix=/usr/local/mysql --without-bench --with-archive-storage-engine 

CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" ./configure --enable-thread-safe-client --enable-assembler  --with-server-suffix =" for >>>MySQL Database of Zebra by Yhc<<<" --without-debug --with-extra-charsets=complex --prefix=/usr/local/mysql  


#然后根据CPU数量进行编译

make -j 8 && make install


#添加用户

groupadd mysql && useradd -g mysql mysql


#创建目录

mkdir /usr/local/mysql/data && mkdir /usr/local/mysql/run && mkdir /usr/local/mysql/log && mkdir /usr/local/mysql/var


#更改mysql目录所有者

#chgrp mysql -R /usr/local/mysql && chown mysql -R /usr/local/mysql

#增加打开文件数量

ulimit -n 2048


#添加PATH

echo "PATH=\"/usr/local/mysql/bin:\$PATH\"" >> /etc/profile && export PATH="/usr/local/mysql/bin:$PATH"


#strip可执行文件

strip /usr/local/mysql/libexec/mysqld


#添加LIB PATH

echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf && ldconfig


#将my.cnf文件cp到/etc目录下

/bin/cp -r /usr/local/mysql/share/mysql/my-huge.cnf  /etc/my.cnf && chown mysql:mysql /etc/my.cnf  

sed -i 's/skip-federated/#skip-federated/' /etc/my.cnf

cd /usr/local/mysql/bin

ln -s ./mysql ./test_mysql

ln -s ./mysqladmin ./adminmysql

ln -s ./mysql_install_db ./install_db_mysql

ln -s ./mysqld_safe ./safe_mysqld

#初始化Mysql表

cd /usr/local/mysql/bin

./install_db_mysql --user=mysql

chown -R root /usr/local/mysql && chown -R  mysql /usr/local/mysql/var && chgrp -R mysql /usr/local/mysql  

pkill -9  mysql

#su - mysql -c "mysqld_safe --skip-name-resolve --open-files-limit=20480 &"


#完成后,删除空的用户名帐号。

#/usr/local/mysql/bin/mysql -uroot -e "use mysql;delete from user where "User"='';"


#为本地帐户创建密码

#/usr/local/mysql/bin/mysql -uroot -e "set password for root@"localhost" = password('123456');"

#/usr/local/mysql/bin/mysql -uroot -p123456 -e "use mysql;update user set Password=password('123456') where "Host"='localhost.localdomain';flush privileges;"


#关闭服务器

#su - mysql -c "mysqladmin -u root -pPASSWORD shutdown"

supervisor.sh

#!/bin/bash

#https://pypi.python.org/pypi/supervisor

#wget https://pypi.python.org/packages/80/37/964c0d53cbd328796b1aeb7abea4c0f7b0e8c7197ea9b0b9967b7d004def/supervisor-3.3.1.tar.gz

tar xzvf supervisor-3.3.1.tar.gz

cd supervisor-3.3.1

python setup.py install

#默认安装到python的bin目录:/usr/local/python2.7.6/bin


#生成默认配置

/usr/local/python2.7.6/bin/echo_supervisord_conf > /etc/supervisord.conf.default

/usr/local/python2.7.6/bin/supervisord


echo "#!/bin/bash" > /home/haoren/super.sh

echo "" >> /home/haoren/super.sh

echo "nohup /usr/local/python2.7.6/bin/supervisord & > /dev/null" >> /home/haoren/super.sh


chown haoren.haoren /home/haoren/super.sh

#/usr/local/python2.7.6/bin/supervisorctl

super.sh 

#!/bin/bash


nohup /usr/local/python2.7.6/bin/supervisord & > /dev/null



vsftp_install.sh

#!/bin/bash

#1.安装vsftp

rpm -ivh vsftpd-2.0.5-24.el5.x86_64.rpm

#覆盖config file

cp vsftpd.conf /etc/vsftpd/vsftpd.conf

#3.启动vsftpd

service vsftpd start

#4.打开3级别随系统自动启动vsftpd

chkconfig --level 3 vsftpd on


vsftpd.conf

anonymous_enable=no

local_enable=YES

write_enable=YES

local_umask=022

dirmessage_enable=YES

xferlog_enable=YES

connect_from_port_20=YES

xferlog_std_format=YES

chroot_local_user=yes

pasv_enable=yes

listen=YES


pam_service_name=vsftpd

userlist_enable=YES

listen=YES

tcp_wrappers=YES


syncKey-TJ-20150204.sh

#!/bin/bash


set timeout 5


for i in `cat ./serverlist.ini |grep "="|awk -F= '{print $2}'`

do


echo $i


expect<<-END

   spawn ssh zgam@$i ""

   expect "Are you sure you want to continue connecting (yes/no)? "

   send "yes\n"

expect eof

exit

END

done


num-to-ip2.sh

#!/bin/bash


for a in `cat ./20150427-num-ip.txt`


do


N=$a

L2=$((($N & 0x000000ff) ))

L1=$((($N & 0x0000ff00) >> 8))

H2=$((($N & 0x00ff0000) >> 16))

H1=$((($N & 0xff000000) >> 24))

echo $a " " $L2.$L1.$H2.$H1  >> ./20150427-IP.txt


done


IP-search2.sh

#!/bin/bash

hexip=""

hextoip() {

    hex=$1

        ip1=`printf "%d." 0x${hex:6:2}`

        ip2=`printf "%d." 0x${hex:4:2}`

    ip3=`printf "%d." 0x${hex:2:2}`

        ip4=`printf "%d" 0x${hex:0:2}`

        ip=$ip1$ip2$ip3$ip4

        hexip=$ip

        #return $ip

}


iptohex() {

    IFS=.

    for str in $1

    do

        printf "%02X" $str

    done

}


iptoaddr ()

{

        #exec < $1

        #while read a

        for a in `cat $1`

        do

        #sring=`curl -s  "http://ip138.com/ips138.asp?ip=${a}&action=2" |grep '<ul class="ul1"><li>' |awk -F'[><]+' '{print $5}'`

        #sring=$(wget -q "http://www.ip138.com/ips.asp?ip=${a}&action=2" -O -| iconv -f gbk -t utf-8 | grep "数据" | awk -F"ul" '{print $3}' | awk -F"" '{print $1$2}' | awk -F"" '{print $2"\n"$3}' | head -1)

        hex=`printf "%X" ${a}`

        #echo $a $hex

        hextoip $hex

        #hexip=$?

        #echo $a $hexip

        sring=$(wget -q "http://ip138.com/ips138.asp?ip=${hexip}&action=2" -O -| grep '<ul class="ul1"><li>' |awk -F'[><]+' '{print $5}')

        echo $a $hexip $sring

        done

}


case $1 in

-f)

        shift

        iptoaddr $1

;;

-i)

        shift

        #sring=`curl -s  "http://ip138.com/ips138.asp?ip=${1}&action=2" |grep '<ul class="ul1"><li>' |awk -F'[><]+' '{print $5}'`

                #sring=$(wget -q "http://ip138.com/ips138.asp?ip=${1}&action=2" -O -| iconv -f gbk -t utf-8 | grep "数据" | awk -F"ul" '{print $3}' | awk -F"" '{print $1$2}' | awk -F"" '{print $2"\n"$3}' | head -1)

                #sring=$(wget -q "http://ip138.com/ips138.asp?ip=${1}&action=2" -O -| grep "数据" | awk -F"ul" '{print $3}' | awk -F"" '{print $1$2}' | awk -F"" '{print $2"\n"$3}' | head -1)

                sring=$(wget -q "http://ip138.com/ips138.asp?ip=${1}&action=2" -O -| grep '<ul class="ul1"><li>' |awk -F'[><]+' '{print $5}')

        echo $1 $sring

;;

-h)

        shift

                hex=`echo "ibase=10;obase=16;$1"|bc`

                echo $hex

        hextoip $hex

;;

-x)

        shift

        iptohex $1

;;

*)

        echo "[Help]

        $0 need -f or -i

        -f ------- argument is a file

        -i ------- argument is a IP

[For example]:

        $0 -f filename

        $0 -i ipadress

        "

;;

esac

log_trans20160706-2.py

#!/usr/bin/python

#-*- coding:UTF-8 -*-

#Write by Chang.zh

#Prostrate in worship!!!


try:

    import os,sys

    import re

    import datetime

    import shutil

    import commands


    from optparse import OptionParser

except ImportError,e:

    print "Error:",e

    sys.exit()


def Get_And_ScpLogfile(host,list,tmpdir,yestoday):

    logdir = '/log/'

    desdir = '/home/haoren/logdir/'

    global dirs;dirs = []

    for ip in list:

        ident = ip.split('.')[3]

        ldir = '%s%s_%s' % (tmpdir,yestoday,ident)

        dirs.append(ldir) 

        if not os.path.exists(ldir):

                os.makedirs(ldir)


        s,o = commands.getstatusoutput('ssh %s /bin/ls -ld %s%s ' % (ip,logdir,yestoday))

        print "********************************************%s**************************************************" % ip

        print "BEGIN:"

        if s == 0:

            os.system('/usr/bin/scp -r %s:%s%s/* %s' % (ip,logdir,yestoday,ldir)) 

        else:

            os.system('/usr/bin/scp -r %s:%s*%s* %s' % (ip,logdir,yestoday,ldir)) 



    for ip in host:

         print "**************************************SCP_To_%s**************************************************" % ip

         print "BEGIN:"

         os.system('/usr/bin/scp -r %s%s* %s:%s' % (tmpdir,yestoday,ip,desdir))     


def CleanLogFile():

    for d in dirs:

        shutil.rmtree(d,True)


def main():

    ####option####

    parser = OptionParser()

    parser.add_option("-t","--time",action="store",dest="filedate",help="appoint the logfile time,use like this '-t 130825'")

    (options,args) = parser.parse_args()


    ####option####

    

    if options.filedate:

        filedate = options.filedate

    else:

        filedate = (datetime.datetime.now() - datetime.timedelta(days=1)).strftime('%y%m%d')


    iplist = []

    host = []

    tmpdir = '/home/haoren/tempdir/'

    f = open('/home/haoren/tools/log_config.ini','r')

    for line in f:

        line = line.strip()

        if re.search(r'^[0-9]{1,2}=.*',line):

            iplist.append(line.split('=')[1])

        elif re.search(r'^host=.*',line):

            #host = line.split('=')[1]

            host.append(line.split('=')[1])

        elif re.search(r'^host2=.*',line):

        #    host2 = line.split('=')[1]

            host.append(line.split('=')[1])

    f.close()

    Get_And_ScpLogfile(host,iplist,tmpdir,filedate) 

    CleanLogFile()


if __name__ == "__main__":

    main()

udpsysctl.sh

#!/bin/sh

#增大UDP缓冲区


echo "" >> /etc/sysctl.conf

echo "# Add UDP BUF" >> /etc/sysctl.conf

echo "net.core.rmem_default=262144" >> /etc/sysctl.conf

echo "net.core.wmem_default=262144" >> /etc/sysctl.conf

echo "net.core.rmem_max=4194304" >> /etc/sysctl.conf

echo "net.core.wmem_max=4194304" >> /etc/sysctl.conf


/sbin/sysctl -p


Add-crontable.sh

#!/bin/bash

for i in `cat /root/haoren/serverlist1.ini `

do

 ssh $i "echo '*/30 * * * * /usr/sbin/ntpdate 202.108.53.214' >> /var/spool/cron/root"

 #ssh $i "source /etc/rc.d/forward"

 #ssh $i "sed -i '/115.29.24.20/d' /etc/rc.d/forward "

 #ssh $i "source /etc/rc.d/forward"

 ssh $i  /bin/echo "source  /etc/rc.d/forward" >>/etc/rc.d/rc.local

 ssh $i  /bin/mkdir -p /home/haoren/yuyoucun/

 scp    ./lrzsz-0.12.20-22.1.x86_64.rpm $i:/home/haoren/yuyoucun/

 ssh $i /bin/rpm -ivh /home/haoren/yuyoucun/lrzsz-0.12.20-22.1.x86_64.rpm

done


show-du-lh.sh

#!/bin/bash

for ip in `cat ./serverlist.ini |grep "=" |grep -v "#"|awk -F= '{print $2}'`

do

    echo $ip

    ssh $ip /bin/df -h

   # echo "Execution is complete."

done


syncKey-nogen.sh

#!/bin/bash


set timeout 30

for i in `cat ./serverlist.ini |grep "="|awk -F= '{print $2}'`

do

        echo $i

expect<<-END

#   spawn scp /root/.ssh/id_rsa.pub root@192.168.136.172:.ssh/id_rsa.pub

#   expect "password: "

#   send "haoren@123\n"


   spawn ssh root@$i "mkdir /root/.ssh/"

   expect "password: "

   send "haoren@123\n"

expect eof

exit

END

expect<<-END

   spawn scp /root/.ssh/id_rsa.pub root@$i:/root/.ssh/id_rsa.pub

   expect "password: "

   send "haoren@123\n"

expect eof

exit

END

expect<<-END

   spawn ssh root@$i "touch /root/.ssh/authorized_keys"

   expect "password: "

   send "haoren@123\n"

expect eof

exit

END

expect<<-END

   spawn ssh root@$i "cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys"

   expect "password: "

   send "haoren@123\n"

expect eof

exit

END

#   #scp *.sh $i:/root/

done


#set timeout 30

#spawn ssh root@127.0.0.1

#expect "password: "

#send "haoren@123\n"



#expect {

#    "(yes/no)?" {

#       send "yes\n"

#

#       }

#   "pwd:"{

#       ...

#       }

#}


#expect{

#       "yes/no" {send "yes\r"; exp_continue}

#       "pwd:{send"abc\n"}"

#}


insert_crab_code.sh

#!/bin/bash


DB_IP='192.168.1.12'

DB_USER=root

DB_PASSWD=123654

DB_NAME=IMHKDB



cat $1 | while read line

do

    arr=(${line})

    CODE=${arr[0]}

    TYPE=${arr[1]}

    mysql  IMHKDB  -e "INSERT INTO CRAB_CODE VALUES('$CODE', $TYPE, 0, 0)"

done


#!/bin/bash


#更新插入

cat zerotime.txt | while read line

do

        #echo $line

        read PID TIME < <(echo $line| awk '{print $1,$2}')


        mysql IMHKDB -e "UPDATE PFORMEINFO SET ADDTIME=$TIME WHERE PERFORMERID=$PID"

done


cat performerlist.txt | while read line

do

    # echo $line

    PRFORME=`echo $line | awk '{print $2}'`

    CHANNELPING=`echo $line | awk '{print $1}'`


    echo "insert into PRFORMEINFO VALUES($PRFORME, $CHANNEL, 1, 1, `date +%s`);"

    mysql -u$DBUSER  $DBNAME -e "insert into PFORMEINFO VALUES($PERFORMER, $CHANNEL, 1, 1, `date +%s`);"

done


#!/bin/bash


tables="表1 表2 表3 表4"

for table in $tables

{

        `mysqldump -uroot  IMHKDB $table > gold_table_bak/$table.sql`

}


#!/bin/sh


cat code.txt | while read line

do

        arr=(${line})

        echo ${arr[0]} ${arr[1]}

        mysql IMHKDB -e "INSERT INTO WIFILOTTERY_CARDBAG VALUES(4001, '${arr[0]}', '${arr[1]}', 0, 0);"

done



#!/bin/sh

#使用时,更改相应的参数,更改用户名与密码以及库名,其它不用更改


name=root

passwd=123654

dbname=IMHKDB

hostname=127.0.0.1

port=3306



tmpfilename=savetablename_tmp.txt


#mysql -h127.0.0.1 -uroot  DB -e "show tables like '%SPECIALFLOWERHANDSELDETAILS_201603%';" > $tmpfilename

mysql -h127.0.0.1 -uroot  DB -e "show tables like '%CLIENTBUGS201608%';" > $tmpfilename

#mysql -h127.0.0.1 -uroot  DB -e "show tables like '%2014%';" > $tmpfilename

sed -i '1,1d' $tmpfilename


for table in `cat $tmpfilename`

do

    mysql -h127.0.0.1 -uroot  DB -e "DROP TABLE $table;"

done


#!/bin/bash


echo "$1 ~ now"

timestart=`date +%s -d "$1"`

mysql -D IMHKDB -e "select sum(PRICE/100) as order_total from SON_ORDER_CREATE where OPTIME>=unix_timestamp('$1');"

mysql -D IMHKDB -e "select sum(PRICE/100) as real_total from SON_ORDER_ACCEPT where OPTIME>=unix_timestamp('$1');"

mysql -D IMHKDB -e "select count(distinct(PESENTEID)) as order_user_total from SON_ORDER_CREATE where OPTIME>=unix_timestamp('$1')"

mysql -D IMHKDB -e "select count(*) as order_song_total from SO_ORDER_CREATE where OPTIME>=unix_timestamp('$1');"


echo "order_deal_details:"


mysql -D IMHKDB -e "select a.SINGID, a.PESENTEID,a.CHANID, b.OUTERID ,(a.PRICE/100) as PRICE, from_unixtime(a.OPTIME) as OPTIME, SONG_NAME from SONG_ORDER_ACCEPT a left join CHNNELOUTERIDMAP b on a.CHANNELID=b.INNERID where a.OPTIME>=unix_timestamp('$1');"


#!/bin/bash


mysql -D IMHKDB -e "select a.GROUP_ID, count(b.CHARID) as group_members from GROUP_BIND_GAME a inner join GROUPMEMBER b on a.GROUP_ID=b.GROUPID group by a.GROUP_ID"


mysql -D IMHKDB -e "select count(b.CHARID) as joingroup_total from GROUP_BIND_GAME a inner join GROUPMEMBER b on a.GROUP_ID=b.GROUPID"


#!/bin/bash


mysql -D IMHKDB -e "select *, from_unixtime(EXPIREDTIME) from USERCONSUMEAW where USERID in (54362488, 36433198)"


#!/bin/bash


for imid in `cat singer_id_append.txt`

{

        inner_id=`mysql -D IMHKDB -e "select INNERID from IDCHANGE where OUTERID=$imid"`


        if [ "$inner_id" == "" ]; then

                inner_id="$imid"

        else

                inner_id=`echo ${inner_id:8}`

        fi

        echo "inner_id:$inner_id, outer_id:$imid"

        ((i=$inner_id%10))


        PICNAME=`mysql -D IMHKDB -e "select PICNAME from SINSHOW$i where ID=$inner_id"`

        echo $PICNAME

        echo `mysql -D IMHKDB -e "select NORMALPICNAME from SINSHOW$i where ID=$inner_id"`

        #echo $i

        #exit


}










本文转自 chengxuyonghu 51CTO博客,原文链接:http://blog.51cto.com/6226001001/1895989,如需转载请自行联系原作者
相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore &nbsp; &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
1天前
|
运维 监控 应用服务中间件
自动化运维:如何利用Python脚本提升工作效率
【10月更文挑战第30天】在快节奏的IT行业中,自动化运维已成为提升工作效率和减少人为错误的关键技术。本文将介绍如何使用Python编写简单的自动化脚本,以实现日常运维任务的自动化。通过实际案例,我们将展示如何用Python脚本简化服务器管理、批量配置更新以及监控系统性能等任务。文章不仅提供代码示例,还将深入探讨自动化运维背后的理念,帮助读者理解并应用这一技术来优化他们的工作流程。
|
2天前
|
运维 监控 Linux
自动化运维:如何利用Python脚本优化日常任务##
【10月更文挑战第29天】在现代IT运维中,自动化已成为提升效率、减少人为错误的关键技术。本文将介绍如何通过Python脚本来简化和自动化日常的运维任务,从而让运维人员能够专注于更高层次的工作。从备份管理到系统监控,再到日志分析,我们将一步步展示如何编写实用的Python脚本来处理这些任务。 ##
|
6天前
|
运维 Prometheus 监控
自动化运维之路:从脚本到DevOps
【10月更文挑战第25天】在数字化时代的浪潮中,运维不再是简单的服务器管理,而是成为了企业竞争力的核心。本文将带你走进自动化运维的世界,探索如何通过技术手段提升效率和稳定性,以及实现快速响应市场的能力。我们将一起学习如何从基础的脚本编写进化到全面的DevOps实践,包括工具的选择、流程的优化以及文化的建设。无论你是运维新手还是资深专家,这篇文章都将为你提供有价值的见解和实用的技巧。
11 3
|
8天前
|
JSON 测试技术 持续交付
自动化测试与脚本编写:Python实践指南
自动化测试与脚本编写:Python实践指南
13 1
|
24天前
|
人工智能 运维 Devops
自动化运维之路:从脚本到DevOps的转变
【10月更文挑战第7天】在这篇文章中,我们将一起探索自动化运维的演变历程,从最初的简单脚本到现代的DevOps实践。我们将深入理解自动化如何改变了运维工作的本质,并讨论实现这一转变的关键技术和策略。文章将不包含代码示例,而是聚焦于理念、工具和方法论的介绍,旨在为读者提供一个全面的自动化运维框架视图。
|
23天前
|
人工智能 运维 监控
自动化运维:从脚本到工具的演变之路
【10月更文挑战第8天】在数字化时代的浪潮中,运维不再是简单的硬件维护,它已经演变成一场关于效率、稳定性和创新的技术革命。本文将带您领略自动化运维的魅力,从最初的脚本编写到现代复杂的自动化工具,我们将一探究竟,看看这些工具如何帮助运维人员简化日常任务,提升工作效率,并最终推动业务发展。
|
1月前
|
XML 前端开发 数据格式
Ruby脚本:自动化网页图像下载的实践案例
Ruby脚本:自动化网页图像下载的实践案例
|
1月前
|
存储 运维 监控
自动化运维:使用Shell脚本简化日常任务
【9月更文挑战第35天】在IT运维的日常工作中,重复性的任务往往消耗大量的时间。本文将介绍如何通过编写简单的Shell脚本来自动化这些日常任务,从而提升效率。我们将一起探索Shell脚本的基础语法,并通过实际案例展示如何应用这些知识来创建有用的自动化工具。无论你是新手还是有一定经验的运维人员,这篇文章都会为你提供新的视角和技巧,让你的工作更加轻松。
37 2
|
19天前
|
监控 关系型数据库 MySQL
PowerShell 脚本编写 :自动化Windows 开发工作流程
PowerShell 脚本编写 :自动化Windows 开发工作流程
17 0
|
20天前
|
Web App开发 Java 测试技术
一、自动化:web自动化。Selenium 入门指南:从安装到实践
一、自动化:web自动化。Selenium 入门指南:从安装到实践
31 0