当前位置:Gxlcms > 数据库问题 > saltstack的深入-测试saltstack配置zabbix所需的mysql-server

saltstack的深入-测试saltstack配置zabbix所需的mysql-server

时间:2021-07-01 10:21:17 帮助过:30人阅读

saltstack的深入-测试saltstack配置zabbix所需的mysql-server

操作内容:
一、基础环境
1、使用tvm-cobbler安装一个tvm-zabbix虚拟机来做实验。
2、网络:
eth0:host-only(用于虚拟内网,手动固定IP,这样从宿主机可以直接连接到这个vm)
eth1:NAT(用于上外网,动态IP)
[root@tvm-zabbix ~]# cd /etc/sysconfig/network-scripts/
[root@tvm-zabbix network-scripts]# cat ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.56.200
PREFIX=24
GATEWAY=192.168.56.1
DNS1=192.168.56.254

[root@tvm-zabbix network-scripts]# cat ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
DNS1=192.168.56.254

[root@tvm-zabbix ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        36G  1.8G   32G   6% /
tmpfs           499M   12K  499M   1% /dev/shm
/dev/sda1       194M   29M  155M  16% /boot
/dev/sdb1        99G  188M   94G   1% /data


使用域名:
[root@tvm-yum ~]# cat /etc/dnsmasq.d/office.conf |grep zbx-m
address=/zbx-m.office.test/192.168.56.200

3、repo
我们在自己的office这个repo中已经增加了几个rpm包:
[root@tvm-zabbix data]# yum search --disablerepo=\* --enablerepo=office percona
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
======================================================================================= N/S Matched: percona =======================================================================================
Percona-Server-55-debuginfo.x86_64 : Debug information for package Percona-Server-55
Percona-Server-client-55.x86_64 : Percona Server - Client
Percona-Server-devel-55.x86_64 : Percona Server - Development header files and libraries
Percona-Server-server-55.x86_64 : Percona Server: a very fast and reliable SQL database server
Percona-Server-shared-55.x86_64 : Percona Server - Shared libraries
Percona-Server-test-55.x86_64 : Percona Server - Test suite
percona-zabbix-templates.noarch : Percona Monitoring Plugins for Zabbix

  Name and summary matches only, use "search all" for everything.

二、配置
1、sls文件
[root@tvm-saltmaster base]# cat mysql/server.sls    
## 安装mysql-server,以及对应的zabbix监控相关文件。
# 
# via pc @ 2015/8/12

Percona-Server:
  pkg.installed:
## for local-office.repo
#
    - fromrepo: office,base,repo
    - name: zabbix-agent
    - skip_verify: True
    - refresh: True
    - pkgs:
## for percona-server
#      
      - Percona-Server-55-debuginfo
      - Percona-Server-client-55
      - Percona-Server-devel-55
      - Percona-Server-server-55
      - Percona-Server-shared-55
      - Percona-Server-test-55
      - percona-zabbix-templates
## for zabbix
# Scripts are installed to /var/lib/zabbix/percona/scripts
# Templates are installed to /var/lib/zabbix/percona/templates
#
# /var/lib/zabbix/percona/scripts:
# total 64
# -rwxr-xr-x 1 root root  1251 Jul 21  2014 get_mysql_stats_wrapper.sh
# -rwxr-xr-x 1 root root 58226 Jul 21  2014 ss_get_mysql_stats.php
#
# /var/lib/zabbix/percona/templates:
# total 284
# -rw-r--r-- 1 root root  18866 Jul 21  2014 userparameter_percona_mysql.conf
# -rw-r--r-- 1 root root 269258 Jul 21  2014 zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.4.xml
# 
      - php
      - php-mysql

/etc/my.cnf:
  file.managed:
    - source: salt://conf.d/mysql/my.cnf
    - mode: 644
    - require:
      - pkg: Percona-Server

/data/mysql:
  file.directory:
    - user: mysql
    - group: mysql
    - mode: 755
    - makedirs: True
    - require:
      - pkg: Percona-Server

run-mysql:
## Installing MySQL system tables
# PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
# /usr/bin/mysqladmin -u root password ‘new-password‘
  cmd.run:
    - name: /usr/bin/mysql_install_db
    - onlyif:
      - d_mysql=$(grep ‘datadir‘ /etc/my.cnf |cut -d‘=‘ -f2);
        d_mysql_install="${d_mysql}/mysql";
        test ! -d ${d_mysql_install}
  service.running:
    - name: mysql
    - enable: True
    - require:
      - pkg: Percona-Server

## for zabbix
percona_zabbix_php:
  file.managed:
    - name: /etc/php.ini
    - source: salt://conf.d/mysql/percona_zabbix_php.ini
    - mode: 755
    - require:
      - pkg: Percona-Server

## for zabbix
# notice! password need to be protected in file: ss_get_mysql_stats.php
ss_get_mysql_stats:
  file.managed:
    - name: /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
    - source: salt://conf.d/mysql/ss_get_mysql_stats.php
    - mode: 770
    - require:
      - pkg: Percona-Server



2、conf文件
[root@tvm-saltmaster base]# tree conf.d/mysql/
conf.d/mysql/
├── my.cnf
├── percona_zabbix_php.ini
└── ss_get_mysql_stats.php

0 directories, 3 files

[root@tvm-saltmaster base]# cat conf.d/mysql/my.cnf 
[mysqld]
# GENERAL
datadir=/data/mysql
socket=/data/mysql/mysql.sock
pid_file=/data/mysql/mysqld.pid
user=mysql
port=3306
#enforce_storage_engine=InnoDB
default-storage-engine=InnoDB
character_set_server=utf8

# InnoDB
innodb_buffer_pool_size=2G
innodb_flush_method=O_DIRECT
innodb_file_per_table=1
innodb_open_files=500
innodb_log_buffer_size=128M
innodb_log_file_size=256M
innodb_stats_on_metadata=OFF
innodb_support_xa=OFF
innodb_thread_concurrency=0
innodb_io_capacity=200

# MyISAM
key_buffer_size=128M

#BINLOG
server_id=10
log_bin=/data/mysql/mysql-bin
binlog_format=mixed
#replicate-do-db=cdn
#replicate-ignore-db=mysql
#replicate-ignore-db=test
#relay_log=/data/mysql/relay-log

# LOGGING
log_error=/data/mysql/mysql-error.log
slow_query_log=ON
long_query_time=2
slow_query_log_file=/data/mysql/mysql-slow
##These two variables are only for Percona
max_slowlog_files=5
max_slowlog_size=100M
expire_logs_days=14

# OTHER
tmp_table_size=32M
max_heap_table_size=32M
open_files_limit=600000
query_cache_type=0
query_cache_size=0
thread_cache_size=64
table_definition_cache=500
table_open_cache=1000
max_allowed_packet=16M
max_connections=800
max_user_connections=400
max_connect_errors=99999999
skip_name_resolve

[client]
default_character_set=utf8
socket=/data/mysql/mysql.sock

其他2个文件,主要是mysql相关的配置要调整:
[root@tvm-saltmaster base]# grep ‘mysql.sock‘ conf.d/mysql/percona_zabbix_php.ini 
mysql.default_socket = /data/mysql/mysql.sock
mysqli.default_socket = /data/mysql/mysql.sock

[root@tvm-saltmaster base]# grep -E ‘^\$mysql_(u|p)‘ conf.d/mysql/ss_get_mysql_stats.php 
$mysql_user = ‘zabbix_ro‘;
$mysql_pass = ‘xxx‘;
$mysql_port = 3306;


三、执行
[root@tvm-saltmaster base]# salt ‘tvm-zabbix‘ state.sls mysql.server --output-file=‘/tmp/salt.log‘ 


四、注意事项
如果我们在另一个shell中,开启了salt-minion的debug日志,而同时,我们的salt-minion服务并未结束,此时有多个salt-minion:
[root@tvm-zabbix data]# salt-minion -l debug
[root@tvm-zabbix ~]# ps -ef |grep salt
root     31623     1  0 16:45 ?        00:00:01 /usr/bin/python2.6 /usr/bin/salt-minion -d
root     31882  1205  0 17:04 pts/0    00:00:00 /usr/bin/python2.6 /usr/bin/salt-minion -l debug
root     31885 31882  1 17:04 pts/0    00:00:00 /usr/bin/python2.6 /usr/bin/salt-minion -l debug
root     32083 29908  0 17:05 pts/1    00:00:00 grep salt


则,在salt-master上执行salt命令可能会出现如下的异常:

[root@tvm-saltmaster base]# salt ‘tvm-zabbix‘ state.sls mysql.server --output-file=‘/tmp/salt.log‘ 
[root@tvm-saltmaster base]# cat /tmp/salt.log 
tvm-zabbix:
    Data failed to compile:
----------
    The function "state.sls" is running as PID 32031 and was started at 2015, Aug 12 17:04:42.900197 with jid 20150812170442900197

因此,建议的做法是,先关闭monit和salt-minion服务,然后再手动启动debug模式的salt-minion服务:
service monit stop
service salt-minion stop
salt-minion -l debug



ZYXW、参考
1、老大提供的资料。


saltstack的深入-测试saltstack配置zabbix所需的mysql-server

标签:mysql   saltstack   highstate   

人气教程排行