0%

什么?谁?w (who & what)

.. code::
去年花里逢君别,今日花开已一年。
韦应物《寄李儋元锡》

w可以认为是加强版的who,果然越简洁越强大,就比如lessmore是功能更多的。

w不仅可以显示谁在登录,还可以打印他们在做什么。w显示的信息如下:

  • 登录的用户;
  • 运行的程序;
  • 第一行显示的信息:当前时间、系统运行的时间、多少用户登录、系统的负载(分贝为1,5,15分钟)

官方定义为:

w - Show who is logged on and what they are doing.

用法为:

1
$ w [options] user [...]

常用的两个选项为:

  • -h  不显示各栏位的标题信息列。

  • -s  简洁格式列表,不显示用户登入时间,JCPU或者PCPU的时间

默认的显示

显示当前用户的登录信息及执行的命令

1
2
3
4
5
6
7
8
9
$ w
16:29:03 up 26 days, 2:49, 6 users, load average: 1.00, 0.97, 0.96
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
user pts/4 :1 07Sep21 20days 9:59 1:53m bash
user pts/0 :2 08Sep21 6days 0.70s 1:53m zsh
user pts/1 :3 08Sep21 20days 1:13m 1:53m bash
user :0 :0 15Sep21 6days 27days 21.36s zsh
user pts/2 :0 15Sep21 14days 0.25s 0.25s zsh
user pts/3 :3 16Sep21 24:45m 0.22s 0.22s bash

不显示标题行

1
2
3
4
5
6
7
8
9
$ w -h
16:29:16 up 26 days, 2:49, 6 users, load average: 1.20, 0.67, 0.76
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
user pts/4 :1 07Sep21 20days 9:59 1:53m bash
user pts/0 :2 08Sep21 6days 0.70s 1:53m zsh
user pts/1 :3 08Sep21 20days 1:13m 1:53m bash
user :0 :0 15Sep21 6days 27days 21.36s zsh
user pts/2 :0 15Sep21 14days 0.25s 0.25s zsh
user pts/3 :3 16Sep21 24:45m 0.22s 0.22s bash

简洁模式显示

1
2
3
4
5
6
7
8
9
$ w -s
16:29:26 up 26 days, 2:49, 6 users, load average: 1.50, 0.67, 0.36
USER TTY FROM IDLE WHAT
user pts/4 :1 20days bash
user pts/0 :2 6days zsh
user pts/1 :3 20days bash
user :0 :0 6days zsh
user pts/2 :0 14days zsh
user pts/3 :3 24:45m bash

聊聊版本控制

Git是一款分布式版本控制系统,有别于CVS和SVN等集中式版本控制系统,Git可以让研发团队更加高效地协同工作,从而提高生产率。

有很长一段时间Linus只使用diff、patch和tar包来管理Linux的代码。

大家平时在安装软件包的时候会发现软件包的名字后面有-svn,-git等等字眼。。到底有什么区别呢?看下面~~~

  1. RCS(Revision Control System) 修订控制系统,特点:
  2. 简单
  3. 使用Lock机制防止多个开发人员对同一个文件同时进行修改.
  4. CVS(Cocurrent Version System)并发版本系统,建立在RCS基础上,最流行的开放源代码版本控制系统,特点:
  5. 使用单一的主代码树,而不像RCS那样依赖多个目录.
  6. 最大优点在于多名开发人员可以同时对一个文件进行修改.允许合并.这就“并发“开发.
  7. SVN(SubVersion)
  8. 目录的版本控制,CVS 只能对文件进行版本控制,不能对目录进行版本控制.CVS 只能注意到,一个文件在一个位置被删除了,而在一个新位置创建了另外一个文件。由于它不会连接两个操作,因此也很容易使文件历史轨迹丢失,SVN可以
  9. 原子性提交,CVS 采用线性、串行的批量提交,即依次地,一个接一个地执行提交,每成功提交一个文件,该文件的一个新的版本即被记录到版本库中,提交时用户提供的日志信息被重复地存储到每一个被修改的文件的版本历史中。CVS 串行批量提交模式的弊端在于 -当任何原因造成批量操作的中断时(典型原因包括:网络中断、客户端死机等),版本库往往处于一个不一致的状态:原本应该全部入库的文件只有一部分入库,很有可能版本库中的最新版本不能顺利编译,更为严重的是,随着其他的用户执行cvs update 操作,该不一致性将迅速在开发团队中扩散,从而严重影响团队的开发效率,并存在质量隐患。另外,假如该批量提交的中断没有被及时发现,开发团队往往要花更多的时间进行软件调试和排错。
  10. Git, Git 是用于 Linux 内核开发的版本控制工具。与常用的版本控制工具 CVS, Subversion 等不同,它采用了分布式版本库的方式,不必服务器端软件支持,使源代码的发布和交流极其方便。 Git 的速度很快,这对于诸如 Linux kernel 这样的大项目来说自然很重要。 Git 最为出色的是它的合并跟踪(merge tracing)能力。git更加适合分布式开发项目。而svn(当然全称是subversion)则更适合于集中式大型开发项目。也有在git之上再使用一层svn的做法。

