我的系统是centos7.6,安装php8.3时,先直接yum remove php* 移除原有的php组件,然后按照以下攻略安装当前最新的php8.3版本

https://medium.com/@nothanjack/mastering-the-installation-of-php-8-3-on-centos-7-easy-steps-1118ed651522

我把php8.3所需的扩展组件汇总,你可以直接yum install -y,当然你得先把仓库安装好

sudo yum install epel-release

sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

然后 yun install以下

php83 php-bcmath php83-php-bcmath php83-php-cli php83-php-common php83-php-devel php83-php-fpm php83-php-gd php83-php-gmp php83-php-intl php83-php-mbstring php83-php-mysqlnd php83-php-opcache php83-php-pdo php83-php-pdo-dblib php83-php-pecl-apcu php83-php-pecl-apcu-devel php83-php-pecl-igbinary php83-php-pecl-imagick-im6 php83-php-pecl-msgpack php83-php-pecl-redis6 php83-php-pecl-zip php83-php-process php83-php-sodium php83-php-xml

发表于wooder | 留下评论

使用环境 centos 8 LNMP wordpress

先说结论:系统重启后没有关闭selinux

因为维护主机,所以重启了一下虚拟机,结果wp就没法正常访问了,一直提示数据库连接异常。在排查了数据库和nginx无果之后,想到了去系统的message查下报错信息。果然发现了端倪

Mar 7 19:45:14 host setroubleshoot[2219]: SELinux is preventing php-fpm from name_connect access on the tcp_socket port 3306.#012#012***** Plugin catchall_boolean (47.5 confidence) suggests ******************#012#012If you want to allow httpd to can network connect#012Then you must tell SELinux about this by enabling the 'httpd_can_network_connect' boolean.#012#012Do#012setsebool -P httpd_can_network_connect 1#012#012***** Plugin catchall_boolean (47.5 confidence) suggests ******************#012#012If you want to allow httpd to can network connect db#012Then you must tell SELinux about this by enabling the 'httpd_can_network_connect_db' boolean.#012#012Do#012setsebool -P httpd_can_network_connect_db 1#012#012***** Plugin catchall (6.38 confidence) suggests **************************#012#012If you believe that php-fpm should be allowed name_connect access on the port 3306 tcp_socket by default.#012Then you should report this as a bug.#012You can generate a local policy module to allow this access.#012Do#012allow this access for now by executing:#012# ausearch -c 'php-fpm' --raw | audit2allow -M my-phpfpm#012# semodule -X 300 -i my-phpfpm.pp#012

这就很明显提示selinux阻止了php-fpm建立的mysql连接。关闭selinux之后一切正常。

发表于wooder | 留下评论

转载自https://note.qidong.name/2020/05/docker-proxy/

有时因为网络原因,比如公司NAT,或其它啥的,需要使用代理。 Docker的代理配置,略显复杂,因为有三种场景。 但基本原理都是一致的,都是利用Linux的http_proxy等环境变量。

dockerd代理

在执行docker pull时,是由守护进程dockerd来执行。 因此,代理需要配在dockerd的环境中。 而这个环境,则是受systemd所管控,因此实际是systemd的配置。

sudo mkdir -p /etc/systemd/system/docker.service.d
sudo touch /etc/systemd/system/docker.service.d/proxy.conf

在这个proxy.conf文件(可以是任意*.conf的形式)中,添加以下内容:

[Service]
Environment="HTTP_PROXY=http://proxy.example.com:8080/"
Environment="HTTPS_PROXY=http://proxy.example.com:8080/"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"

其中,proxy.example.com:8080要换成可用的免密代理。 通常使用cntlm在本机自建免密代理,去对接公司的代理。 可参考《Linux下安装配置Cntlm代理》。

Container代理

在容器运行阶段,如果需要代理上网,则需要配置~/.docker/config.json。 以下配置,只在Docker 17.07及以上版本生效。

{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://proxy.example.com:8080",
     "httpsProxy": "http://proxy.example.com:8080",
     "noProxy": "localhost,127.0.0.1,.example.com"
   }
 }
}

这个是用户级的配置,除了proxiesdocker login等相关信息也会在其中。 而且还可以配置信息展示的格式、插件参数等。

此外,容器的网络代理,也可以直接在其运行时通过-e注入http_proxy等环境变量。 这两种方法分别适合不同场景。 config.json非常方便,默认在所有配置修改后启动的容器生效,适合个人开发环境。 在CI/CD的自动构建环境、或者实际上线运行的环境中,这种方法就不太合适,用-e注入这种显式配置会更好,减轻对构建、部署环境的依赖。 当然,在这些环境中,最好用良好的设计避免配置代理上网。

docker build代理

虽然docker build的本质,也是启动一个容器,但是环境会略有不同,用户级配置无效。 在构建时,需要注入http_proxy等参数。

docker build . \
    --build-arg "HTTP_PROXY=http://proxy.example.com:8080/" \
    --build-arg "HTTPS_PROXY=http://proxy.example.com:8080/" \
    --build-arg "NO_PROXY=localhost,127.0.0.1,.example.com" \
    -t your/image:tag

