美文网首页
第一章:公司业务统计SQL化

第一章:公司业务统计SQL化

作者: daniel_hao | 来源:发表于2015-08-04 20:39 被阅读51次

    说明

    对于运维来说,一份整理好的公司资料对工作的效率是事半功倍的,这里来说明利用关系型数据库来管理公司的业务文档。

    运维很多时候会把各个服务器,业务统计到excel中,分成好几个文件,当业务量提升,公司业务数据也在不断更新,而我们的excel会变的很多,很乱。在日常的维护中降低了工作效率。我们都是IT行业的人员,可以用更加专业的方式来管理:比如mysql!

    安装部署说明

    环境介绍

    首先,这些资料都是公司内部的资料,所以在搭建中一定要保证安全,这里我们将此主机搭建在公司内网环境中。

    找到一台主机,在主机上做好优化后,部署lnmp环境,这里我用的是最新稳定版本的nginx,mysql,php,具体安装文档在lnmp中查看,并做好各个服务的优化。平时管理数据库,我们可以用很多mysql的windows客户端来做,为了查看的可视化,我这里安装了phpmyadmin,通过web页面来查看,并将此主机ip解析到公司内网中,这样,公司中的工作人员就可以通过web来查看相应的资料了。

    安全

    为了保证公司数据的安全,这里的授权一定要授权好,这里我将用户和对应的库进行绑定设置,我创建了两个用户:一个为admin管理员用户,一个为xxx普通用户(root除外,因为在用一些mysql客户端管理中,不允许root连接)。同时创建了两个数据库:

    一个是admin库,一个是xxx库,admin用户授权all privileges on . to admin@,来进行整个的管理,此用户也是平时管理员管理用的用户。

    而另一个xxx库,授权则是all privileges on xxx.* to xxx@

    记得flush privileges;

    插入表

    表结构

    这里简单举例说明:分了三个表来说:

    第一个:admin

    CREATE DATABASE list;
    DROP TABLE IF EXISTS admin;
    CREATE TABLE admin(   
    id int unsigned not null auto_increment comment '主键',    
    pub_ip varchar(255) not null default '' comment '公网ip',   
    pri_ip varchar(255) not null default '' comment '私网ip',      
    user  varchar(255) not null default '' comment '用户', 
    passwd  varchar(255) not null default '' comment '密码', 
    notes varchar(255) not null default '' comment '备注',   
    primary key (id));
    

    第二个:business

    DROP TABLE IF EXISTS business;
    CREATE TABLE business(   
    id int unsigned not null auto_increment comment '主键',    
    pub_ip varchar(255) not null default '' comment '公网ip',   
    pri_ip varchar(255) not null default '' comment '私网ip',   
    domain varchar(255) not null default '' comment '域名',    
    domain_desc varchar(255) not null default '' comment '对应作用',
    biz varchar(255) not null default '' comment '标记',
    status varchar(255) not null default '' comment '状态',
    notes varchar(255) not null default '' comment '备注',   
    primary key (id));
    

    第三个:IP统计

    DROP TABLE IF EXISTS IP统计;
    CREATE TABLE IP统计(   
    id int unsigned not null auto_increment comment '主键',    
    pub_ip varchar(255) not null default '' comment '公网ip',   
    pri_ip varchar(255) not null default '' comment '私网ip',   
    gateway varchar(255) not null default '' comment '网关',   
    mask  varchar(255) not null default '' comment '掩码',   
    notes varchar(255) not null default '' comment '备注',   
    primary key (id));
    

    写入数据规范

    这样把登录,IP统计,业务统计分开,在日后的维护中也方便管理,这里我们可以通过sql语句批量添加,也可以通过SQLyog来进行管理添加。

    规范注意

    既然我们用了mysql来管理,看中的就是操作性和便捷搜索性,所以在日常的维护中要做到以下几点:
    1.业务变更数据准时同步到mysql中
    2.每天做好备份,因为占用空间很小,所以可以备份同步到自己电脑,一定要保证备份数据不会丢失。
    3.在每次更改数据前,记得做好数据的备份,防止误操作。
    4.在分配用户时,要注意管理好admin用户。

    相关文章

      网友评论

          本文标题:第一章:公司业务统计SQL化

          本文链接:https://www.haomeiwen.com/subject/gaivqttx.html