几个版本控制

  • 本地版本控制:这个可能是大多数人使用的方式,不同的名字或者时间信息等,但很容易混淆文件
  • 集中化版本控制:有个单一的集中管理的服务器,保持所有文件的修改版本,容易管理,但万一服务器宕机,风险就超级大了
  • 分布式版本控制:多地克隆备份

总结

CVS,Git,Mercurial,Subversion比较

特征 CVS Git Mercurial Subversion
是否原子提交 没有 是的
文件和目录是否可以移动或重命名 CVS: 不是. 重命名不支持. 如果手动进行, 可能会损坏历史记录 Git: 支持重命名, 这是很实用的目的. git甚至能检测到重命名之后文件的改变. 尽管如此, 基于特殊的存储结构, 重命名不会被显示的记录, git能够推导出来(在实际使用中很容易做到) 是的, 重命名是支持的 是的. 支持重命名
在移动或重命名之后智能合并 CVS: 不能. 重命名都不支持, 就不必说智能了 Git: 不支持. Mercurial: 是的. 重命名之后智能合并是支持的. 不支持.
文件和目录拷贝 不能 不能 支持拷贝 拷贝非常容易(O(1)). 包括产生分支
远程存储仓库的备份 间接的. git的内部特征 是的 间接的.
是否传递变更到父仓库 CVS: 不会 是的 是的 是的,
仓库权限 CVS: 很有限. Mercutial: 是的. Subversion: 是的.
变更集 CVS: 不是. 变更是基于文件的 Git: 是的. 是支持的, 创建他们很容易 Mercurial: 是的. 变更集是支持的 Subversion: 部分支持. 对于一次提交会隐式创建一个变更集
跟踪线性的文件历史 CVS: 是的. cvs annotate Git: 是的.(git blame) Mercurial: 是的(hg annotate) Subversion: 是的(svn blame)
能够只在仓库的单目录下作用 CVS: 是的 Git: 不是. 尽管如此, 提交多少能被限制 Mercurial: 能够基于某树的某个子集进行提交. 也有局部检出的能力 Subversion: 是的
跟踪未提交的变化 CVS: 是的. 通过cvs diff Git: 是的. Mercurial: 是的. 使用hg diff Subversion: 是的. 使用svn diff
基于单个文件的提交信息 CVS: 不是. 提交信息是基于单次变化的 Git: 是的. 提交信息基于变更集 Mercurial: 不是 Subversion: 不是. 没有这个特征
文档 CVS: 非常棒. 有很多在线的tutorials和资源, 在线的书籍. Git: 良好. 短的帮助比较简洁难懂. Mercurial: 很好. 有基于公司的书籍和wiki. 每个命令都集成了帮助 Subversion: 很好. 有一些在线的书籍和一些在线的tutorials和资源. 并且书籍是以docbook/xml写的
配置是否轻松 CVS: 好. 是个事实上的标准. 基于每个系统都有并且很容易配置 Git: 好. 在现有平台上二进制可用. 需要C编译器和Perl. 在windows上需要cygwin. 并有一些Unix特征 Mercurial: 非常好. 几乎所有平台都有二进制包. 从源码编译需要python2.3以上, 并且需要C编译器 有些复杂
命令集 CVS: 包含了3个经常用到的命令的简单的命令集(cvs commit, cvs update和cvs checkout)和其它一些 Git: 命令集很丰富, 并且和CVS不兼容 Mercurial: 尝试模仿CVS交互方式, 但是偏离了基于不同的设计的意图 Subversion: 类CVS的命令集, 能够很容易被CVS用户使用
网络支持 CVS: 好. cvs在不同的场合使用不同的协议. 协议能够通过ssh链接的加密隧道进行 Git: 非常棒. 能够使用本地的git协议, 但也能在rsync, ssh, HTTP和HTTPS上使用 Mercurial: 非常棒. 使用HTTP或ssh. 远程访问会非常安全, 在只读网络里不需要上锁 Subversion: 非常好. Subversion服务器支持WebDAV+DeltaV(基于HTTP或HTTPS)作为底层协议, 或者它自身的协议同样能在ssh链接通道里使用.
可移植性 客户端能在UNIX, Windows和Mac OS上使用. 客户端运行在大多数的UNIX系统上, 运行在基于所有能运行python的平台 客户端和服务器端都能在UNIX, Windows和Mac OS X上运行
web接口 .CVSweb, ViewVC, Chora和wwCVS Gitweb Mercurial: 是的. Web接口是内置组件 ViewVC, SVN::Web, WebSVN, ViewSVN, mod_svn_view, Chora, Trac,SVN::RaWeb::Light,SVN Browser, Insurrection和perl_svn.
图形用户界面 WinCVS, Cervisia, TortoiseCVS Gitk,Qqit和Git-gui Hgit,hgct RapidSVN, TortoiseSVN, Jsvn(java),

