function networkAndFtp()
{
timeout
=
5
target
=
www.baidu.com
ret_code
=
`curl
-
I
-
s
-
-
connect
-
timeout $timeout $target
-
w
%
{http_code} | tail
-
n1`
if
[
"x$ret_code"
=
"x200"
]; then
echo
-
e
" 33[42;37m Network Check Complate!!! Continue 33[0m"
else
echo
-
e
"Network Error!!! Program has exit"
exit
1
fi
}
yum install ntpdate
-
y
echo
"01 0 * * * ntpdate time.pool.aliyun.com "
>
/
tmp
/
addcrontab.txt
crontab
/
tmp
/
addcrontab.txt
rm
-
rf
/
tmp
/
addcrontab.txt
systemctl stop firewalld.service
systemctl disable firewalld.service
function update_time()
{
shpath
=
/
apps
/
sh
if
[ !
-
d $shpath ];then
mkdir
-
p $shpath
fi
echo
"01 0 * * * ntpdate time.pool.aliyun.com"
>>
/
tmp
/
addcrontab.txt
crontab
/
tmp
/
addcrontab.txt
rm
-
rf
/
tmp
/
addcrontab.txt
cat >
/
apps
/
sh
/
update_time.sh<<
"EOF"
function networkcheck()
{
timeout
=
5
target
=
www.baidu.com
ret_code
=
`curl
-
I
-
s
-
-
connect
-
timeout $timeout $target
-
w
%
{http_code} | tail
-
n1`
if
[
"x$ret_code"
=
"x200"
]; then
echo
"Network check Pass"
else
echo
"Network Error exit....."
exit
1
fi
}
rpm
-
qa|grep ntpd &>
/
dev
/
null
ntppk
=
`echo $?`
if
[ $ntppk
-
eq
0
];then
logger restarting ntpd server.
/
bin
/
systemctl restart ntpd.service
else
networkcheck
yum install ntp
-
y &>
/
dev
/
null
stat
=
`echo $?`
if
[ ! $stat
-
eq
0
];then
echo
"ntpd install error."
exit
10
fi
/
bin
/
systemctl start ntpd.service
fi
EOF
}
networkAndFtp
echo
"Please enter Server name (hostname):"
read servername
echo
"Please enter servicename (localhost service code):"
read servicename
echo
"Please check hostname: $servername"
echo
"=================================="
echo
"Please check hostname: $servicename"
echo
"Countdown 5s!"
for
i
in
`seq
-
w
5
-
1
1
`
do
echo
"The countdown $i to start"
;
sleep
1
;
done
hostnamectl
-
-
static
set
-
hostname $servername
groupadd apps
adduser
-
g apps apps
yum install
-
y vim wget lrzsz iptables
-
services ntp net
-
tools psmisc unzip
/
usr
/
sbin
/
ntpdate time.pool.aliyun.com
wget
-
O
/
etc
/
yum.repos.d
/
epel.repo http:
/
/
mirrors.aliyun.com
/
repo
/
epel
-
7.repo
yum clean
all
wget
-
O
/
etc
/
sysctl.d
/
youhua.conf http:
/
/
121.201
.
24.30
:
8188
/
conf
/
youhua.conf
mv
/
etc
/
security
/
limits.conf
/
etc
/
security
/
limits.conf_`date
+
%
s`
echo
'* - nofile 65535'
>
/
etc
/
security
/
limits.conf
setenforce
0
wget
-
O
/
etc
/
selinux
/
config http:
/
/
121.201
.
24.30
:
8188
/
conf
/
selinux
/
config
mkdir
-
p
/
apps
/
svr
/
RouteIp
=
`route
-
n | awk
'{print $2}'
| awk
'NR ==3 '
`
if
[ $RouteIp
=
=
"10.0.20.27"
]
then
FileServerIp
=
"10.0.20.250"
else
FileServerIp
=
"10.0.5.250"
fi
wget
-
O
/
tmp
/
java.tar http:
/
/
$FileServerIp
/
apps
-
source
-
for
-
java.tar.gz
cd
/
tmp
/
;tar zxvf java.tar
chown
-
R apps.apps
/
tmp
/
apps
rm
-
rf
/
tmp
/
apps
/
svr
/
nginx
rm
-
rf
/
tmp
/
apps
/
svr
/
nginx
-
1.6
.
3
rm
-
rf
/
tmp
/
apps
/
svr
/
apache
-
tomcat
-
7.0
.
70
rm
-
rf
/
tmp
/
apps
/
sh
/
rotate
-
1.3
.sh
rm
-
rf
/
tmp
/
apps
/
sh
/
nginx.sh
if
[ $
1
=
=
"jdk18"
]
then
echo
-
e
" 33[42;37m Let's Install Java Development Kit Version 1.8 33[0m "
cp
-
r
/
tmp
/
apps
/
svr
/
apps
cp
-
r
/
tmp
/
apps
/
sh
/
apps
sleep
2
;
else
echo
-
e
" 33[42;37m I Think You Need Java Development Kit Version 1.7 33[0m "
rm
-
rf
/
tmp
/
apps
/
svr
/
jdk
cp
-
r
/
tmp
/
apps
/
svr
/
apps
cp
-
r
/
tmp
/
apps
/
sh
/
apps
cd
/
apps
/
svr
/
;ln
-
s
/
apps
/
svr
/
jdk1.
7.0_80
jdk
sleep
2
;
fi
echo
"source /apps/sh/java_env.sh"
>>
/
home
/
apps
/
.bashrc
function install_zabbix_agentd()
{
mkdir
-
p
/
apps
/
logs
/
zabbix
/
mkdir
-
p
/
apps
/
zabbix
/
etc
/
zabbix_agent.d
wget
-
O
/
apps
/
zabbix.tar.gz http:
/
/
121.201
.
24.30
:
8188
/
zabbix_centos7_64.tar.gz
tar xvf
/
apps
/
zabbix.tar.gz
-
C
/
apps
/
cp
/
apps
/
zabbix
/
sh
/
zabbix_agentd
/
etc
/
init.d
/
chmod
+
x
/
etc
/
init.d
/
zabbix_agentd
chkconfig
-
-
add zabbix_agentd
chkconfig
-
-
level
35
zabbix_agentd on
echo
'LogFile=/apps/logs/zabbix/zabbix_agentd.log'
>
/
apps
/
zabbix
/
etc
/
zabbix_agentd.conf
echo
'Server=10.0.5.30'
>>
/
apps
/
zabbix
/
etc
/
zabbix_agentd.conf
echo
'ServerActive=10.0.5.30'
>>
/
apps
/
zabbix
/
etc
/
zabbix_agentd.conf
echo
"Hostname=$servername"
>>
/
apps
/
zabbix
/
etc
/
zabbix_agentd.conf
echo
'AllowRoot=1'
>>
/
apps
/
zabbix
/
etc
/
zabbix_agentd.conf
echo
'Include=/apps/zabbix/etc/zabbix_agent.d/*.conf'
>>
/
apps
/
zabbix
/
etc
/
zabbix_agentd.conf
echo
'UserParameter=bd,/usr/bin/bash /apps/zabbix/sh/killall-check.sh'
>
/
apps
/
zabbix
/
etc
/
zabbix_agent.d
/
system.conf
service zabbix_agentd start
}
echo
"starting install_zabbix_agentd."
install_zabbix_agentd
yum update
-
y
echo
'ulimit -u 4096'
>>
/
home
/
apps
/
.bashrc
echo
'ulimit -u 4096'
>>
/
root
/
.bashrc
mkdir
-
p
/
apps
/
newcode
echo
-
e
" 33[42;37m done!!! Please reboot server! 33[0m"
sync
sync
sync
reboot