又犯了一个错误,MySQL的,
lower_case_table_names=1这个参数一定要在安装完mysql后改为1.不然,以后有肯能会出现,
Error was: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Duplicate column name 'groupl
参考 shell自动收集服务器硬件系统信息通过web页面显示
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
有几个地方要注意一下
1.php
php 500
yum -y
install
php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
php.ini
修改php.ini配置文件,error_reporting = E_ALL & ~E_NOTICE
在php.ini中设置
date
.timezone的值为PRC,设置好以后的为:
date
.timezone=PRC
2.mysql
1)mysql不要使用root
2)如果通过ansible执行的话,客户端没有安装mysql客户端,需要安装
yum -y
install
mysql,还需要覆盖my.cnf
cat
/etc/my
.cnf
[mysqld]
datadir=
/var/lib/mysql
socket=
/var/lib/mysql/mysql
.sock
user=mysql
lower_case_table_names=1
default-character-
set
= utf8
character_set_server = utf8
default-storage-engine=InnoDB
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
max_allowed_packet=100M
[mysqld_safe]
log-error=
/var/log/mysqld
.log
pid-
file
=
/var/run/mysqld/mysqld
.pid
主要是字符集的问题
3)如果是编译安装mysql,那么用
which
mysql
3.建立数据库
CREATE TABLE `systeminfo` (
`
id
` int(11) NOT NULL AUTO_INCREMENT,
`ip_info` varchar(50) NOT NULL,
`cpu_info` varchar(50) NOT NULL,
`disk_info` varchar(50) NOT NULL,
`mem_info` varchar(50) NOT NULL,
`service_info` varchar(200) NOT NULL,
PRIMARY KEY (`
id
`),
UNIQUE KEY `ip_info` (`ip_info`),
UNIQUE KEY `ip_info_2` (`ip_info`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
4.修改过后的脚本
cat
systeminfo.sh
#!/bin/bash
#auto get system info
echo
-e
"\033[34m\033[1m"
cat
<<EOF
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++Welcome to use system Coolect++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
EOF
ip_info=`
ifconfig
|
awk
'/inet addr/ {gsub(/:/," ");print $3}'
|
grep
-
v
127.0.0.1`
cpu_info1=`
cat
/proc/cpuinfo
|
grep
"model name"
|
awk
-F:
'{print $2}'
|
sed
's/^//g'
|
awk
'{print $1,$3,$4,$NF}'
`
cpu_info2=`
cat
/proc/cpuinfo
|
grep
"physical id"
|
sort
|
uniq
-c|
wc
-l`
cpu_info3=`
grep
processor
/proc/cpuinfo
|
wc
-l`
serv_info=`
hostname
|
tail
-1`
disk_xinfo=`
fdisk
-l|
grep
"Disk"
|
grep
-
v
"identifier"
|
awk
'{print $2,$3,$4}'
|
sed
's/,//g'
`
disk_info=`
fdisk
-l|
grep
"Disk"
|
grep
-
v
"identifier"
|
awk
'{print $2,$3,$4}'
|
sed
's/,//g'
|
grep
-
v
mapper|
awk
-F
' '
'{print $2}'
|
awk
'{sum += $1} END {print sum}'
`
mem_info=`
free
-m|
awk
'/Mem/ {printf ("%.f\n",$2/1024)}'
`
services=(nginx gitlab ntpd tomcat mysql ldap nexus)
for
var
in
${services[@]}
do
num=`
ps
-ef|
grep
$var|
grep
-
v
grep
|
wc
-l`
if
[ $num -gt 1 ];
then
service_info=${var}
" "
${service_info}
fi
done
echo
-e
"\033[32m-------------------------------------\033[1m"
echo
IPADDR:${ip_info}
echo
HOSTNAME:$serv_info
echo
CPU_INFO:${cpu_info1}X${cpu_info2}
echo
Disk_INFO:$disk_info
echo
MEM_INFO:$mem_info
echo
service_info:$service_info
#echo -e -n "\033[36m You want to write the data to the databases?\033[1m";read ensure
#if [ "$ensure" == "yes" -o "$ensure" == "y" -o "$ensure" == "Y" ];then
echo
"------------------------"
result=`
which
mysql`
if
[ $? -
ne
0 ];
then
yum -y
install
mysql
result=`
which
mysql`
fi
$result -uxx -pxx -h xx -D xx -e
"insert into systeminfo values('','${ip_info}','${cpu_info3}"
核
"','$disk_info"
G
"','$mem_info"
G
"','$service_info');"
#else
if
[ $? -
ne
0 ];
then
echo
"what exit"
exit
1
fi
5.通过ansible调用hosts分组执行
ansible xx -m script -a
'systeminfo.sh'
6.php环境搭建
php环境用yum搭建,比如yum -y
install
php php-fpm,启动
/etc/init
.d
/php-fpm
nginx配置文件
server {
listen 80;
server_name xx;
access_log
/opt/log/check
.log;
error_log
/opt/log/check
.error;
root
/opt/check
;
location / {
index index.php index.html index.htm;
allow xx
/24
;
deny all;
}
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
expires 30d;
}
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht {
deny all;
}
}
7.php页面显示
<html>
<
head
>
<title>服务器管理统计<
/title
>
<
/head
>
<body>
<?php
$con = mysql_connect(
"xx"
,
"xx"
,
"xx"
);
if
(!$con)
{
die(
'数据库连接失败: '
. mysql_error());
}
else
{
mysql_query(
"SET NAMES UTF8"
);
mysql_query(
"set character_set_client=utf8"
);
mysql_query(
"set character_set_results=utf8"
);
mysql_select_db(
"xx"
, $con);
$result = mysql_query(
"SELECT * FROM systeminfo inet_aton(ip_info)"
);
//
在表格中输出显示结果
echo
"<table border=
'1'
>
<
tr
>
<th>主机IP<
/th
>
<th>主机名<
/th
>
<th>cup型号<
/th
>
<th>磁盘<
/th
>
<th>内存<
/th
>
<th>负载<
/th
>
<th>机房<
/th
>
<
/tr
>";
while
($row = mysql_fetch_array($result))
{
echo
"<tr>"
;
echo
"<td>"
. $row[
'ip_info'
] .
"</td>"
;
echo
"<td>"
. $row[
'serv_info'
] .
"</td>"
;
echo
"<td>"
. $row[
'cpu_info'
] .
"</td>"
;
echo
"<td>"
. $row[
'disk_info'
] .
"</td>"
;
echo
"<td>"
. $row[
'mem_info'
] .
"</td>"
;
echo
"<td>"
. $row[
'load_info'
] .
"</td>"
;
echo
"<td>"
. $row[
'mark_info'
] .
"</td>"
;
echo
"</tr>"
;
}
echo
"</table>"
;
}
mysql_close($con);
?>
<
/body
>
|
本文转自 liqius 51CTO博客,原文链接:http://blog.51cto.com/szgb17/1783476,如需转载请自行联系原作者