Git 是什么

Git与其他版本控制系统的区别,其他的一般基于差异delta-based版本控制,如下:

git是基于快照流的,如下:

近乎所有的操作都是本地执行。

git的初始配置

设置用户名和邮箱地址

在使用git提交或者操作的时候,git需要知道你是谁,邮箱是什么,可以通过下面的命令进行配置:

1
2
$ git config --global user.name "Your Name"
$ git config --global user.email "youremail@xyz.com"

设置文本编辑器

如果你想使用不同的文本编辑器,例如 vim,可以这样做:

1
$ git config --global core.editor vim

提供命令输出的可读性

默认情况下,git的操作可能都是黑白的,如果更改为彩色,就可以注意到很多特性,并且提高可读性,让你的世界不再只是黑白色。

1
$ git config --global color.ui auto

当然也可以在文件~/.gitconfig加上以上

1
2
[color]
ui = auto

Git 在Windows上的配置

git add 提示warning: LF will be replaced by CRLF in 解决办法

在使用git的时候,每次执行

1
$ git add filename

都会提示这样一个警告消息:

这里主要是因为不同的操作系统之间对换行的定义不同,比如Windows为CRLF,Linux为LF,而MacOSX为CR。

这就导致从不同系统checkout代码的时候,文件并未修改,反而出现了modified的情况,如下可以避免这种情况。

1
$ git config core.autocrlf false

这样设置git的配置后在执行add操作就没有问题了。

精准快速定位的locate

.. note::

众里寻他千百度,蓦然回首,那人却在灯火阑珊处
-李煜

Linux locate命令用于查找符合条件的文档、程序、目录等等。这个命令会在数据库中查找符合条件的各种信息。

一般情况我们只需要输入 locate name 即可查找。

官方定义为:

locate - list files in databases that match a pattern

使用方法为:

1
2
3
4
$ locate  [-d  path  |  --database=path]  [-e  | -E | --[non-]existing] [-i | --ignore-case] [-0 | --null] [-c |
--count] [-w | --wholename] [-b | --basename] [-l N | --limit=N] [-S | --statistics] [-r | --regex ] [--regex‐
type R] [--max-database-age D] [-P | -H | --nofollow] [-L | --follow] [--version] [-A | --all] [-p | --print]
[--help] pattern...

看着很复杂,不过常用的参数倒是不多,基本为:

  • -n : 至多显示 n个输出。
  • -i, --ignore-case : 忽略大小写

默认无参数

默认情况下,locate直接跟上需要查找的信息就可以了,如下所示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ locate set_vis.cpp
/home/user/mycode/src/set_vis.cpp