注意:无论是docker run还是docker build,默认是网络隔绝的。 如果代理使用的是localhost:3128这类,则会无效。 这类仅限本地的代理,必须加上--network host才能正常使用。 而一般则需要配置代理的外部IP,而且代理本身要开启gateway模式。

重启生效

代理配置完成后,reboot重启当然可以生效,但不重启也行。

docker build代理是在执行前设置的,所以修改后,下次执行立即生效。 Container代理的修改也是立即生效的,但是只针对以后启动的Container,对已经启动的Container无效。

dockerd代理的修改比较特殊,它实际上是改systemd的配置,因此需要重载systemd并重启dockerd才能生效。

sudo systemctl daemon-reload
sudo systemctl restart docker

参考

发表于wooder | 留下评论

转载自https://www.unixso.com/NetWork/netstat.html

Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memberships) 等等。
常见参数

-a (all)显示所有选项,默认不显示LISTEN相关
-t (tcp)仅显示tcp相关选项
-u (udp)仅显示udp相关选项
-n 拒绝显示别名,能显示数字的全部转化成数字。
-l 仅列出有在 Listen (监听) 的服務状态
-p 显示建立相关链接的程序名
-r 显示路由信息,路由表
-e 显示扩展信息,例如uid等
-s 按各个协议进行统计
-c 每隔一个固定时间,执行该netstat命令。

提示:LISTEN和LISTENING的状态只有用-a或者-l才能看到
状态列表:

LISTEN:侦听来自远方的TCP端口的连接请求
SYN-SENT:再发送连接请求后等待匹配的连接请求
SYN-RECEIVED:再收到和发送一个连接请求后等待对方对连接请求的确认
ESTABLISHED:代表一个打开的连接
FIN-WAIT-1:等待远程TCP连接中断请求,或先前的连接中断请求的确认
FIN-WAIT-2:从远程TCP等待连接中断请求
CLOSE-WAIT:等待从本地用户发来的连接中断请求
CLOSING:等待远程TCP对连接中断的确认
LAST-ACK:等待原来的发向远程TCP的连接中断请求的确认
TIME-WAIT:等待足够的时间以确保远程TCP接收到连接中断请求的确认
CLOSED:没有任何连接状态

常用使用方法:

并发请求数及其TCP连接状态:
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

显示当前所有活动的网络连接:
netstat -na

列出所有端口 (包括监听和未监听的)
netstat -a

只显示监听端口 netstat -l
netstat -l

只列出所有监听 tcp 端口 netstat -lt
netstat -lt

只列出所有监听 udp 端口 netstat -lu
netstat -lu

只列出所有监听 UNIX 端口 netstat -lx
netstat -lx

显示所有端口的统计信息 netstat -s
netstat -s

显示 TCP 或 UDP 端口的统计信息 netstat -st 或 -su
netstat -st 
netstat -su

在 netstat 输出中显示 PID 和进程名称 netstat -p
netstat -p 可以与其它开关一起使用,就可以添加 “PID/进程名称” 到 netstat 输出中,这样 debugging 的时候可以很方便的发现特定端口运行的程序。
netstat -pt

显示系统不支持的地址族 (Address Families)
netstat --verbose

显示核心路由信息 netstat -r
netstat -r

显示网络接口列表
netstat -i

显示出所有处于监听状态的应用程序及进程号和端口号:
netstat -aultnp

如果想对一个单一的进行查询,只需要在命令后面再加上“| grep $”。这里就用到了管道符,以及grep筛选命令,$代表参数,也就是你要查询的那个。
如要显示所有80端口的网络连接:
netstat -aultnp | grep 80

如果还想对返回的连接列表进行排序,这就要用到sort命令了,命令如下:
netstat -aultnp | grep :80 | sort

当然,如果还想进行统计的话,就可以再往后面加wc命令。如:
netstat -aultnp | grep :80 | wc -l

其实,要想监测出系统连接是否安全,要进行多状态的查询,以及要分析,总结,还有就是经验。总的下来,才可以判断出连接是否处于安全状态。
netstat -n -p|grep SYN_REC | wc -l

这个命令可以查找出当前服务器有多少个活动的 SYNC_REC 连接。正常来说这个值很小,最好小于5。 当有Dos攻击或者邮件炸弹的时候,这个值相当的高。尽管如此,这个值和系统有很大关系,有的服务器值就很高,也是正常现象。
netstat -n -p | grep SYN_REC | sort -u

先把状态全都取出来,然后使用uniq -c统计,之后再进行排序。
wss8848@ubuntu:~$ netstat -nat |awk '{print $6}'|sort|uniq -c

列出所有连接过的IP地址。
netstat -n -p | grep SYN_REC | awk '{print $5}' | awk -F: '{print $1}'

列出所有发送SYN_REC连接节点的IP地址。
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

使用netstat命令计算每个主机连接到本机的连接数。
netstat -anp |grep 'tcp|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

列出所有连接到本机的UDP或者TCP连接的IP数量。
netstat -ntu | grep ESTAB | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr

检查 ESTABLISHED 连接并且列出每个IP地址的连接数量。
netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1
发表于wooder | 留下评论

检测sshd异常登录的脚本,防止暴力破解:

#!/bin/bash
#This is a host.deny Shell Script
#2013-08-24
cat /var/log/secure | awk '/Failed/{print $(NF-3)}' | sort | uniq -c | awk '{print $2 "=" $1;}' > /tmp/black_ip.txt
DEFINE=10
for i in `cat /tmp/black_ip.txt`
do
IP=`echo $i | awk -F= '{print $1}'`
NUM=`echo $i | awk -F= '{print $2}'`
if [ $NUM -gt $DEFINE ]
then
grep $IP /etc/hosts.deny > /dev/null
if [ $? -gt 0 ]
then
echo "sshd:$IP" >> /etc/hosts.deny
fi
fi
done

发表于wooder | 留下评论

今天发现了一个可以更换群晖登录界面壁纸的脚本,拉取的是Bing的图片,代码在下面这个链接:

https://github.com/kkkgo/DSM_Login_BingWallpaper

把它添加到群晖定时任务里边就行了。

发表于wooder | 留下评论

clickhouse统计数据库大小

注意最后以后右边是两个分号

 

select
sum(rows) as "总行数",
formatReadableSize(sum(data_uncompressed_bytes)) as "原始大小",
formatReadableSize(sum(data_compressed_bytes)) as "压缩大小",
round(sum(data_compressed_bytes) / sum(data_uncompressed_bytes) * 100, 0) "压缩率"
from system.parts;;
发表在 clickhouse | 标签为 | 留下评论

centos清除磁盘标签

我之前有几块硬盘用作freenas的zfs分区,现在不用了,想换到centos主机上面用,那就得格式化,但是当我按常规fdisk分区,mkfs格式化,mount挂载分区,遇到这个问题:

[root@server3 samba]# mount /dev/sdb1 /var/nextcloud_bak1
mount: /dev/sdb1:检测到更多文件系统。这不应该出现,
请使用 -t <类型> 指明文件系统类型或
使用 wipefs(8) 清理该设备。

 

也就是说原先zfs格式的磁盘标签没有清理,当然,不影响使用,但是你挂载就得指磁盘分区,不是那么完美,然后blkid也查不到uuid,所以还是要清理干净

[root@server3 samba]# wipefs /dev/sdb1
offset type
----------------------------------------------------------------
0xe8e0c3e000 zfs_member [filesystem]

0x438 ext4 [filesystem]
UUID: b66153c7-dda6-496e-a9bc-04cd7e81a2bf

 

可以看到,我的ext4格式已经出来了,但是原先的zfs也还在

 

[root@server3 samba]# wipefs -a /dev/sdb
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d3e000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d3d000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d3c000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d3b000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d3a000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d39000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d38000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d37000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d36000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d35000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d34000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d33000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d7f000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d7e000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d7d000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d7c000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d7b000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d7a000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d79000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d78000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d77000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d76000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d75000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d74000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d73000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d72000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d71000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0d70000 (zfs_member):0c b1 ba 00 00 00 00 00
/dev/sdb:8 个字节已擦除,位置偏移为 0x00000200 (gpt):45 46 49 20 50 41 52 54
/dev/sdb:8 个字节已擦除,位置偏移为 0xe8e0db5e00 (gpt):45 46 49 20 50 41 52 54
/dev/sdb:2 个字节已擦除,位置偏移为 0x000001fe (PMBR):55 aa
/dev/sdb: calling ioclt to re-read partition table: 成功

 

直接执行-a就行了,但是得注意,所有的内容都会擦除,并且得重新分区和格式化!

发表在 通用 | 标签为 , , | 留下评论

xxx command denied to user xxx mysql权限管理

感谢原作者

https://www.cnblogs.com/smallrookie/p/7552097.html

今天遇到一个mysql 权限的问题,即标题所述  xxx command denied to user xxx,一般mysql 这种报错,基本都属于当前用户没有进行该操作的权限,需要 root 用户授权才能解决,从网上找了一些资料,感觉这篇写得不错,分享一下:

原文地址:http://www.rainsts.net/article.asp?id=988

可以用 CREATE USER 或 GRANT 创建用户,后者还同时分配相关权限。而 REVOKE 则用于删除用户权限,DROP USER 删除账户。

$ mysql -u root -p
password:

mysql> create database test; # 创建数据库
Query OK, 1 row affected (0.00 sec)

mysql> show databases; # 查看数据库是否创建成功
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql> grant all on test.* to user1@'%' identified by '123456' with grant option; # 创建特权管理用户
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from mysql.user; # 查看用户创建是否成功
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| user1            | %         |
| root             | 127.0.0.1 |
| debian-sys-maint | localhost |
| root             | localhost |
| root             | server    |
+------------------+-----------+
5 rows in set (0.00 sec)

mysql> show grants for user1; # 查看用户权限
+--------------------------------------------------------------------------------------------------+
| Grants for user1@%                                                                               |
+--------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'user1'@'%' IDENTIFIED BY PASSWORD '*6BB...2CA2AD9'                        |
| GRANT ALL PRIVILEGES ON `test`.* TO 'user1'@'%' WITH GRANT OPTION                                |
+--------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

GRANT 语法:

GRANT privileges (columns)
    ON what
    TO user IDENTIFIED BY "password"
    WITH GRANT OPTION

