ssh免密登录
#!/bin/bash
read -p "密码" PASS
#设置网段最后的地址,4-255之间,越小扫描越快
END=254
IP=`ip a s ens33 | awk -F'[ /]+' 'NR==3{print $3}'`
NET=${IP%.*}.
rm -f /root/.ssh/id_rsa
[ -e ./SCANIP.log ] && rm -f SCANIP.log
for((i=3;i<="$END";i++));do
ping -c 1 -w 1 ${NET}$i &> /dev/null && echo "${NET}$i" >> SCANIP.log &
done
wait
ssh-keygen -P "" -f /root/.ssh/id_rsa
rpm -q sshpass || yum -y install sshpass
sshpass -p $PASS ssh-copy-id -o StrictHostKeyChecking=no $IP
AliveIP=(`cat SCANIP.log`)
for n in ${AliveIP[*]};do
sshpass -p $PASS scp -o StrictHostKeyChecking=no -r /root/.ssh root@${n}:
done
网卡配置
#!/bin/bash
read -p "请输入网卡名称(例:ens33): " wk
read -p "请输入你的ip地址: " ip
read -p "请输入你的网段: " wd
cd /etc/sysconfig/network-scripts/
echo "TYPE=Ethernet
BOOTPROTO=static
DEVICE=$wk
ONBOOT=yes
IPADDR=$ip
NETMASK=255.255.255.0
GATEWAY=$wd
DNS1=114.114.114.114" >ifcfg-$wk
systemctl restart network
if [ $? -eq 0 ]
then
echo "网卡配置成功"
else
echo "网络配置失败"
fi
nginx编译安装
#!/bin/bash
NV=`ls | grep ^nginx.*\.tar\. | sed 's/nginx-\(.*\).tar.*/\1/' | tail -n1 `
ping www.baidu.com -c2 &>/dev/null
if [ $? -eq 0 ]
then
echo '网络正常'
else
echo '网络不通请检查网络'
exit
fi
systemctl status nginx.service &>/dev/null
if [ $? -eq 0 ]
then
echo "已安装`nginx -v`"
exit
else
echo 将安装nginx-$NV
fi
yum -y install gcc pcre-devel openssl-devel zlib-devel openssl openssl-devel &>/dev/null
id nginx
if [ $? -eq 0 ]
then
echo '已有用户nginx'
else
useradd -s /sbin/nologin nginx
fi
tar xf nginx-$NV.tar.gz
cd nginx-$NV
./configure --prefix=/apps/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module &>/dev/null
make -j2 &>/dev/null && make install &>/dev/null
chown -R nginx.nginx /apps/nginx
ln -s /apps/nginx/sbin/nginx /usr/sbin/ &>/dev/null
cat > /etc/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/apps/nginx/logs/nginx.pid
ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/bin/kill -s TERM \$MAINPID
LimitNOFILE=100000
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload &>/dev/null
systemctl enable --now nginx &>/dev/null
if [ $? -eq 0 ]
then
echo 'nginx启动成功'
exit
else
echo 'nginx启动失败'
fi
安装haproxy
#!/bin/bash
#注意目录需要在data下
lua () {
tar xf lua-5.4.4.tar.gz
cd lua-5.4.4
make all test
cd
ln -s /data/lua-5.4.4 /data/lua
}
ha () {
yum -y install gcc openssl-devel pcre-devel systemd-devel
cd /data
tar xf haproxy-2.2.11.tar.gz
cd haproxy-2.2.11/
make ARCH=x86_64 TARGET=linux-glibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_LUA=1 LUA_INC=/data/lua/src/ LUA_LIB=/data/lua/src/
make install PREFIX=/apps/haproxy
ln -s /apps/haproxy/sbin/haproxy /usr/sbin/
cat > /usr/lib/systemd/system/haproxy.service <<eof
[Unit]
Description=HAProxy Load Balancer
After=syslog.target network.target
[Service]
ExecStartPre=/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -c -q
ExecStart=/usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /var/lib/haproxy/haproxy.pid
ExecReload=/bin/kill -USR2 \$MAINPID
LimitNOFILE=100000
[Install]
WantedBy=multi-user.target
eof
mkdir /etc/haproxy
cat > /etc/haproxy/haproxy.cfg <<eof
global
maxconn 100000
chroot /apps/haproxy
stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
uid 99
gid 99
daemon
#nbproc 4
#cpu-map 1 0
#cpu-map 2 1
#cpu-map 3 2
#cpu-map 4 3
pidfile /var/lib/haproxy/haproxy.pid
log 127.0.0.1 local3 info
defaults
option http-keep-alive
option forwardfor
maxconn 100000
mode http
timeout connect 300000ms
timeout client 300000ms
timeout server 300000ms
listen stats
mode http
bind 0.0.0.0:9999
stats enable
log global
stats uri /haproxy-status
stats auth haadmin:123456
listen web_port
bind 0.0.0.0:8899
mode http
log global
server web1 127.0.0.1:8080 check inter 3000 fall 2 rise 5
eof
mkdir /var/lib/haproxy
useradd -r -s /sbin/nologin haproxy
systemctl enable --now haproxy
if systemctl status haproxy &>/dev/null
then
echo -e "\E[1;32m haproxy启动成功 \E[0m"
else
echo -e "\E[1;31m haproxy启动失败 \E[0m"
fi
}