# 以查找apropos为例
$ locate apropos
/usr/bin/apropos
/usr/local/difmap/help/apropos.hlp
/usr/share/emacs/24.3/lisp/apropos.elc
/usr/share/man/de/man1/apropos.1.gz
/usr/share/man/es/man1/apropos.1.gz
/usr/share/man/fr/man1/apropos.1.gz
/usr/share/man/id/man1/apropos.1.gz
/usr/share/man/it/man1/apropos.1.gz
/usr/share/man/ja/man1/apropos.1.gz
/usr/share/man/man1/apropos.1.gz
/usr/share/man/nl/man1/apropos.1.gz
/usr/share/man/pl/man1/apropos.1.gz
/usr/share/man/ru/man1/apropos.1.gz

太多需要简单化

如果输出的信息很多,仅仅希望看到前面的几个,使用-n参数既可

1
2
3
4
5
# 仅仅查看前的3个
$ locate -n 3 apropos
/usr/bin/apropos
/usr/local/difmap/help/apropos.hlp
/usr/share/emacs/24.3/lisp/apropos.elc

不区分大小写

部分情况下,可能有大小写混淆的情况,此时使用-i参数既可

1
2
3
$ $ locate -i set_vis.cpp
/home/user/mycode/src/set_vis.cpp
/home/user/mycode_CPP/src/set_VIS.cpp

📖 说明

不过刚按照的系统,这个命令并不一定有输出,主要是因为locatefind 不同, find 直接在硬盘找,而locate 只在数据库中查找。

这个数据库在CentOS系统默认的为 /var/lib/mlocate/mlocate.db 中,所以 locate 的查找会比较快,但并一定是实时的,而是以数据库的更新为准。

可以通过下面的命令手工升级数据库 ,命令为:

1
$ updatedb

然后就可以使用了。

无器械健身

总结起来也就六个字:

** 结实 强壮 自信 **

即练出结实的肌肉、锻炼强壮的躯体,培养自信的自己。

Plus:成功健身必须遵循的6个原则

  • 坚持
  • 恢复
  • 规律
  • 变化
  • 进步
  • 超负荷

solved : RPMDB altered outside of yum

在使用yum的时候报的错误,解决方法为:

1
yum history sync

主要是将我们rpmdb和yumdb进行同步一下,注意,这个过程根据你的机器情况和安装软件包的数量可能会小小的需要一段时间。

Refer:

https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/7-Beta/html/System_Administrators_Guide/sect-Yum-Transaction_History.html

5.4. Working with Transaction History

The yum history command allows users to review information about a timeline of Yum transactions, the dates and times they occurred, the number of packages affected, whether transactions succeeded or were aborted, and if the RPM database was changed between transactions. Additionally, this command can be used to undo or redo certain transactions. All history data are stored in the history DB in the var/lib/yum/history/ directory.

5.4.1. Listing Transactions

To display a list of twenty most recent transactions, as root, either run yum history with no additional arguments, or type the following at a shell prompt:

yum history list

To display all transactions, add the all keyword:

yum history list all

To display only transactions in a given range, use the command in the following form:

yum history list start_id..end_id

You can also list only transactions regarding a particular package or packages. To do so, use the command with a package name or a glob expression:

yum history list glob_expression…

Example 5.18. Listing the five oldest transactions

In the output of yum history list, the most recent transaction is displayed at the top of the list. To display information about the five oldest transactions stored in the history data base, type:

~]# yum history list 1..5

Loaded plugins: product-id, refresh-packagekit, subscription-manager

ID | Login user | Date and time | Action(s) | Altered

——————————————————————————-

 5 | Jaromir … <jhradilek>  | 2013-07-29 15:33 | Install        |    1

 4 | Jaromir … <jhradilek>  | 2013-07-21 15:10 | Install        |    1

 3 | Jaromir … <jhradilek>  | 2013-07-16 15:27 | I, U           |   73

 2 | System <unset>           | 2013-07-16 15:19 | Update         |    1

 1 | System <unset>           | 2013-07-16 14:38 | Install        | 1106

history list

All forms of the yum history list command produce tabular output with each row consisting of the following columns:

ID — an integer value that identifies a particular transaction.

Login user — the name of the user whose login session was used to initiate a transaction. This information is typically presented in the Full Name form. For transactions that were not issued by a user (such as an automatic system update), System is used instead.

Date and time — the date and time when a transaction was issued.

Action(s) — a list of actions that were performed during a transaction as described in Table 5.1, “Possible values of the Action(s) field”.

