Zabbix分佈式監控--Mysql安裝

1、安裝環境
node

主機角色 主機IP VIP 操做系統版本 軟件版本
ServerA(Master) 192.168.1.101

192.168.1.100mysql

(keepalived+腳本)c++

CentOS 6.5 64bit Zabbix-2.2.4
ServerB(Backup) 192.168.1.102 CentOS 6.5 64bit Zabbix-2.2.4
Master A 192.168.1.97

(主從)sql

CentOS 6.5 64bit mysql-5.6.21
Slave B 192.168.1.98 CentOS 6.5 64bit mysql-5.6.21

2、架構圖
數據庫

架構詳見:http://51ctoo.blog.51cto.com/5742811/1697547緩存


3、Mysql安裝
安全

1. 建立目錄和安裝依賴包

提早規劃好數據庫安裝目錄,具體以下:bash

安裝目錄:prefix dir架構

/usr/local/mysql/

sock目錄:socket

/var/lib/mysql/mysql.sock

數據目錄datadir

/data/ismdata/

Innodb數據目錄

/data/idbdata

相關Logs目錄:

/data/myqllog/slowlog/slow.log
/data/mysqllog/errorlog/log-error.log
/data/mysqllog/binlog/master-bin.log


建立相應目錄並安裝基礎包:

mkdir -p /data/{ismdata,idbdata,mysqllog}
yuminstall sudo gdb ethtool ntp sysstat htop ntpdate irqbalance ncftp straceltrace hal gcc g++ cmake make bison libncurses5-dev gcc-c++ ncurses-devel
groupadd-g 900 mysql
useraddmysql -u 900 -g mysql -s /sbin/nologin
chownmysql.mysql -R /data/ismdata
chownmysql.mysql -R /data/idbdata
chownmysql.mysql -R /data/mysqllog


2. 解壓編譯安裝mysql


tar zxvf mysql-5.6.21.tar.gz 
cd mysql-5.6.21
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ 
-DMYSQL_DATADIR=/data/ismdata/-DENABLED_LOCAL_INFILE=1 
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock-DWITH_DEBUG=0 
-DMYSQL_USER=mysql 
-DMYSQL_TCP_PORT=3306  
-DWITH_READLINE=1
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 
-DWITH_INNOBASE_STORAGE-ENGINE=1
-DWITH_MYISAM_STORAGE_ENGINE=1 
-DWITH_MEMORY_STORAGE_ENGINE=1 
-DWITH_PARTITION_STORAGE_ENGINE=1
-DDEFAULT_CHARSET=utf8 
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk
-DENABLE_DOWNLOADS=1
make -j 4
make install
這裏編輯my.cnf文件
chmod 755scripts/mysql_install_db
./scripts/mysql_install_db --user=mysql--basedir=/usr/local/mysql --datadir=/data/ismdata
cp support-files/mysql.server /etc/init.d/mysqld && chmod u+x /etc/init.d/mysqld &&chkconfig --add mysqld
ln -s /usr/local/mysql/bin/mysql /usr/bin/

3.設密碼

use mysql
grant all privileges on *.* to root@"%" identified by "EhqW{OZzdsfwe";
update user set password= password('EhqW{OZzdsfwe') where user='root';
flush privileges;


4.安全相關設置

#/usr/local/mysql/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current password for the root user.  If you've just installed MySQL, and you haven't set the root password yet, the password will be blank,so you should just press enter here.
Enter current password for root (enter for none): 
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n] n
 ... skipping.
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
 ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
 ... skipping.
By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
 ... Success!
All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...


5.mysql主從配置

Mysql從5.6版本開始,能夠直接進行配置,而無需鎖表複製文件了。

Master上配置:

grant replication slave on *.* torepuser@'172.29.31.%' identified by "XXXXXXX";
stop slave;
reset master;


Slave上配置:

stop slave;
reset slave;
Change master tomaster_host='172.29.31.111',master_user='repuser',master_password='XXXXX',master_auto_position=1;
start slave;



6.mysqlDB分表,去housekeeping(等後面zabbix server安裝完成後再來進行)



最後附上my.cnf文件

