#Creating some default dirctoris==========================================Begin
#mkdir -p /data/upgrade_install/
#mkdir -p /data/tools/
#mkdir -p /data/bak/
#mkdir -p /data/webapps/
#mkdir -p /data/logs/


yum install -y net-snmp iptraf vnstat ipmitool OpenIPMI nmap telnet yum-plugin-downloadonly systemtap psacct iftop jwhois bind-utils crontabs lua-devel openssl-devel pcre-devel zlib-devel dmidecode pciutils
yum groupinstall -y "Development Tools"
#Install Packages=========================================================End


# SNMP setting============================================================Begin
/bin/cat > /etc/snmp/snmpd.conf << "EOF"
###############################################################################
com2sec notConfigUser  1.1.1.1/32      public
com2sec notConfigUser  2.2.2.2/32     public
group   notConfigGroup v2c                notConfigUser
access  notConfigGroup ""       any       noauth    exact  all none none
view all    included  .1                               80
###############################################################################
EOF

/sbin/chkconfig snmpd on
/etc/init.d/snmpd start
# SNMP setting============================================================End

# Initting SSH Service and Installing SSH Key ============================Begin
cd /root/
#mkdir -p .ssh

cd /root/
if [ ! -d "/root/.ssh" ]; then
    mkdir -p "/root/.ssh"
fi


cat >>/root/.ssh/authorized_keys <<"EOF"
ssh-rsa [payload removed: 372 characters] root@NW-Monitor
EOF

chmod 700 /root/.ssh/
chmod 600 /root/.ssh/authorized_keys

sed -i -e 's/#RSAAuthentication\ yes/RSAAuthentication\ yes/' /etc/ssh/sshd_config
sed -i -e 's/#PubkeyAuthentication\ yes/PubkeyAuthentication\ yes/' /etc/ssh/sshd_config
sed -i -e 's/#AuthorizedKeysFile/AuthorizedKeysFile/' /etc/ssh/sshd_config
sed -i -e 's/#UseDNS\ yes/UseDNS\ no/' /etc/ssh/sshd_config
sed -i -e '/X11Forwarding yes/s/yes/no/' /etc/ssh/sshd_config

service sshd restart
# Initting SSH Service and Installing SSH Key ============================End




#Disable selinux==========================================================Begin
sed -i -e '/SELINUX=enforcing/s/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
sed -i -e '/SELINUX=enforcing/s/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0
#Disable selinux==========================================================End


# Disable Needless Services===============================================Begin
/sbin/chkconfig --level 0123456 acpid off
/sbin/chkconfig --level 0123456 auditd off
/sbin/chkconfig --level 0123456 ip6tables off
/sbin/chkconfig --level 0123456 iptables off
/sbin/chkconfig --level 0123456 kdump off
/sbin/chkconfig --level 0123456 lvm2-monitor off
/sbin/chkconfig --level 0123456 mdmonitor off
/sbin/chkconfig --level 0123456 postfix off
/sbin/chkconfig --level 0123456 restorecond off
/sbin/chkconfig --level 0123456 udev-post off
/sbin/chkconfig --level 0123456 psacct on
/sbin/chkconfig --level 0123456 ntpd off
/etc/init.d/iptables stop
# Disable Needless Services===============================================End

# Sync date===============================================================Begin
cat >> /var/spool/cron/root << "EOF"
*/30 * * * * /usr/sbin/ntpdate ntp.whaley.cn > /dev/null 2>&1
EOF

cat >> /etc/hosts << "EOF"
123.59.83.58   ntp.whaley.cn
EOF

# Display Command excute time=============================================Begin
cat >> /etc/bashrc<< "EOF"
export HISTTIMEFORMAT='%Y-%m-%d %H:%M:%S '
EOF
# Display Command excute time=============================================End


# file notification setting===============================================Begin
cat >> /etc/security/limits.conf << "EOF"
*    -     nofile    1000000
EOF

cat >> /etc/security/limits.d/90-nproc.conf << "EOF"
*    soft     nproc    65535
EOF
# file notification setting===============================================End