权限列表:

  • ALTER: 修改表和索引。
  • CREATE: 创建数据库和表。
  • DELETE: 删除表中已有的记录。
  • DROP: 抛弃(删除)数据库和表。
  • INDEX: 创建或抛弃索引。
  • INSERT: 向表中插入新行。
  • REFERENCE: 未用。
  • SELECT: 检索表中的记录。
  • UPDATE: 修改现存表记录。
  • FILE: 读或写服务器上的文件。
  • PROCESS: 查看服务器中执行的线程信息或杀死线程。
  • RELOAD: 重载授权表或清空日志、主机缓存或表缓存。
  • SHUTDOWN: 关闭服务器。
  • ALL: 所有权限,ALL PRIVILEGES同义词。
  • USAGE: 特殊的 “无权限” 权限。

用 户账户包括 “username” 和 “host” 两部分,后者表示该用户被允许从何地接入。user1@’%’ 表示任何地址,默认可以省略。还可以是 “[email protected].%”、”user1@%.abc.com” 等。数据库格式为 db@table,可以是 “test.*” 或 “*.*”,前者表示 test 数据库的所有表,后者表示所有数据库的所有表。

子句 “WITH GRANT OPTION” 表示该用户可以为其他用户分配权限。

我们用 root 再创建几个用户,然后由 test 数据库的管理员 user1 为他们分配权限。

mysql> create user user2 identified by '123456', user3 identified by 'abcd';
Query OK, 0 rows affected (0.00 sec)

mysql> select user, host from mysql.user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| user1            | %         |
| user2            | %         |
| user3            | %         |
| root             | 127.0.0.1 |
| debian-sys-maint | localhost |
| root             | localhost |
| root             | server    |
+------------------+-----------+
7 rows in set (0.00 sec)

好了,我们退出改用 user1 登录并针对 test 数据库进行操作。

mysql> quit # 退出
Bye

$ mysql -u user1 -p123456 test # 使用新用户登录

mysql> select database(); # 确认当前工作数据库
+------------+
| database() |
+------------+
| test       |
+------------+
1 row in set (0.00 sec)

mysql> select current_user(); # 确认当前工作账户
+----------------+
| current_user() |
+----------------+
| user1@%        |
+----------------+
1 row in set (0.00 sec)

继续,创建一个数据表。

mysql> create table table1 # 创建表
    -> (
    ->    name varchar(50),
    ->    age integer
    -> );
Query OK, 0 rows affected (0.02 sec)

mysql> show tables; # 查看表是否创建成功
+----------------+
| Tables_in_test |
+----------------+
| table1         |
+----------------+
1 row in set (0.00 sec)

mysql> describe table1; # 查看表结构
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name  | varchar(50) | YES  |     | NULL    |       |
| age   | int(11)     | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> insert into table1 values('Tom', 20); # 插入记录
Query OK, 1 row affected (0.00 sec)

mysql> select * from table1; # 查询记录
+------+------+
| name | age  |
+------+------+
| Tom  |   20 |
+------+------+
1 row in set (0.00 sec)

接下来我们为 user2, user3 分配权限。

mysql> grant select on test.* to user2; # 为 user2 分配 SELECT 权限。
Query OK, 0 rows affected (0.00 sec)

mysql> grant select on test.* to user3; # 为 user3 分配 SELECT 权限。
Query OK, 0 rows affected (0.00 sec)

mysql> grant insert, update on test.* to user2; # 再为 user2 增加 INSERT, UPDATE 权限。
Query OK, 0 rows affected (0.00 sec)

好了,我们退出,切换成 user2 操作看看。

$ mysql -u user2 -p123456

mysql> use test; # 切换工作数据库
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

mysql> select database(); # 验证当前工作数据库
+------------+
| database() |
+------------+
| test       |
+------------+
1 row in set (0.00 sec)

mysql> select user(); # 验证当前账户
+-----------------+
| user()          |
+-----------------+
| user2@localhost |
+-----------------+
1 row in set (0.00 sec)

mysql> show grants for user2; # 查看当前用户权限,显然后来添加的 INSERT, UPDATE 被添加了。
+--------------------------------------------------------------------------------------------------+
| Grants for user2@%                                                                               |
+--------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'user2'@'%' IDENTIFIED BY PASSWORD '*6BB837....2C9'                        |
| GRANT SELECT, INSERT, UPDATE ON `test`.* TO 'user2'@'%'                                          |
+--------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

进行操作测试。

mysql> insert into table1 values("Jack", 21); # INSERT 操作成功
Query OK, 1 row affected (0.00 sec)

mysql> update table1 set age=22 where name='Jack'; # UPDATE 操作成功
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select * from table1; # SELECT 操作成功
+------+------+
| name | age  |
+------+------+
| Tom  |   20 |
| Jack |   22 |
+------+------+
2 rows in set (0.00 sec)

mysql> delete from table1 where age=22; # DELETE 操作无权限
ERROR 1142 (42000): DELETE command denied to user 'user2'@'localhost' for table 'table1'

我们切换回 user1 管理账户,移除 user2 的 UPDATE 权限看看。

$ mysql -u user1 -p123456 test

mysql> revoke update on test.* from user2; # 移除 UPDATE 权限
Query OK, 0 rows affected (0.00 sec)

再次切换回 user2。

$ mysql -u user2 -p123456 test