Altered — the number of packages that were affected by a transaction, possibly followed by additional information as described in Table 5.2, “Possible values of the Altered field”.

Table 5.1. Possible values of the Action(s) field

Action Abbreviation Description

Downgrade D At least one package has been downgraded to an older version.

Erase E At least one package has been removed.

Install I At least one new package has been installed.

Obsoleting O At least one package has been marked as obsolete.

Reinstall R At least one package has been reinstalled.

Update U At least one package has been updated to a newer version.

Table 5.2. Possible values of the Altered field

Symbol Description

< Before the transaction finished, the rpmdb database was changed outside Yum.

After the transaction finished, the rpmdb database was changed outside Yum.
  • The transaction failed to finish.
    

The transaction finished successfully, but yum returned a non-zero exit code.

E The transaction finished successfully, but an error or a warning was displayed.

P The transaction finished successfully, but problems already existed in the rpmdb database.

s The transaction finished successfully, but the –skip-broken command line option was used and certain packages were skipped.

To synchronize the rpmdb or yumdb database contents for any installed package with the currently used rpmdb or yumdb database, type the following:

yum history sync

To display some overall statistics about the currently used history DB use the following command:

yum history stats

Example 5.19. Example output of yum history stats

~]# yum history stats

Loaded plugins: langpacks, presto, refresh-packagekit

File : //var/lib/yum/history/history-2012-08-15.sqlite

Size : 2,766,848

Transactions: 41

Begin time : Wed Aug 15 16:18:25 2012

End time : Wed Feb 27 14:52:30 2013

Counts :

NEVRAC : 2,204

NEVRA : 2,204

NA : 1,759

NEVR : 2,204

rpm DB : 2,204

yum DB : 2,204

history stats

Yum also allows you to display a summary of all past transactions. To do so, run the command in the following form as root:

yum history summary

To display only transactions in a given range, type:

yum history summary start_id..end_id

Similarly to the yum history list command, you can also display a summary of transactions regarding a certain package or packages by supplying a package name or a glob expression:

yum history summary glob_expression…

Example 5.20. Summary of the five latest transactions

~]# yum history summary 1..5

Loaded plugins: product-id, refresh-packagekit, subscription-manager

Login user | Time | Action(s) | Altered

——————————————————————————-

Jaromir … | Last day | Install | 1

Jaromir … | Last week | Install | 1

Jaromir … | Last 2 weeks | I, U | 73

System | Last 2 weeks | I, U | 1107

history summary

All forms of the yum history summary command produce simplified tabular output similar to the output of yum history list.

As shown above, both yum history list and yum history summary are oriented towards transactions, and although they allow you to display only transactions related to a given package or packages, they lack important details, such as package versions. To list transactions from the perspective of a package, run the following command as root:

yum history package-list glob_expression…

Example 5.21. Tracing the history of a package

For example, to trace the history of subscription-manager and related packages, type the following at a shell prompt:

~]# yum history package-list subscription-manager*

Loaded plugins: product-id, refresh-packagekit, subscription-manager

ID | Action(s) | Package

——————————————————————————-

 3 | Updated        | subscription-manager-0.95.11-1.el6.x86_64

 3 | Update         |                      0.95.17-1.el6_1.x86_64

 3 | Updated        | subscription-manager-firstboot-0.95.11-1.el6.x86_64

 3 | Update         |                                0.95.17-1.el6_1.x86_64

 3 | Updated        | subscription-manager-gnome-0.95.11-1.el6.x86_64

 3 | Update         |                            0.95.17-1.el6_1.x86_64

 1 | Install        | subscription-manager-0.95.11-1.el6.x86_64

 1 | Install        | subscription-manager-firstboot-0.95.11-1.el6.x86_64

 1 | Install        | subscription-manager-gnome-0.95.11-1.el6.x86_64

history package-list

In this example, three packages were installed during the initial system installation: subscription-manager, subscription-manager-firstboot, and subscription-manager-gnome. In the third transaction, all these packages were updated from version 0.95.11 to version 0.95.17.

5.4.2. Examining Transactions

To display the summary of a single transaction, as root, use the yum history summary command in the following form:

yum history summary id

To examine a particular transaction or transactions in more detail, run the following command as root:

yum history info id…