# Kernel setting==========================================================Begin
cat > /etc/sysctl.conf << "EOF"
# Kernel sysctl configuration file for Red Hat Linux
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 1025 65000
net.ipv4.tcp_max_syn_backlog = 20480
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_max_tw_buckets = 300000
net.ipv4.tcp_timestamps = 0
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.wmem_max = 16777216
net.core.rmem_max = 16777216
net.ipv4.tcp_rmem = 10240 87380 16777216
net.ipv4.tcp_wmem = 10240 87380 16777216
net.core.netdev_max_backlog = 50000
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.tcp_max_orphans = 3276800
net.core.somaxconn = 3276800
vm.swappiness = 10
fs.file-max = 1000000
fs.inotify.max_user_watches = 10000000
EOF
# Kernel setting==========================================================End
sysctl -p /etc/sysctl.conf

#disable ctrl alt del=====================================================Begin
sed -i -e '/exec/s/exec/#exec/' /etc/init/control-alt-delete.conf
#disable ctrl alt del=====================================================End

#Creating some default dirctoris==========================================End


#Changing cron job of sysstat=============================================Begin
#sed -i '/*\/10/s/*\/10/*/' /etc/cron.d/sysstat
#Changing cron job of sysstat=============================================End


#Changing search domain===================================================Begin
#sed -i -e '/localhost.localdomain/s/localdomain/idc.moretv.com.cn/' /etc/sysconfig/network

#Changing search domain===================================================End


#Disable IPv6=============================================================Begin
sed -i -e '/NETWORKING=yes/aNETWORKING_IPV6=no' /etc/sysconfig/network
sed -i -e '/NETWORKING=yes/aIPV6INIT=no' /etc/sysconfig/network

cat > /etc/modprobe.d/disable_ipv6.conf << "EOF"
install ipv6 /bin/true
EOF
#Disable IPv6=============================================================End


#Change log.

#Install puppet===========================================================End
#yum install -y puppet
#echo '10.10.96.33 moretv-puppet01' >> /etc/hosts
#echo '    server = moretv-puppet01' >> /etc/puppet/puppet.conf
#puppet agent -t


#Install puppet===========================================================END
#if [ `ping monitor.whaley.cn -c 1 -w 1 | grep 100%  | wc -l` -ge 1 ];then
#wget "http://10.10.114.116/whaley_tools/zabbix_agent_whaley.tar.gz"
#else
#wget "http://monitor.whaley.cn/whaley_tools/zabbix_agent_whaley.tar.gz"
#fi

#tar zxf zabbix_agent_whaley.tar.gz

#cd zabbix_agent
#rpm -ihv zabbix-agent-2.4.6-1.el6.x86_64.rpm --nodeps --force > /dev/null 2>&1
#sleep 3

#if [ `id zabbix | wc -l` -lt 1 ];then
#useradd zabbix -s /sbin/nologin
#fi

#mv -f zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf
#cp -r scripts/ /etc/zabbix/
#mv -f .my.cnf /etc/zabbix/
#mv -f userparameter_mysql.conf /etc/zabbix/zabbix_agentd.d/

#chmod -R u+x /etc/zabbix/scripts/

#if [ ! -d /var/log/zabbix ];then
#        mkdir -p /var/log/zabbix
#        chown -R zabbix.zabbix /var/log/zabbix/
#fi

#if [ ! -d /var/run/zabbix ];then
#        mkdir -p /var/run/zabbix
#        chown -R zabbix.zabbix /var/run/zabbix/
#fi

#ps -ef | grep zabbix_agentd | grep -v grep | while read u p o
#do
#kill -9 $p
#done

#sleep 3

#/etc/init.d/zabbix-agent start

#RESULT=`ps -ef | grep -w zabbix_agentd.conf | grep -v grep | wc -l`

#if [ $RESULT -ge 1 ];then
#        echo "zabbix_agent installed"
#        rm -rf zabbix_agent
#else
#        /etc/init.d/zabbix-agent restart
#fi

#chkconfig zabbix-agent on

yum install -y nc > /dev/null 2>&1

#install agent===================================Begin

yum install unzip -y
mkdir -p /root/tools/
cd /root/tools/
wget http://123.59.77.3/whaley_tools/agent_neiwang_install_linux.zip
#wget http://10.10.114.116/whaley_tools/agent_debug_install.zip
#unzip agent_debug_install.zip
unzip agent_neiwang_install_linux.zip
#cd agent_debug
mv agent_neiwang agent
cd agent
./agent install

/etc/init.d/agent start

sleep 10

/etc/init.d/agent restart
#install agent====================================End