mysql> show grants for user2; # UPDATE 权限被移除
+--------------------------------------------------------------------------------------------------+
| Grants for user2@%                                                                               |
+--------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'user2'@'%' IDENTIFIED BY PASSWORD '*6B...2AD9'                            |
| GRANT SELECT, INSERT ON `test`.* TO 'user2'@'%'                                                  |
+--------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> update table1 set age=23 where name='Jack'; # 不在拥有 UPDATE 权限
ERROR 1142 (42000): UPDATE command denied to user 'user2'@'localhost' for table 'table1'

好了,到此我们基本完成了创建用户和分配权限的操作。接下来,我们回到 root 进行修改用户密码和删除用户操作。

$ mysql -u root -p123456

mysql> set password for user3=password('abcabc'); # 修改用户 user3 密码
Query OK, 0 rows affected (0.00 sec)

mysql>flush privileges; # 刷新权限表(通常只在直接修改相关管理数据表后需要该操作)
Query OK, 0 rows affected (0.00 sec)

mysql> revoke all on *.* from user2; # 移除 user2 在所有数据库上的权限 
Query OK, 0 rows affected (0.00 sec)

mysql> drop user user2; # 删除 user2 账户
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from mysql.user; # 验证删除结果
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| user1            | %         |
| user3            | %         |
| root             | 127.0.0.1 |
| debian-sys-maint | localhost |
| root             | localhost |
| root             | server    |
+------------------+-----------+
6 rows in set (0.00 sec)

用户 user2 无法再次使用。

$ mysql -u user2 -p123456 test

ERROR 1045 (28000): Access denied for user 'user2'@'localhost' (using password: YES)

试试 user3。

$ mysql -u user3 -pabc test # 连接失败!哦,对了,我们修改了密码。
ERROR 1045 (28000): Access denied for user 'user3'@'localhost' (using password: YES)

$ mysql -u user3 -pabcabc test # 新密码成功

mysql> select * from table1; # SELECT 操作成功
+------+------+
| name | age  |
+------+------+
| Tom  |   20 |
| Jack |   22 |
+------+------+
2 rows in set (0.00 sec)

要修改自己的密码直接执行 “set password = password(‘new_password’);” 即可。

——- 摘要 ————————————–

创建用户:

GRANT insert, update ON testdb.* TO user1@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
CREATE USER user2 IDENTIFIED BY 'password';

分配权限:

GRANT select ON testdb.* TO user2;

查看权限:

SHOW GRANTS FOR user1;

修改密码:

SET PASSWORD FOR user1 = PASSWORD('newpwd');
SET PASSWORD = PASSWORD('newpwd');

移除权限:

REVOKE all ON *.* FROM user1;

删除用户:

DROP USER user1;

数据库列表:

SHOW DATABASES;

数据表列表:

SHOW TABLES;

当前数据库:

SELECT DATABASE();

当前用户:

SELECT USER();

数据表结构:

DESCRIBE table1;

刷新权限:

FLUSH PRIVILEGES;
发表在 mysql | 标签为 | 留下评论

zabbix_agentd监控配置说明

Agent 监控配置说明

 

Linux安装Agent

1.查看系统版本

查看系统版本

uname -a
1
根据系统版本下载对应的zabbix-agent版本安装
下载地址:http://repo.zabbix.com/zabbix

2.安装zabbix-agent

把下载好的rpm安装包拷贝到主机上
运行命令安装

rpm -ivh zabbix-agent-3.0.4-1.el7.x86_64.rpm
1
安装完成后设置开机自动启动

chkconfig zabbix-agent on
1
3.配置zabbix-agent

ServerActive=10.0.0.105(zabbix-server的IP地址)
Timeout=15(超时时间)
AllowRoot=1(允许以root运行)
UnsafeUserParameters=1(允许特殊字符)
UserParameter(配置自定义key)

详细配置详解

############ GENERAL PARAMETERS #################

### Option: PidFile
# Name of PID file.
#
# Mandatory: no
# Default:
# PidFile=/tmp/zabbix_agentd.pid

PidFile=/var/run/zabbix/zabbix_agentd.pid

PidFile
默认值:/tmp/zabbix_agentd.pid
PID文件名

### Option: LogType
# Specifies where log messages are written to:
# system – syslog
# file – file specified with LogFile parameter
# console – standard output
#
# Mandatory: no
# Default:
# LogType=file

LogType
指定日志消息写入的位置
system:syslog
file:使用LogFile参数指定的文件
console:标准输出

### Option: LogFile
# Log file name for LogType ‘file’ parameter.
#
# Mandatory: no
# Default:
# LogFile=

LogFile=/var/log/zabbix/zabbix_agentd.log

LogFile
日志文件路径
如果未配置,日志会记录到syslog中

### Option: LogFileSize
# Maximum size of log file in MB.
# 0 – disable automatic log rotation.
#
# Mandatory: no
# Range: 0-1024
# Default:
# LogFileSize=1
LogFileSize=0

LogFileSize
取值范围:0-1024
默认值:1
日志文件大小,单位为MB。
0 – 关闭自动轮滚.
备注:如果日志文件到达了最大值并且文件轮滚失败,那么老日志文件会被清空掉。

