首页 > 学院 > 操作系统 > 正文

常用模块自动化安装脚本

2024-06-28 16:01:26
字体:
来源:转载
供稿:网友

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 zgame    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

}

#!/bin/shOK="/033[32mPASS/033[m"NO="/033[31mWARNING/033[m"FAIL="/033[31mFAIL/033[m"if [ -e "net-snmp.zip" ]        then        echo -e "检查文件net-snmp.zip: [$OK]"        rm -rf /tmp/net-snmp         unzip net-snmp.zip  -d /tmp 1>/dev/null 2>&1else        echo -e "检查文件net-snmp.zip: [$NO] (/033[31m需要下载到本地目录上/033[m)"         exit        fi# 检查下载scripts目录if [ -d "/root/scripts" ]        then        :else        mkdir /root/scripts        cd /root/scriptsfi#SELINUX#######################################################################################################################        SElinuxOK=`grep  -v '^#'  /etc/selinux/config|grep 'SELINUX='`        SElinuxOFF=`/usr/sbin/getenforce`        if [  "$SElinuxOK"  ==  'SELINUX=disabled' ]                then                if [ "$SElinuxOFF" == 'Disabled' ]                        then                        echo  -e "检查SELINUX是否关闭: [$OK]"                        /usr/sbin/setenforce 0 1>/dev/null 2>&1                else                        echo  -e "检查SELINUX是否关闭: [$OK]"                        /usr/sbin/setenforce 0 1>/dev/null 2>&1                fi        else                echo -e  "检查SELINUX是否关闭: [$NO] (SELINUX没有关闭,可能会影响net-snmp的自定义OID脚本运行)"                sed  -i '/^SELINUX=/d' /etc/selinux/config  ;  sed  -i  '/SELINUXTYPE= type/i  SELINUX=disabled' /etc/selinux/config                /usr/sbin/setenforce 0 1>/dev/null 2>&1        fi#dmidecode.pl.exe##############################################################################################################        if [ -e "/root/scripts/dmidecode.pl.exe" ]                  then                dmi_md5="6c533aaf2c84ca04c90d1c9542123671";                dmimd5=`md5sum /root/scripts/dmidecode.pl.exe |awk '{print $1}'`;                if [ $dmi_md5 == $dmimd5 ]                       then                      echo -e "dmidecode.pl.exe脚本检查:[$OK]"                else                      cd  /root/scripts/                      rm -f dmidecode.pl.exe*                      cp /tmp/net-snmp/dmidecode.pl.exe  /root/scripts/dmidecode.pl.exe                       chmod +x dmidecode.pl.exe                          fi        else                echo -e "dmidecode.pl.exe脚本检查:[$NO]"                cd  /root/scripts/                rm -f dmidecode.pl.exe*                cp /tmp/net-snmp/dmidecode.pl.exe  /root/scripts/dmidecode.pl.exe                chmod +x dmidecode.pl.exe        fi        if [ "`awk '/root//scripts//dmidecode.pl.exe/' /var/spool/cron/root`" ]                then                echo -e "dmidecode.pl.exe脚本定时任务检查:[$OK]"        else                        sed  -i '/dmidecode.pl.exe/d' /var/spool/cron/root                echo '*/15 * * * * /root/scripts/dmidecode.pl.exe'>> /var/spool/cron/root                 /sbin/service crond restart        fi#snmpd#########################################################################################################################        if [ -e "/etc/snmp/snmpd.conf" ]                then                rm -f /etc/snmp/snmpd.conf        fi                cd /root/scripts/             rm -f snmpd.conf*        cp /tmp/net-snmp/snmpd.conf /root/scripts/snmpd.conf         if [ -e "/usr/local/sbin/snmpd" ]                then                echo -e "安装软件包:snmpd:[$OK]"        else                echo -e "安装软件包:snmpd:[$NO]"                rpm -ivh /tmp/net-snmp/RedHat_AS_4.3/beecrypt-devel-3.1.0-6.x86_64.rpm 1>/dev/null 2>&1                rpm -ivh /tmp/net-snmp/RedHat_AS_4.3/elfutils-libelf-devel-0.97-5.x86_64.rpm 1>/dev/null 2>&1                rpm -ivh /tmp/net-snmp/RedHat_AS_4.7/beecrypt-devel-3.1.0-6.x86_64.rpm 1>/dev/null 2>&1                rpm -ivh /tmp/net-snmp/RedHat_AS_4.7/elfutils-libelf-devel-0.97.1-5.x86_64.rpm 1>/dev/null 2>&1                rpm -ivh /tmp/net-snmp/RedHat_AS_5.4/beecrypt-devel-4.1.2-10.1.1.x86_64.rpm 1>/dev/null 2>&1                rpm -ivh /tmp/net-snmp/RedHat_AS_5.4/elfutils-libelf-devel-0.137-3.el5.x86_64.rpm 1>/dev/null 2>&1                cd /tmp/net-snmp                 tar zxvf net-snmp-5.1.2.tar.gz 1>/dev/null 2>&1                cd net-snmp-5.1.2                ./configure --with-out-mib-modules="host/hr_swinst" --with-mib-modules="disman/event-mib host ucd-snmp/diskio"  --with-ldflags=-L/usr/lib64 --with-sys-contact  --with-sys-location --with-default-snmp-version=2 --with-logfile=/var/log/snmpd.log --with-persistent-directory=/var/net-snm 1>/dev/null 2>&1                 make 1>/dev/null 2>&1                 make install 1>/dev/null 2>&1                /usr/local/sbin/snmpd -c /root/scripts/snmpd.conf                sed -i '///usr//local//sbin//snmpd/d' /etc/rc.d/rc.local                echo "/usr/local/sbin/snmpd -c /root/scripts/snmpd.conf" >> /etc/rc.d/rc.local        fi        if [ -x "/root/scripts/snmphw.py" ]                then                echo -e "snmphw.py 脚本检查 [$OK]"        else                echo -e "snmphw.py 脚本检查 [$NO]"                cd /root/scripts/                rm -f snmphw.py*                cp /tmp/net-snmp/snmphw.py /root/scripts/snmphw.py                chmod +x snmphw.py        fi        rm -rf /tmp/net-snmp


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表