linux基础工具、脚本、依赖库整理

镜像切换

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
yum makecache

yum update -y

基础工具包

yum install tree nmap dos2unix lrzsz nc lsof wget tcpdump htop iftop iotop sysstat nethogs -y
yum install psmisc net-tools bash-completion vim-enhanced -y

依赖库

#!/bin/bash

Libiconv_Ver='libiconv-1.15'
# 依赖库安装

for packages in make cmake gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel patch wget crontabs libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel unzip tar bzip2 bzip2-devel libzip-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap diffutils ca-certificates net-tools libc-client-devel psmisc libXpm-devel git-core c-ares-devel libicu-devel libxslt libxslt-devel xz expat-devel libaio-devel rpcgen libtirpc-devel perl python-devel cyrus-sasl-devel freetype-devel libmcrypt-devel mhash mcrypt;
do yum -y install $packages; done

#
cd ~
if [ ! -f ${Libiconv_Ver}.tar.gz ];then
    wget http://ftp.gnu.org/pub/gnu/libiconv/${Libiconv_Ver}.tar.gz
fi
tar -xf ${Libiconv_Ver}.tar.gz
cd ${Libiconv_Ver}
./configure --prefix=/usr/local/libiconv
make && make install

脚本

批量分发脚本

[root@node1 scripts]# cat xsync.sh
#!/bin/bash
#1获取输入参数的个数,如果没有参数直接退出
pcount=$#
if((pcount==0));then
    echo no args;
    exit;
fi
#2 获取文件名称
p1=$1
fname=`basename $p1`
#3 获取上级目录到绝对路径
pdir=`cd -P $(dirname $p1);pwd`
#4 获取当前用户的名称
user=`whoami`
#5循环
for((host=2;host<4;host++));do
echo -----------$host-----------
rsync -rvl $pdir/$fname $user@node$host:$pdir
done

[root@node1 scripts]# chmod 777 xsync.sh
[root@node1 scripts]# cp xsync.sh /usr/bin/xsync

批量执行脚本

[root@node1 scripts]# cat xcall.sh
#!/bin/sh
pcount=$#
if((pcount==0));then
        echo no args...;
        exit;
fi
echo ==================localhost=================
$@
for((host=2; host<=4; host++)); do
        echo ==================node$host==================
        ssh node$host $@
done
[root@node1 scripts]# chmod 777 xcall.sh
[root@node1 scripts]# cp xsync.sh /usr/bin/xsync