### Option: DebugLevel
# Specifies debug level:
# 0 – basic information about starting and stopping of Zabbix processes
# 1 – critical information
# 2 – error information
# 3 – warnings
# 4 – for debugging (produces lots of information)
# 5 – extended debugging (produces even more information)
#
# Mandatory: no
# Range: 0-5
# Default:
# DebugLevel=3

DebugLevel
取值范围:0-5
默认值:3
指定日志级别
0 – basic information about starting and stopping of Zabbix processes
1 – critical级别
2 – error级别
3 – warnings级别
4 – debug级别
5 – extended debugging (与级别4一样. 只能使用runtime control 来设置.)

### Option: SourceIP
# Source IP address for outgoing connections.
#
# Mandatory: no
# Default:
# SourceIP=

SourceIP
zabbix对外连接的出口IP地址

### Option: EnableRemoteCommands
# Whether remote commands from Zabbix server are allowed.
# 0 – not allowed
# 1 – allowed
#
# Mandatory: no
# Default:
# EnableRemoteCommands=0

EnableRemoteCommands
默认值:0
是否运行zabbix server在此服务器上执行远程命令
0 – 禁止
1 – 允许

### Option: LogRemoteCommands
# Enable logging of executed shell commands as warnings.
# 0 – disabled
# 1 – enabled
#
# Mandatory: no
# Default:
# LogRemoteCommands=0

LogRemoteCommands
默认值:0
记录原型执行的shell命令日志,级别为warrning
0 – disabled
1 – enabled

### Option: Server
# List of comma delimited IP addresses (or hostnames) of Zabbix servers.
# Incoming connections will be accepted only from the hosts listed here.
# If IPv6 support is enabled then ‘127.0.0.1’, ‘::127.0.0.1’, ‘::ffff:127.0.0.1’ are treated equally.
#
# Mandatory: no
# Default:
# Server=

Server=10.0.0.100

Server
zabbix server的ip地址,多个ip使用逗号分隔

### Option: ListenPort
# Agent will listen on this port for connections from the server.
#
# Mandatory: no
# Range: 1024-32767
# Default:
# ListenPort=10050

ListenPort
取值范围:1024-32767
默认值10050
监听端口

### Option: ListenIP
# List of comma delimited IP addresses that the agent should listen on.
# First IP address is sent to Zabbix server if connecting to it to retrieve list of active checks.
#
# Mandatory: no
# Default:
# ListenIP=0.0.0.0

ListenIP
默认值:0.0.0.0
监听IP地址,默认为所有接口,多个ip之间使用逗号分隔

### Option: StartAgents
# Number of pre-forked instances of zabbix_agentd that process passive checks.
# If set to 0, disables passive checks and the agent will not listen on any TCP port.
#
# Mandatory: no
# Range: 0-100
# Default:
# StartAgents=3

StartAgents
取值范围:0-100
默认值:3
zabbix启动之后开启被动监控的进程数量,如果设置为0,那么zabbix被动监控被禁用,并且不会监听相应端口,也就是说10050端口不会开启。

### Option: ServerActive
# List of comma delimited IP:port (or hostname:port) pairs of Zabbix servers for active checks.
# If port is not specified, default port is used.
# IPv6 addresses must be enclosed in square brackets if port for that host is specified.
# If port is not specified, square brackets for IPv6 addresses are optional.
# If this parameter is not specified, active checks are disabled.
# Example: ServerActive=127.0.0.1:20051,zabbix.domain,[::1]:30051,::1,[12fc::1]
#
# Mandatory: no
# Default:
# ServerActive=

ServerActive=10.0.0.100:10052

ServerActive
zabbix 主动监控server的ip地址,使用逗号分隔多IP,如果注释这个选项,那么当前服务器的主动监控就被禁用了

### Option: Hostname
# Unique, case sensitive hostname.
# Required for active checks and must match hostname as configured on the server.
# Value is acquired from HostnameItem if undefined.
#
# Mandatory: no
# Default:
# Hostname=

Hostname
默认值:HostnameItem配置的值
主机名,必须唯一,区分大小写。Hostname必须和zabbix web上配置的一直,否则zabbix主动监控无法正常工作。为什么呢?因为agent拿着这个主机名去问server,我有配置主动监控项 吗?server拿着这个主机名去配置里面查询,然后返回信息。
支持字符:数字字母、’.’、’ ‘、 ‘_’、 ‘-‘,不超过64个字符

### Option: HostnameItem
# Item used for generating Hostname if it is undefined. Ignored if Hostname is defined.
# Does not support UserParameters or aliases.
#
# Mandatory: no
# Default:
# HostnameItem=system.hostname

HostnameItem
默认值:system.hostname
设置主机名,只有当HostMetadata没设置,她才生效。不支持UserParameters 、aliases,支持system.run[]

### Option: HostMetadata
# Optional parameter that defines host metadata.
# Host metadata is used at host auto-registration process.
# An agent will issue an error and not start if the value is over limit of 255 characters.
# If not defined, value will be acquired from HostMetadataItem.
#
# Mandatory: no
# Range: 0-255 characters
# Default:
# HostMetadata=

HostMetadata
取值范围:0-255 字符
仅用于主机自动注册功能,如果当前值为定义,那么它的值默认为HostMetadataItem的值。这个选项在2.2.0之后加入,并且确保支付不能超过限制,以及字符串必须是UTF8,否则服务器无法启动