The id argument is optional and when you omit it, yum automatically uses the last transaction. Note that when specifying more than one transaction, you can also use a range:

yum history info start_id..end_id

Example 5.22. Example output of yum history info

The following is sample output for two transactions, each installing one new package:

~]# yum history info 4..5

Loaded plugins: product-id, refresh-packagekit, subscription-manager

Transaction ID : 4..5

Begin time : Thu Jul 21 15:10:46 2011

Begin rpmdb : 1107:0c67c32219c199f92ed8da7572b4c6df64eacd3a

End time : 15:33:15 2011 (22 minutes)

End rpmdb : 1109:1171025bd9b6b5f8db30d063598f590f1c1f3242

User : Jaromir Hradilek

Return-Code : Success

Command Line : install screen

Command Line : install yum-plugin-fs-snapshot

Transaction performed with:

Installed     rpm-4.8.0-16.el6.x86_64

Installed     yum-3.2.29-17.el6.noarch

Installed     yum-metadata-parser-1.1.2-16.el6.x86_64

Packages Altered:

Install screen-4.0.3-16.el6.x86_64

Install yum-plugin-fs-snapshot-1.1.30-6.el6.noarch

history info

You can also view additional information, such as what configuration options were used at the time of the transaction, or from what repository and why were certain packages installed. To determine what additional information is available for a certain transaction, type the following at a shell prompt as root:

yum history addon-info id

Similarly to yum history info, when no id is provided, yum automatically uses the latest transaction. Another way to refer to the latest transaction is to use the last keyword:

yum history addon-info last

Example 5.23. Example output of yum history addon-info

For the fourth transaction in the history, the yum history addon-info command provides the following output:

~]# yum history addon-info 4

Loaded plugins: product-id, refresh-packagekit, subscription-manager

Transaction ID: 4

Available additional history information:

config-main

config-repos

saved_tx

history addon-info

In the output of the yum history addon-info command, three types of information are available:

config-main — global Yum options that were in use during the transaction. Refer to Section 5.5.1, “Setting [main] Options” for information on how to change global options.

config-repos — options for individual Yum repositories. Refer to Section 5.5.2, “Setting [repository] Options” for information on how to change options for individual repositories.

saved_tx — the data that can be used by the yum load-transaction command in order to repeat the transaction on another machine (see below).

To display selected type of additional information, run the following command as root:

yum history addon-info id information

5.4.3. Reverting and Repeating Transactions

Apart from reviewing the transaction history, the yum history command provides means to revert or repeat a selected transaction. To revert a transaction, type the following at a shell prompt as root:

yum history undo id

To repeat a particular transaction, as root, run the following command:

yum history redo id

Both commands also accept the last keyword to undo or repeat the latest transaction.

Note that both yum history undo and yum history redo commands only revert or repeat the steps that were performed during a transaction. If the transaction installed a new package, the yum history undo command will uninstall it, and if the transaction uninstalled a package the command will again install it. This command also attempts to downgrade all updated packages to their previous version, if these older packages are still available. If you need to restore the system to the state before an update, consider using the fs-snapshot plug-in described in Section 5.6.3, “Working with Plug-ins”.

When managing several identical systems, Yum also allows you to perform a transaction on one of them, store the transaction details in a file, and after a period of testing, repeat the same transaction on the remaining systems as well. To store the transaction details to a file, type the following at a shell prompt as root:

yum -q history addon-info id saved_tx > file_name

Once you copy this file to the target system, you can repeat the transaction by using the following command as root:

yum load-transaction file_name

You can configure load-transaction to ignore missing packages or rpmdb version. For more information on these configuration options see the yum.conf man page.

5.4.4. Starting New Transaction History

Yum stores the transaction history in a single SQLite database file. To start new transaction history, run the following command as root:

yum history new

This will create a new, empty database file in the /var/lib/yum/history/ directory. The old transaction history will be kept, but will not be accessible as long as a newer database file is present in the directory.

grafana使用教程

安装

参考 https://grafana.com/docs/grafana/latest/installation/rpm/

1
$ sudo vim /etc/yum.repos.d/grafana.repo

对于开源而言,内容如下:

1
2
3
4
5
6
7
8
9
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt

对于商用版本,内容如下:

1
2
3
4
5
6
7
8
9
[grafana]
name=grafana
baseurl=https://packages.grafana.com/enterprise/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt

