阿里云SLB不能负载到ECS的解决
1420 字
7 分钟
阿里云SLB不能负载到ECS的解决
新加的机器ECS,通过SLB居然负载不上去,网上百度了很多方法,甚至还求助了阿里云内部工作人员,无果.最后想到之前申请的机器都会执行一个脚本,修改一些配置.之后搜索了一些相关文章,发现了其中的问题.
对于添加到负载均衡实例后端的ECS,原则上不需要进行特别的配置。如果针对关联到负载均衡4层(TCP协议)服务的Linux系统的ECS,如果发现无法正常访问,需要确保系统配置文件/etc/sysctl.conf的以下三项为0
net.ipv4.conf.default.rp_filter = 0net.ipv4.conf.all.rp_filter = 0net.ipv4.conf.eth0.rp_filter = 0如果部署在同一内网网段下的ECS之间有通信需求,且发现有无法通信的情况存在,那么需要检查如下参数的配置是否正确
net.ipv4.conf.default.arp_announce =2net.ipv4.conf.all.arp_announce =2- 更新配置
sysctl -p-
脚本分享
Terminal window #######main#install toolsinstall_tools(){echo -e "\033[32m \037Begin install tools,please waiting........\033[0m"yum install -y setuptool vim wget ntp ftp telnet openssh-clients make dstat ncurses-devel gcc gcc-c++ make libtool lrzsz >/dev/null 2>&1if [ $? -eq 0 ];thenecho -e "\033[32m \037The tools install finshed...\033[0m"fi}selinux(){#being selinux configSELINUX_STATUS=`cat /etc/selinux/config |grep '^SELINUX\>' |cut -d "=" -f2`if [[ $SELINUX_STATUS == enforcing || $SELINUX_STATUS == permissive ]];thensed -i "s/SELINUX=$SELINUX_STATUS/SELINUX=disabled/g" /etc/selinux/configecho -e "Now selinux status is: \033[1;31m disable\033[0m."elseecho -e "No change.The selinux status is: \033[1;35m disable\033[0m."fi}Time(){#time zoneTIME_ZONE=`cat /etc/sysconfig/clock |grep '^ZONE' |cut -d "=" -f2`if [ $TIME_ZONE != \"Asia/Shanghai\" ];thencat > /etc/sysconfig/clock <<EOFZONE="Asia/Shanghai"UTC=falseARC=falseEOFTIME_ZONE=`cat /etc/sysconfig/clock |grep '^ZONE' |cut -d "=" -f2`echo -e "Now Time zone set success ,Zone now is: \"\033[1;31m$TIME_ZONE\033[0m\"."elseecho -e "No change.Time zone is: \"\033[1;35m$TIME_ZONE\033[0m\"."fi}##time synctime_sync(){time_dns='pool.ntp.org'/usr/sbin/ntpdate -s $time_dnsTIME=`date +%Y-%m-%d_%T`export LANG=Cif [ $? -eq 0 ];thenecho -e "Sync time success.Now the time is: \"\033[1;32m$TIME\033[0m\""fi#sync time for bioshwclock --systohc}ssh_port(){#change ssh login portDE_SH=`cat /etc/ssh/sshd_config |grep 'Port\>' |head -c1`DE_SH_PORT=`cat /etc/ssh/sshd_config |grep 'Port\>'`if [ $DE_SH == \# ];thensed -i s/"$DE_SH_PORT"/"Port 3322"/ /etc/ssh/sshd_configSSH_PORT=`cat /etc/ssh/sshd_config |grep 'Port\>' |awk '{print $2}'`if [ $SSH_PORT == 3322 ];thenecho -e "Now SSH port set success,port is: \"\033[1;31m$SSH_PORT\033[0m.\""fielseSSH_PORT=`cat /etc/ssh/sshd_config |grep 'Port\>' |awk '{print $2}'`if [ $SSH_PORT != 3322 ];thensed -i s/"Port $SSH_PORT"/"Port 3322"/ /etc/ssh/sshd_configecho -e "Now SSH port \"\033[1;31m$SSH_PORT\033[0m\" has change \"\033[1;31m63999\033[0m\"."elseecho -e "No change SSH port is: \"\033[1;35m63999\033[0m\""fifi}ssh_root(){#delay root loginDEF_PER=`cat /etc/ssh/sshd_config |grep 'PermitRootLogin' |grep -v 'without-password' |head -c 1`DEF_PER_CON=`cat /etc/ssh/sshd_config |grep 'PermitRootLogin' |grep -v 'without-password'`if [ $DEF_PER == \# ];thensed -i s/"$DEF_PER_CON"/"PermitRootLogin no"/ /etc/ssh/sshd_configDEF_PER_CON1=`cat /etc/ssh/sshd_config |grep 'PermitRootLogin' |grep -v 'without-password'`echo -e "Now Root login permit set success.Now is: \"\033[1;31m$DEF_PER_CON1\033[0m\" ."elseLOGIN_PER=`cat /etc/ssh/sshd_config |grep 'PermitRootLogin' |grep -v 'without-password' |cut -d" " -f2`if [ $LOGIN_PER == yes ];thensed -i s/"PermitRootLogin yes"/"PermitRootLogin no"/ /etc/ssh/sshd_configDEF_PER_CON2=`cat /etc/ssh/sshd_config |grep 'PermitRootLogin' |grep -v 'without-password'`echo -e "Now The permit is: \"\033[1;31m$DEF_PER_CON2\033[0m\" ."elseecho -e "No change.The root login permit is: \"\033[1;35m no\033[0m\"."fifi}ssh_zip(){#open ssh zipDEF_ZIP=`cat /etc/ssh/sshd_config |grep Compression |head -c 1`ZIP_STAT=`cat /etc/ssh/sshd_config |grep 'Compression'`if [ $DEF_ZIP == \# ];thensed -i s/"$ZIP_STAT"/"Compression yes"/ /etc/ssh/sshd_configZIP_STAT=`cat /etc/ssh/sshd_config |grep 'Compression'`echo -e "Open zip for scp success.status is: \"\033[1;31m$ZIP_STAT\033[0m.\""elseZIP_STATUS=`cat /etc/ssh/sshd_config |grep 'Compression' |awk '{print $2}'`if [ $ZIP_STATUS != yes ];thensed -i s/"Compression $ZIP_STATUS"/"Compression yes"/ /etc/ssh/sshd_configecho -e "Scp zip status: \"\033[1;31m$ZIP_STATUS\033[0m\" has change \"\033[1;31myes\033[0m\"."elseecho -e "No change scp commpression status: \"\033[1;35myes\033[0m\""fifi}ssh_dns(){#close dns for ssh conDEF_DNS=`cat /etc/ssh/sshd_config |grep 'UseDNS' |head -c 1`DNS_STAT=`cat /etc/ssh/sshd_config |grep 'UseDNS'`if [ $DEF_DNS == \# ];thensed -i s/"$DNS_STAT"/"UseDNS no"/ /etc/ssh/sshd_configDNS_STAT=`cat /etc/ssh/sshd_config |grep 'UseDNS'`echo -e "Close dns for ssh.status is: \"\033[1;31m$DNS_STAT\033[0m.\""elseDNS_STATUS=`cat /etc/ssh/sshd_config |grep 'UseDNS' |awk '{print $2}'`if [ $ZIP_STATUS != no ];thensed -i s/"Compression $ZIP_STATUS"/"Compression no"/ /etc/ssh/sshd_configecho -e "DNS status: \"\033[1;31m$DNS_STATUS\033[0m\" has change \"\033[1;31mno\033[0m\"."elseecho -e "No change UseDNS status: \"\033[1;35mno\033[0m\""fifi}ssh_startup(){#max startSTART_MAX=`cat /etc/ssh/sshd_config |grep MaxStartups |head -c 1`MAX_STAT=`cat /etc/ssh/sshd_config |grep MaxStartups`if [ $DEF_DNS == \# ];thensed -i s/"$MAX_STAT"/"MaxStartups 5"/ /etc/ssh/sshd_configMAX_STAT=`cat /etc/ssh/sshd_config |grep MaxStartups`echo -e "The max startups status is : \"\033[1;31m$MAX_STAT\033[0m.\""fi}ssh_emptypasswd(){#refuse empty passwd loginDEF_EMPTY=`cat /etc/ssh/sshd_config |grep PermitEmptyPasswords |head -c 1`EMPTY_STAT=`cat /etc/ssh/sshd_config |grep PermitEmptyPasswords`if [ $DEF_EMPTY == \# ];thensed -i s/"$EMPTY_STAT"/"PermitEmptyPasswords no"/ /etc/ssh/sshd_configEMPTY_STAT=`cat /etc/ssh/sshd_config |grep PermitEmptyPasswords`echo -e "PermitEmptyPasswords status is: \"\033[1;31m$EMPTY_STAT\033[0m.\""elseEMPTY_STATUS=`cat /etc/ssh/sshd_config |grep 'PermitEmptyPasswords' |awk '{print $2}'`if [ $EMPTY_STATUS != no ];thensed -i s/"PermitEmptyPasswords $EMPTY"/"PermitEmptyPasswords no"/ /etc/ssh/sshd_configecho -e "PermitEmptyPasswords status: \"\033[1;31m$EMPTY_STATUS\033[0m\" has change \"\033[1;31mno\033[0m\"."elseecho -e "No change PermitEmptyPasswords status: \"\033[1;35mno\033[0m\""fifi}ssh_restart(){echo -e "\033[1;32m Begin restart sshd process....\033[0m"systemctl restart sshd.service >/dev/nullif [ $? -eq 0 ];thenecho -e "\033[1;31m sshd_config set success. \033[0m"fi}set_user(){#beging set userNAME_COU=`cat /etc/passwd |grep '^test\>' |wc -l`if [ $NAME_COU -eq 1 ];thenecho 'test123' | passwd --stdin "test" > /dev/nullecho -e "No change . The user name \"\033[1;35m test\033[0m \" exist,passwd has set again. please check out."elseuseradd testecho 'test123' | passwd --stdin "test" > /dev/nullecho -e "Now Create username \"\033[1;31m test \033[0m\" && set passwd success."fi#set root passwdecho 'testroot' | passwd --stdin "root" > /dev/nullecho -e "Now \033[1;31m Root\033[0m passwd set success.."}profile_hist(){#begin set add time format for historyPRO_COUNT=`cat /etc/profile |grep 'HISTTIMEFORMAT' |wc -l`if [ $PRO_COUNT -eq 0 ];then/bin/sed -i "/^export PATH/a\export HISTTIMEFORMAT" /etc/profile/bin/sed -i "/^HISTSIZE/a\HISTTIMEFORMAT=\"%Y-%m-%d %H:%M:%S: \"" /etc/profileexport HISTTIMEFORMATecho -e "Now The\033[1;31m history timeformat\033[0m set success now."elseecho -e "No change.The\033[1;35m history timeformat\033[0m has setted ."fi}profile_other(){echo "TMOUT=1800" >> /etc/profileecho "alias vi='vim'" >>/etc/profileecho "unset MAILCHECK" >> /etc/profilesource /etc/profile}run_level(){#begin set runlevelRUNLEVEL=`cat /etc/inittab |grep '^id:.:initdefaul' |cut -d":" -f2`if [ $RUNLEVEL != 3 ];then/bin/sed -i s/"id:$RUNLEVEL"/"id:3"/ /etc/inittabNOW_RUNLEVEL=`cat /etc/inittab |grep '^id:.:initdefaul' |cut -d":" -f2`echo -e "Now the runlevel is \"\033[1;31m$NOW_RUNLEVEL\033[0m\"."elseecho -e "No change .The runlevel is \"\033[1;35m$RUNLEVEL\033[0m\"."fi}iptables(){##begin set iptables start levlesystemctl disable firewalld.service > /dev/nullecho -e "Now default \033[1;31m iptables\033[0m start runlevel all set off "systemctl stop firewalld.service > /dev/null}unnecessary_service(){#begin turn off unnecessary servicesexport LANG=Cecho -e "\e[32m begin turn off unnecessary services.....\e[0m"for close_list in `chkconfig --list |awk '($5~/on/ || $7~/on/) {print $1}' | grep -vE "atd|crond|cpuspeed|irqbalance|lvm2-monitor|network|smartd|sshd|syslog|sysstat"`doecho $close_list/sbin/chkconfig --level 2345 $close_list off/sbin/service $close_list stop >/dev/nulldoneecho -e "Now The \033[1;31m unnecessary services \033[0m turn off now."#echo -e "\e[32m----------------End system initialization ---------------\e[0m"}##set sysctl.confsysctl_set(){cat >> /etc/sysctl.conf <<EOF###################################################vm.overcommit_memory = 1###################################################net.netfilter.nf_conntrack_max=1000000###################################################net.core.rmem_default = 126976net.core.wmem_default = 126976net.core.wmem_max = 16777216net.core.rmem_max = 16777216net.ipv4.tcp_mem = 8192 87380 16777216net.ipv4.tcp_wmem = 8192 65536 16777216net.ipv4.tcp_rmem = 8192 87380 16777216###################################################net.core.netdev_max_backlog = 2500net.core.somaxconn = 100000###################################################net.ipv4.tcp_no_metrics_save = 0net.ipv4.tcp_moderate_rcvbuf = 1net.ipv4.tcp_orphan_retries= 1net.ipv4.tcp_fin_timeout = 5net.ipv4.tcp_keepalive_time = 300net.ipv4.tcp_syncookies = 1net.ipv4.tcp_sack = 1net.ipv4.tcp_tw_reuse = 1net.ipv4.tcp_tw_recycle = 1net.ipv4.ip_local_port_range = 10250 65000net.ipv4.tcp_max_syn_backlog = 81920net.ipv4.tcp_max_tw_buckets = 1600000net.ipv4.tcp_synack_retries = 2net.ipv4.tcp_syn_retries = 2net.ipv4.tcp_retries2 = 2net.ipv4.tcp_window_scaling = 1net.ipv4.tcp_timestamps = 1###################################################fs.file-max = 1024000EOFsysctl -p >/dev/null 2>1&}#limit filelimit_file(){cat >> /etc/security/limits.conf <<EOF* hard nofile 1024000* soft nofile 1024000* hard nproc 1024000* soft nproc 1024000EOF}sudu_log(){touch /var/log/sudo.logcat >> /etc/sudoers <<EOFLocoJoyUser ALL=(ALL) NOPASSWD: /bin/shDefaults logfile=/var/log/sudo.logEOFcat >> /etc/rsyslog.conf <<EOFlocal8.debug /var/log/sudo.logEOF}echo -e "\e[32m----------------Begin system initialization ---------------\e[0m"echoinstall_toolsselinux#Timetime_syncssh_portssh_rootssh_zipssh_dnsssh_startupssh_emptypasswdssh_restartset_userprofile_histprofile_other#run_leveliptables#unnecessary_servicesysctl_setlimit_filesudu_logechoecho -e "\e[32m----------------End system initialization ---------------\e[0m"
文章分享
如果这篇文章对你有帮助,欢迎分享给更多人!
相关文章智能推荐
1
阿里云ECS云盘在线扩容(Linux系统)
其他阿里云在线文档
2
您尚未安装任何 GPG 公钥出现rpm --import public.gpg.key,解决办法
其他2026-01-05
3
无法加载文件 xxx 因为在此系统上禁止运行脚本
其他2026-01-05
4
事务的传播行为
其他事务传播行为用来描述由某一个事务传播行为修饰的方法被嵌套进另一个方法的时事务如何传播。
5
spring-plugin异常的解决办法
其他在学习ES的过程中,本着有最新就用最新的想法,使用了springboot2.3.x的版本,在实操过程中遇到了配置和方法过时的情况,于是将springboot版本降级为2.1.13,诡异的事情发生了,原本能正常启动的项目起不来了,报错如下:
随机文章随机推荐