[client]
port            = 3306
socket            = /var/lib/mysql/mysql.sock
[mysqld]
socket            = /var/lib/mysql/mysql.sock
port            = 3306
tmpdir                      = /tmp/tmpmysql
#character set,5.6version set utf8
character_set_server=utf8
init_connect='set names utf8'
skip-character-set-client-handshake=1
#deafault engine
default_storage_engine  = InnoDB
#log info
slow_query_log        = 1
slow_query_log_file     = /data/mysqllog/slowlog/slowquery.log
long_query_time       = 2
log-error          = /data/mysqllog/errorlog/log-error.log
skip-external-locking
log_warnings
back_log = 300
# fine tuning
skip-name-resolve
max_connections       = 5000
max_allowed_packet       = 32M
max_heap_table_size     = 128M
key_buffer_size       = 128M
sort_buffer_size       = 16M
join_buffer_size       = 16M
net_buffer_length      = 8K
read_buffer_size       = 128M
read_rnd_buffer_size     = 128M
myisam_sort_buffer_size     = 8M
thread_cache_size      = 16
#thread_concurrency     = 24
table_open_cache       = 4096
#mysql 5.6 new feature
explicit_defaults_for_timestamp=true
# * Query Cache Configuration
query_cache_limit       = 4M
query_cache_size       = 4096M
query_cache_type       = 1
tmp_table_size        = 128M
#innodb settings
innodb_data_home_dir         = /data/idbdata
innodb_log_group_home_dir    = /data/idbdata/
innodb_data_file_path        = ibdata1:100M:autoextend
innodb_fast_shutdown         = 1
innodb_file_per_table      = 1
innodb_file_io_threads      = 4
innodb_open_files       = 2048
innodb_buffer_pool_size      = 10G  
#innodb_additional_mem_pool_size = 16M
innodb_thread_concurrency    = 16
innodb_max_dirty_pages_pct   = 90
innodb_log_buffer_size       = 8M
innodb_flush_log_at_trx_commit = 2
innodb_flush_method       = 0_DIRECT
innodb_lock_wait_timeout     = 10
innodb_log_files_in_group   = 2
innodb_log_file_size     = 64M
innodb_flush_log_at_trx_commit= 0
innodb_autoextend_increment  = 256
innodb_buffer_pool_instances = 12
innodb_concurrency_tickets  = 5000
innodb_old_blocks_time    = 1000
innodb_lock_wait_timeout   = 50
#log-bin settings
log-bin            = /data/mysqllog/binlog/master-bin.log
expire_logs_days       = 5
binlog_cache_size       = 1M
max_binlog_size        = 10M
[mysqldump]
# Do not buffer the whole result set in memory before writing it to
# file. Required for dumping very large tables
quick
#quote-names
max_allowed_packet      = 64M
max_connect_errors      =1000
[mysql]
no-auto-rehash # faster start of mysql but no tab completition
[isamchk]
key_buffer = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[myisamchk]
key_buffer = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout

注意事項和要點:

a、使用tmpfs存儲臨時文件

mkdir /tmp/tmpmysql
修改/etc/fstab:
tmfs /tmp/tmpmysql tmpfs rw,uid=mysql,gid=mysql,size=1G,nr_inodes=10k,mode=0700 0 0
修改my.cnf
tmpdir=/tmp/tmpmysql


b、設置正確的buffer pool

設置Innodb可用多少內存,建議設置成物理內存的70%~80%
innodb_buffer_pool_size=10G


c、設置innodb使用O_DIRECT

這樣buffer_pool中的數據就不會與系統緩存中的重複。
innodb_flush_method=O_DIRECT


d、設置合適的log大小

zabbix數據庫屬於寫入較多的數據庫,所以設置大一點能夠避免MySQL持續將log文件flush到表中。
不過有一個反作用,就是啓動和關閉數據庫會變慢一點。
innodb_log_file_size=64M


e、打開慢查詢日誌

log_slow_queries=/data/mysqllog/slowquery.log


f、設置innodb_file_per_table

innodb_file_per_table      = 1
相關文章
相關標籤/搜索