### Option: HostMetadataItem
# Optional parameter that defines an item used for getting host metadata.
# Host metadata is used at host auto-registration process.
# During an auto-registration request an agent will log a warning message if
# the value returned by specified item is over limit of 255 characters.
# This option is only used when HostMetadata is not defined.
#
# Mandatory: no
# Default:
# HostMetadataItem=

HostMetadataItem
功能同上,如果HostMetadata值未设置,这个配置才有效。支持使用UserParameters、alias、system.run[]

### Option: RefreshActiveChecks
# How often list of active checks is refreshed, in seconds.
#
# Mandatory: no
# Range: 60-3600
# Default:
# RefreshActiveChecks=120

RefreshActiveChecks
取值范围:60-3600
默认值:120
多久时间(秒)刷新一次主动监控配置信息,如果刷新失败,那么60秒之后会重试一次

### Option: BufferSend
# Do not keep data longer than N seconds in buffer.
#
# Mandatory: no
# Range: 1-3600
# Default:
# BufferSend=5

BufferSend
取值范围:1-3600
默认值:5
数据存储在buffer中最长多少秒

### Option: BufferSize
# Maximum number of values in a memory buffer. The agent will send
# all collected data to Zabbix Server or Proxy if the buffer is full.
#
# Mandatory: no
# Range: 2-65535
# Default:
# BufferSize=100

BufferSize
取值范围:2-65535
默认值:100
buffer最大值,如果buffer满了,zabbix将会将检索到的数据发送给zabbix server或者proxy

### Option: MaxLinesPerSecond
# Maximum number of new lines the agent will send per second to Zabbix Server
# or Proxy processing ‘log’ and ‘logrt’ active checks.
# The provided value will be overridden by the parameter ‘maxlines’,
# provided in ‘log’ or ‘logrt’ item keys.
#
# Mandatory: no
# Range: 1-1000
# Default:
# MaxLinesPerSecond=20

MaxLinesPerSecond
取值范围:1-1000
默认值:20
处理监控类型为log何eventlog日志时,agent每秒最大发送的行数。默认为20行

### Option: Alias
# Sets an alias for an item key. It can be used to substitute long and complex item key with a smaller and simpler one.
# Multiple Alias parameters may be present. Multiple parameters with the same Alias key are not allowed.
# Different Alias keys may reference the same item key.
# For example, to retrieve the ID of user ‘zabbix’:
# Alias=zabbix.userid:vfs.file.regexp[/etc/passwd,^zabbix:.:([0-9]+),,,,\1]
# Now shorthand key zabbix.userid may be used to retrieve data.
# Aliases can be used in HostMetadataItem but not in HostnameItem parameters.
#
# Mandatory: no
# Range:
# Default:

Alias
key的别名,例如 Alias=ttlsa.userid:vfs.file.regexp[/etc/passwd,^ttlsa:.:([0-9]+),,,,\1], 或者ttlsa的用户ID。你可以使用key:vfs.file.regexp[/etc/passwd,^ttlsa:.: ([0-9]+),,,,\1],也可以使用ttlsa.userid。

备注: 别名不能重复,但是可以有多个alias对应同一个key。

### Option: Timeout
# Spend no more than Timeout seconds on processing
#
# Mandatory: no
# Range: 1-30
# Default:
# Timeout=3

Timeout
默认值:1-30
默认值:3
超时时间

### Option: AllowRoot
# Allow the agent to run as ‘root’. If disabled and the agent is started by ‘root’, the agent
# will try to switch to the user specified by the User configuration option instead.
# Has no effect if started under a regular user.
# 0 – do not allow
# 1 – allow
#
# Mandatory: no
# Default:
# AllowRoot=0
AllowRoot=1

AllowRoot
默认值:0
是否允许使用root身份运行zabbix,如果值为0,并且是在root环境下,zabbix会尝试使用zabbix用户运行,如果不存在会告知zabbix用户不存在。
0 – 不允许
1 – 允许

### Option: User
# Drop privileges to a specific, existing user on the system.
# Only has effect if run as ‘root’ and AllowRoot is disabled.
#
# Mandatory: no
# Default:
# User=zabbix

User
默认值:zabbix
运行zabbix程序的用户,如果AllowRoot被禁用,才有效果

### Option: Include
# You may include individual files or all files in a directory in the configuration file.
# Installing Zabbix will create include directory in /usr/local/etc, unless modified during the compile time.
#
# Mandatory: no
# Default:
# Include=

Include=/etc/zabbix/zabbix_agentd.d/

# Include=/usr/local/etc/zabbix_agentd.userparams.conf
# Include=/usr/local/etc/zabbix_agentd.conf.d/
# Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf

nclude
包含自配置文件,不同的配置写到不同的文件中,然后include,配置文件会显得规范。例如: /absolute/path/to/config/files/*.conf. Zabbix 2.4.0开始支持正则表达式。

### Option: UnsafeUserParameters
# Allow all characters to be passed in arguments to user-defined parameters.
# The following characters are not allowed:
# \ ‘ ” ` * ? [ ] { } ~ $ ! & ; ( ) < > | # @
# Additionally, newline characters are not allowed.
# 0 – do not allow
# 1 – allow
#
# Mandatory: no
# Range: 0-1
# Default:
# UnsafeUserParameters=0
UnsafeUserParameters=1

UnsafeUserParameters
取值范围:0,1
默认值: 0
允许所有字符的参数传递给用户定义的参数(包括特殊字符)。

### Option: UserParameter
# User-defined parameter to monitor. There can be several user-defined parameters.
# Format: UserParameter=<key>,<shell command>
# See ‘zabbix_agentd’ directory for examples.
#
# Mandatory: no
# Default:
# UserParameter=
UserParameter=system.cpu.steal,nproc
UserParameter=dskTotal[*],python /root/disk.py $1 $2
UserParameter=ifNumber,/etc/init.d/network status |awk ‘NR==4’|awk -v RS=”@#$j” ‘{print gsub(/ /,”&”)+1}’
UserParameter=ifInQLen[*],ethtool -S $1 |grep ‘Tx Queue#:’|awk ‘{print $2 3}’
UserParameter=ifOutQLen[*],ethtool -S $1 |grep ‘Rx Queue#:’|awk ‘{print $2 3}’
UserParameter=ifStatus[*],python /root/Net.py $1 $2

UserParameter
用户自定义key,格式: UserParameter=,
例如:serParameter=system.test,who|wc -l

### Option: LoadModulePath
# Full path to location of agent modules.
# Default depends on compilation options.
#
# Mandatory: no
# Default:
# LoadModulePath=${libdir}/modules

LoadModulePath
模块路径,绝对路径

### Option: LoadModule
# Module to load at agent startup. Modules are used to extend functionality of the agent.
# Format: LoadModule=<module.so>
# The modules must be located in directory specified by LoadModulePath.
# It is allowed to include multiple LoadModule parameters.
#
# Mandatory: no
# Default:
# LoadModule=

LoadModule
加载模块文件,可以写多个
格式: LoadModule=
必须配置LoadModulePath,指定模块目录

####### TLS-RELATED PARAMETERS #######

### Option: TLSConnect
# How the agent should connect to server or proxy. Used for active checks.
# Only one value can be specified:
# unencrypted – connect without encryption
# psk – connect using TLS and a pre-shared key
# cert – connect using TLS and a certificate
#
# Mandatory: yes, if TLS certificate or PSK parameters are defined (even for ‘unencrypted’ connection)
# Default:
# TLSConnect=unencrypted

### Option: TLSAccept
# What incoming connections to accept.
# Multiple values can be specified, separated by comma:
# unencrypted – accept connections without encryption
# psk – accept connections secured with TLS and a pre-shared key
# cert – accept connections secured with TLS and a certificate
#
# Mandatory: yes, if TLS certificate or PSK parameters are defined (even for ‘unencrypted’ connection)
# Default:
# TLSAccept=unencrypted

### Option: TLSCAFile
# Full pathname of a file containing the top-level CA(s) certificates for
# peer certificate verification.
#
# Mandatory: no
# Default:
# TLSCAFile=

### Option: TLSCRLFile
# Full pathname of a file containing revoked certificates.
#
# Mandatory: no
# Default:
# TLSCRLFile=

### Option: TLSServerCertIssuer
# Allowed server certificate issuer.
#
# Mandatory: no
# Default:
# TLSServerCertIssuer=

### Option: TLSServerCertSubject
# Allowed server certificate subject.
#
# Mandatory: no
# Default:
# TLSServerCertSubject=

### Option: TLSCertFile
# Full pathname of a file containing the agent certificate or certificate chain.
#
# Mandatory: no
# Default:
# TLSCertFile=

### Option: TLSKeyFile
# Full pathname of a file containing the agent private key.
#
# Mandatory: no
# Default:
# TLSKeyFile=

### Option: TLSPSKIdentity
# Unique, case sensitive string used to identify the pre-shared key.
#
# Mandatory: no
# Default:
# TLSPSKIdentity=

### Option: TLSPSKFile
# Full pathname of a file containing the pre-shared key.
#
# Mandatory: no
# Default:
# TLSPSKFile=

windows安装Agent

1.下载zabbix-agent压缩包

下载地址:http://www.zabbix.com/download

2.安装zabbix-agent

1)在非C盘的任意盘创建zabbix文件夹(以D盘为例)
2)解压下载的zabbix-agent文件,根据系统是64位还是32位系统,选择对应版本(以64位为例)
3)将解压出来的文件夹下的 bin\win64 文件夹中的文件拷贝到创建的zabbix文件夹下
4)将解压出来的文件夹下的 conf 文件夹拷贝到创建的zabbix文件夹下
5)打开 zabbix\conf\ 下的zabbix_agentd.win.conf 修改配置(方法同上)
6)修改好后保存退出,打开终端,运行

D:\zabbix\zabbix_agentd.exe -c D:\zabbix\conf\zabbix_agentd.win.conf -i

D:\zabbix\zabbix_agentd.exe -c D:\zabbix\conf\zabbix_agentd.win.conf -s

-i 安装
-d 卸载
-s 启动
-x 停止
-h 帮助
-c 配置文件位置
注意: 关闭防火墙,或者开放指定端口

转自:http://blog.csdn.net/qq_28426351/article/details/53485435

发表在 zabbix | 标签为 | 留下评论