然后开始安装

1
2
3
4
5
6
$ sudo yum update
$ sudo yum install grafana

# or

$ sudo yum install grafana-enterprise

安装插件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
使用grafana-cli工具安装

#获取可用插件列表

$ grafana-cli plugins list-remote

#修改图形为饼状
$ grafana-cli plugins install grafana-piechart-panel
#安装其他图形插件
$ grafana-cli plugins install grafana-clock-panel
#钟表形展示
$ grafana-cli plugins install briangann-gauge-panel
#字符型展示
$ grafana-cli plugins install natel-discrete-panel
#服务器状态
$ grafana-cli plugins install vonage-status-panel

启动、重启、关闭

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#启动:
$ service grafana-server start

# 停止:
$service grafana-server stop

# 重启:
$ service grafana-server restart

#加入开机自启动:
$chkconfig --add grafana-server on


### Or later

$ sudo systemctl daemon-reload
$ sudo systemctl start grafana-server
$ sudo systemctl status grafana-server
#Configure the Grafana server to start at boot:
$ sudo systemctl enable grafana-server

创建Dashboard

首先选定一个数据库,添加一个数据源。

登录Grafana Protal

在浏览器中输入:http://GRAFANA_HOST_IP:3000
默认账号/密码:admin/admin

进入Plugins界面,选择“Zabbix”
开始面板(左上角图标) -> Plugins -> Apps -> Zabbix

更改linux的MAC地址

执行下列命令,重启后失效:

1
2
3
4
5
6
7
/sbin/ifconfig eth0 down

/sbin/ifconfig eth0 hw ether 00:11:22:33:44:55

/sbin/ifconfig eth0 up

service network restart

永久更改的方法:

1
vi /etc/sysconfig/network-scripts/ifcfg-eth0

添加MACADDR=00:11:22:33:44:55

注释掉原来的HWADDR

有所依靠的chgrp

.. code::
鸿鹄志、向炎天。
宋 刘克庄《贺新郎·杜子昕凯歌》

Linux的chgrp命令用于变更文件或者目录所属的组group。

这里的变更不仅限于本人的组,只要用户属于的组,均可以使用chgrp更改相应的权限而不是必须使用管理员权限。

很多权限的操作可以与chmod来交叉。比如如果希望文件只有本组成员访问,可以通过chmod 770 file/directory,此时就涉及到组的概念了。

官方定义为:

chgrp - change group ownership

语法为:

1
2
$ chgrp [OPTION]... GROUP FILE...
$ chgrp [OPTION]... --reference=RFILE FILE...

常用的几个参数为:

  • --reference=RFILE : 参考指定文件进行所属组更换

  • -R, --recursive :递归处理,将某个目录的所有文件均更改用户组

默认用法

最简单的使用为将文件file归属到组group,使用方法为:

1
2
$ chgrp group file
$ chgrp group1 file1

此时的file数组组group,file1属于组group1。

更改文件夹的所属组

对于文件夹而言,就需要使用-R参数来递归实现了,不然会报错的。

1
2
$ chgrp -R group1 directory1
$ chgrp -R group2 directory2

根据指定文件来修改组

这个参数比较有趣,也比较高效,如果希望某个用户的组权限与另外一个文件一致,此时--reference强势出现

1
$ chgrp --reference=ref_file stage_file

该命令执行后,stage_file的权限将与ref_file的组权限一样。

TODO

设置SGID属性(确保NEWGROUP组拥有所有新建的文件),设置sticky(沾滞位)属性(以免文件被拥有者以外的其他人删除)

1
chmod g+s,o+t /home/groupdir

具体参考SGID/SUID/SBID以及sticky的详细含义。

linux设置只能特定的用户组用户访问文件夹

创建新组:

1
groupadd NEWGROUP

将现有的用户加入改组:

1
usermod -G NEWGROUP username 

改变新目录的组所有权

1
chgrp NEWGROUP directory

禁止非组成员的访问

1
chmod 770 /home/groupdir

设置SGID属性(确保NEWGROUP组拥有所有新建的文件),设置sticky(沾滞位)属性(以免文件被拥有者以外的其他人删除)

1
chmod g+s,o+t /home/groupdir

具体参考SGID/SUID/SBID以及sticky的详细含义。