<![CDATA[安装部署 Zabbix]]> %2F2017%2F11%2F17%2Finstall-zabbix%2F create database zabbix character set utf8 collate utf8_bin; mysql> GRANT ALL privileges ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY 'zabbix'; mysql> GRANT ALL privileges ON zabbix.* TO 'zabbix'@'%' IDENTIFIED BY 'zabbix'; mysql> flush privileges; mysql> quit; # cd /usr/share/doc/zabbix-server-mysql-3.2.1 # zcat create.sql.gz | mysql -uzabbix -Pzabbix zabbix ``` `zcat create.sql.gz | mysql -uzabbix -Pzabbix zabbix` 是把 Zabbix server 的初始化脚本写入 MySQL 数据库,这里执行完可以进入 MySQL 看下数据有没有写成功。 ### 4. 配置 Zabbix server 参数 修改配置文件,使其使用安装好的 MySQL。 ``` # vi /etc/zabbix/zabbix_server.conf LogFile=/var/log/zabbix/zabbix_server.log DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=zabbix ``` ### 5. 启动 Zabbix server 安装完成后既可启动 Zabbix server 服务了。 ``` # service zabbix-server start ``` 日志目录:`LogFile=/var/log/zabbix/zabbix_server.log` 检查进程和日志是否正常启动成功: ``` # ps -ef|grep zabbix_server # netstat -lntup | grep 10051 # tail -f /var/log/zabbix/zabbix_server.log ``` Zabbix server 启动端口为 10051。 若服务器打开 iptables 服务,则需添加该两个端口通行。 ``` # iptables -A INPUT -p tcp --dport 10050 -j ACCEPT # iptables -A INPUT -p tcp --dport 10051 -j ACCEPT ``` ## 安装 Zabbix agent ### 1. 安装 rpm 包 下载需要的 rpm 包 ``` # wget http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-agent-3.2.1-1.el6.x86_64.rpm ``` ``` # yum install zabbix-agent-3.2.1-1.el6.x86_64.rpm ``` ### 2. 配置 Zabbix agent ``` # vi /etc/zabbix/zabbix_agentd.conf LogFile=/var/log/zabbix/zabbix_agentd.log Server=127.0.0.1 UnsafeUserParameters=1 ``` 上述配置中的 Server 指向 Zabbix Server 的地址,如果是本机的话则采用 `127.0.0.1` ### 3. 启动 Zabbix agent ``` # service zabbix-agent start ``` 日志目录:`LogFile=/var/log/zabbix/zabbix_agentd.log` 检查进程和日志是否正常启动成功 ``` # ps -ef|grep zabbix_agentd # netstat -lntup | grep 10050 # tail -f /var/log/zabbix/zabbix_agentd.log ``` Zabbix agentd 启动端口为 10050。 ## 安装 Zabbix web Zabbix 3.2 对 PHP 的要求最低为 5.4,而 CentOS6 默认为 5.3.3,完全不满足要求,故需要利用第三方源将 PHP 升级到 5.4 以上。(注意:同时不支持 PHP7) ### 1. 卸载本地 PHP 版本 检查本机的 PHP 版本,如果 < 5.4 需要卸载重新安装 ``` # yum erase php php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mcrypt php-mbstring php-devel php-pecl-memcached php-pecl-memcache php-common php-pdo php-cli php-fpm libmemcached ``` ### 2. 下载 rpm 包 ``` # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-5.6.28-1.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-mysql-5.6.28-1.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-gd-5.6.28-1.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-imap-5.6.28-1.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-ldap-5.6.28-1.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-odbc-5.6.28-1.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-xml-5.6.28-1.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-xmlrpc-5.6.28-1.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-mcrypt-5.6.28-1.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-mbstring-5.6.28-1.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-devel-5.6.28-1.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-pecl-memcached-2.2.0-2.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-common-5.6.28-1.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-pdo-5.6.28-1.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-cli-5.6.28-1.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-pecl-memcache-3.0.8-2.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-bcmath-5.6.28-1.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-fpm-5.6.28-1.w6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/libmemcached10-1.0.16-1.ius.el6.x86_64.rpm # wget https://repo.webtatic.com/yum/el6/x86_64/php56w-pecl-igbinary-1.2.1-2.w6.x86_64.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/apr-util-ldap-1.3.9-3.el6_0.1.x86_64.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/freetype-2.3.11-17.el6.x86_64.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libX11-1.6.3-2.el6.x86_64.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libX11-common-1.6.3-2.el6.noarch.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libXau-1.0.6-4.el6.x86_64.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libXpm-3.5.10-2.el6.x86_64.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libc-client-2007e-11.el6.x86_64.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libjpeg-turbo-1.2.1-3.el6_5.x86_64.rpm # wget ftp://mirror.switch.ch/pool/4/mirror/epel/6/x86_64/libmcrypt-2.5.8-9.el6.x86_64.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libpng-1.2.49-2.el6_7.x86_64.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libxcb-1.11-2.el6.x86_64.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libxslt-1.1.26-2.el6_3.1.x86_64.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/mailcap-2.1.31-2.el6.noarch.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/pcre-devel-7.8-7.el6.x86_64.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/t1lib-5.1.2-6.el6_2.1.x86_64.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/pcre-7.8-7.el6.x86_64.rpm # wget https://raw.githubusercontent.com/zabbixcn/curl-rpm/master/RPMS/libcurl-devel-7.29.0-25.el6.x86_64.rpm # wget https://raw.githubusercontent.com/zabbixcn/curl-rpm/master/RPMS/libcurl-7.29.0-25.el6.x86_64.rpm # wget https://raw.githubusercontent.com/zabbixcn/curl-rpm/master/RPMS/curl-7.29.0-25.el6.x86_64.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/dejavu-fonts-common-2.33-1.el6.noarch.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/dejavu-sans-fonts-2.33-1.el6.noarch.rpm # wget http://mirror.centos.org/centos/6/os/x86_64/Packages/fontpackages-filesystem-1.41-1.1.el6.noarch.rpm # wget http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/deprecated/zabbix-web-mysql-3.2.1-1.el6.noarch.rpm # wget http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/deprecated/zabbix-web-3.2.1-1.el6.noarch.rpm ``` ### 3. 安装 PHP & Apache & CURL 先安装依赖包 ``` # yum install apr-util-ldap-1.3.9-3.el6_0.1.x86_64.rpm freetype-2.3.11-17.el6.x86_64.rpm libX11-1.6.3-2.el6.x86_64.rpm libX11-common-1.6.3-2.el6.noarch.rpm libXau-1.0.6-4.el6.x86_64.rpm libXpm-3.5.10-2.el6.x86_64.rpm libc-client-2007e-11.el6.x86_64.rpm libjpeg-turbo-1.2.1-3.el6_5.x86_64.rpm libmcrypt-2.5.8-9.el6.x86_64.rpm libpng-1.2.49-2.el6_7.x86_64.rpm libxcb-1.11-2.el6.x86_64.rpm libxslt-1.1.26-2.el6_3.1.x86_64.rpm mailcap-2.1.31-2.el6.noarch.rpm pcre-devel-7.8-7.el6.x86_64.rpm t1lib-5.1.2-6.el6_2.1.x86_64.rpm pcre-7.8-7.el6.x86_64.rpm dejavu-fonts-common-2.33-1.el6.noarch.rpm dejavu-sans-fonts-2.33-1.el6.noarch.rpm fontpackages-filesystem-1.41-1.1.el6.noarch.rpm ``` 安装 5.6 版本的 PHP ``` # yum install php56w-5.6.28-1.w6.x86_64.rpm php56w-mysql-5.6.28-1.w6.x86_64.rpm php56w-gd-5.6.28-1.w6.x86_64.rpm php56w-imap-5.6.28-1.w6.x86_64.rpm php56w-ldap-5.6.28-1.w6.x86_64.rpm php56w-odbc-5.6.28-1.w6.x86_64.rpm php56w-xml-5.6.28-1.w6.x86_64.rpm php56w-xmlrpc-5.6.28-1.w6.x86_64.rpm php56w-mcrypt-5.6.28-1.w6.x86_64.rpm php56w-mbstring-5.6.28-1.w6.x86_64.rpm php56w-devel-5.6.28-1.w6.x86_64.rpm php56w-pecl-memcached-2.2.0-2.w6.x86_64.rpm php56w-common-5.6.28-1.w6.x86_64.rpm php56w-pdo-5.6.28-1.w6.x86_64.rpm php56w-cli-5.6.28-1.w6.x86_64.rpm php56w-pecl-memcache-3.0.8-2.w6.x86_64.rpm php56w-bcmath-5.6.28-1.w6.x86_64.rpm php56w-fpm-5.6.28-1.w6.x86_64.rpm libmemcached10-1.0.16-1.ius.el6.x86_64.rpm php56w-pecl-igbinary-1.2.1-2.w6.x86_64.rpm ``` curl >= 7.20 (如需支持 SMTP 认证),安装较高版本的 CURL ``` # yum install libcurl-devel-7.29.0-25.el6.x86_64.rpm libcurl-7.29.0-25.el6.x86_64.rpm curl-7.29.0-25.el6.x86_64.rpm ``` ### 4. 安装 Zabbix web ``` # yum install zabbix-web-3.2.1-1.el6.noarch.rpm zabbix-web-mysql-3.2.1-1.el6.noarch.rpm ``` 将 Zabbix web 发布到 Apache web 容器里面。 在 CentOS 中,Apache web 的默认路径是:`/var/www/html` ``` # mkdir /var/www/html/zabbix # cd /usr/share/zabbix/ # cp -a . /var/www/html/zabbix/ ``` ### 5. 配置 php.init PHP 中默认的一些参数配置不适用与 Zabbix,需要调整。 ``` # vi /etc/php.ini post_max_size=16M max_execution_time=300 max_input_time=300 date.timezone = Asia/Shanghai always_populate_raw_post_data = -1 ``` ### 6. 启动 Apache ``` # service httpd start ``` 验证 ``` # ps -ef|grep httpd # tail -f /var/log/httpd/error_log ``` ### 7. 登录 Zabbix web 进行配置 访问:[http://127.0.0.1/zabbix](http://127.0.0.1/zabbix) 按一下步骤,执行下去即可完成配置 ![1](./step1.png) 步骤 2 这里需要确认 PHP 的参数是正确的,如果有错误提示,请参照 **5. 配置 php.ini** 章节修改配置。 ![2](./step2.png) 步骤 3 这里配置的即是 MySQL 数据库的链接信息,默认可以和 Zabbix server 放在一个库上,若参照上述文档描述,数据库用户密码为 `zabbix/zabbix`。 ![3](./step3.png) ![4](./step4.png) ![5](./step5.png) ![6](./step6.png) 登录用户/密码:`Admin/zabbix` ![7](./step7.png) ## 参考资料 0. Zabbix rpm 包下载地址:[Index of /zabbix](http://repo.zabbix.com/zabbix/) 1. Zabbix 源码包下载地址:[Zabbix Sources](http://www.zabbix.com/download) - ([zabbix-3.2.1.tar.gz](http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.2.1/zabbix-3.2.1.tar.gz/download)) 2. Zabbix 官方源码编译安装文档:[4 Installation from sources - Zabbix Documentation 3.2](https://www.zabbix.com/documentation/3.2/manual/installation/install) 3. 源码编译安装过程中需要配置数据库,参照:[1 Database creation scripts](https://www.zabbix.com/documentation/3.2/manual/appendix/install/db_scripts) 4. 别人组织的一个 CentOS 6.x 版本的 curl 7.29.0 版本的 rpm 源放在 GitHub 上:[zabbixcn/curl-rpm - GitHub](https://github.com/zabbixcn/curl-rpm) 5. 别人组织的一个 CentOS 6.x 版本的 Zabbix 3.0 版本的 rpm 源放在 GitHub 上:[zabbixcn/zabbix3.0-rpm](https://github.com/zabbixcn/zabbix3.0-rpm) 6. 安装过程中一些依赖包的源: - [http://mirror.centos.org/centos/6/os/x86_64/Packages/](http://mirror.centos.org/centos/6/os/x86_64/Packages/) - [ftp://mirror.switch.ch/pool/4/mirror/epel/6/x86_64/](ftp://mirror.switch.ch/pool/4/mirror/epel/6/x86_64/) - MySQL rpm 源:[https://repo.mysql.com/yum/mysql-5.6-community/el/6/x86_64/](https://repo.mysql.com/yum/mysql-5.6-community/el/6/x86_64/) - MySQL 5.7 rpm 源:[https://repo.mysql.com/yum/mysql-5.7-community/el/6/x86_64](https://repo.mysql.com/yum/mysql-5.7-community/el/6/x86_64) - PHP 5.6 源:[https://repo.webtatic.com/yum/el6/x86_64/](https://repo.webtatic.com/yum/el6/x86_64/) 7. 一些相关的安装教程: - [CENTOS6.3 下 zabbix 安装部署](http://showerlee.blog.51cto.com/2047005/1189484) - [CentOS6.5 上 Zabbix3.0 的 RPM 安装【一】-安装并配置 Server](https://www.cnblogs.com/linprogram/p/5730639.html) - [CentOS 6 下安装 Zabbix 3.0](http://www.hi-linux.com/2016/03/29/CentOS%206%E4%B8%8B%E5%AE%89%E8%A3%85Zabbix%203.0/) - [Zabbix 3.2.0 yum 或编译安装 on CentOS 7](http://www.jianshu.com/p/fa81ede09711) 8. **更方便的方式**:请 **Google**:`一键安装 zabbix` ## 扩展阅读 ### Zabbix 架构 ![arch](./arch1.jpg) ### 阅读 0. [Zabbix 学习笔记](http://www.linux78.com/zabbix-system-study-notes)]]> 监控系统 mariadb <![CDATA[MariaDB 的安装部署]]> %2F2017%2F11%2F17%2F%E5%AE%89%E8%A3%85%20MariaDB%2F " # tee="/home/mysql/mysql3306/logs/audit.log" # pager="less -i -n -S" net_buffer_length=64K unbuffered [mysqladmin] default-character-set = utf8 socket=/tmp/mysql3306.sock [myisamchk] key_buffer = 512M sort_buffer_size = 512M read_buffer = 8M write_buffer = 8M [mysqlhotcopy] interactive-timeout [mysqld_safe] open-files-limit = 8192 ledir=/opt/mariadb/bin ``` 以上配置将 MySQL 实例初始化到 `/home/mysql/mysql3306` 目录下,请安装时根据实际的路径修改上面配置文件中的路径,涉及配置项如下: ``` datadir=/home/mysql/mysql3306/data pid-file=/home/mysql/mysql3306/mysql.pid tmpdir=/home/mysql/mysql3306/tmp log-error=/home/mysql/mysql3306/logs/error3306.log slow_query_log_file=/home/mysql/mysql3306/logs/slow3306.log #general_log_file=/home/mysql/mysql3306/logs/query.log slave-load-tmpdir=/home/mysql/mysql3306/tmp log-bin=/home/mysql/mysql3306/binlog/mysql-bin log-bin-index=/home/mysql/mysql3306/binlog/mysql-bin.index innodb_data_home_dir=/home/mysql/mysql3306/data innodb_log_group_home_dir=/home/mysql/mysql3306/data log-error=/home/mysql/mysql3306/logs/dump3306.log ledir=/opt/mariadb/bin ``` 其他参数的修改: * `server-id=90883306` 命名规则:机器 ip 后两个 + 端口 * `gtid-domain-id=8890926` 一主两从 ip 的后一位 + 端口后一位 * `innodb_buffer_pool_size=100G` 单实例不超过机器内存的 80%,双实例加起来不超过机器内存的 80% * `innodb_thread_concurrency=32` 小于等于 cpu 线程数 * `log_slave_updates` 一主一从关闭 log\_slave\_updates(即注释掉),一主两从开启 `log_slave_updates` **初始化实例** 切换用户到 mysql ``` $ su - mysql Password: ``` 创建需要的目录 ``` $ mkdir -p /home/mysql/mysql3306/ $ cd /home/mysql/mysql3306/ && mkdir {data,logs,binlog,tmp,bin} ``` 运行一下命令进行初始化: ``` $ mysql_install_db --basedir=/opt/mariadb/ --defaults-file=/etc/my.cnf --user=mysql Installing MariaDB/MySQL system tables in '/home/mysql/mysql3306' ... 2016-12-12 9:12:48 139952692410208 [Note] /opt/mariadb/bin/mysqld (mysqld 10.1.19-MariaDB) starting as process 14731 ... OK Filling help tables... 2016-12-12 9:12:54 140080526587744 [Note] /opt/mariadb/bin/mysqld (mysqld 10.1.19-MariaDB) starting as process 14763 ... OK Creating OpenGIS required SP-s... 2016-12-12 9:12:59 140681527736160 [Note] /opt/mariadb/bin/mysqld (mysqld 10.1.19-MariaDB) starting as process 14795 ... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER ! To do so, start the server, then issue the following commands: '/opt/mariadb/bin/mysqladmin' -u root password 'new-password' '/opt/mariadb/bin/mysqladmin' -u root -h 127.0.0.1 password 'new-password' Alternatively you can run: '/opt/mariadb/bin/mysql_secure_installation' which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the MariaDB Knowledgebase at http://mariadb.com/kb or the MySQL manual for more instructions. You can start the MariaDB daemon with: cd '/opt/mariadb/' ; /opt/mariadb/bin/mysqld_safe --datadir='/home/mysql/mysql3306/data' You can test the MariaDB daemon with mysql-test-run.pl cd '/opt/mariadb/mysql-test' ; perl mysql-test-run.pl Please report any problems at http://mariadb.org/jira The latest information about MariaDB is available at http://mariadb.org/. You can find additional information about the MySQL part at: http://dev.mysql.com Support MariaDB development by buying support/new features from MariaDB Corporation Ab. You can contact us about this at sales@mariadb.com. Alternatively consider joining our community based development effort: http://mariadb.com/kb/en/contributing-to-the-mariadb-project/ ``` 可以通过上面信息看到 OK。 ![](./install_mysql_succ.png) 查询 `cat /home/mysql/mysql3306/logs/error3306.log` 日志,没有 `[ERROR]` 日志标识安装成功。 ### 启动 MariaDB 实例 **方式一:本文采用服务方式启动 MariaDB 服务。** 首先,需要拷贝配置脚本到服务启动目录: ``` # cp /opt/mariab/support-files/mysql.server /etc/rc.d/init.d/mysqld # chmod +x /etc/rc.d/init.d/mysqld ``` 修改启动脚本内容: ``` # vi /etc/rc.d/init.d/mysqld # 修改 basedir= 及 datadir= 两个参数 basedir=/opt/mariadb datadir=/home/mysql/mysql3306/data ``` 通过 service 启动服务 ``` $ service mysqld start Starting MySQL.161212 10:02:09 mysqld_safe Logging to '/home/mysql/mysql3306/logs/mysql_3306.err'. ... $ ps -ef|grep mysql mysql 24488 1 0 10:02 pts/1 00:00:00 /bin/sh /opt/mariadb/bin/mysqld_safe --datadir=/home/mysql/mysql3306/data --pid-file=/home/mysql/mysql3306/mysqld3306.pid mysql 25032 24488 0 10:02 pts/1 00:00:04 /opt/mariadb/bin/mysqld --basedir=/opt/mariadb/ --datadir=/home/mysql/mysql3306/data --plugin-dir=/opt/mariadb/lib/plugin --log-err or=/home/mysql/mysql3306/logs/mysql_3306.err --open-files-limit=8192 --pid-file=/home/mysql/mysql3306/mysqld3306.pid --socket=/tmp/mysql3306.sock --po rt=3306 ``` **方式二:采用 mysqld\_safe 启动** ``` $ mysqld_safe --defaults-file=/etc/my.cnf & $ ps -ef|grep mysql mysql 24488 1 0 10:02 pts/1 00:00:00 /bin/sh /opt/mariadb/bin/mysqld_safe --datadir=/home/mysql/mysql3306/data --pid-file=/home/mysql/mysql3306/mysqld3306.pid mysql 25032 24488 0 10:02 pts/1 00:00:04 /opt/mariadb/bin/mysqld --basedir=/opt/mariadb/ --datadir=/home/mysql/mysql3306/data --plugin-dir=/opt/mariadb/lib/plugin --log-err or=/home/mysql/mysql3306/logs/mysql_3306.err --open-files-limit=8192 --pid-file=/home/mysql/mysql3306/mysqld3306.pid --socket=/tmp/mysql3306.sock --po rt=3306 ``` 至此,MariaDB 的安装部署已经完成。 ### 配置 root 用户密码 启动服务成功后,MySQL 实例 root 用户的默认密码为空。 可以通过一下命令登录: ``` $ mysql -uroot -p -S /tmp/mysql3306.sock Enter password: ``` `Enter password:` 处回车即可。 然后通过一下命令修改密码: ``` $ mysqladmin -u root password 'new_password' ``` `new_password` 处即为新密码,请修改后保存改密码,后续登录 root 用户需要输入此密码。 如果需要修改新密码,可以先登录到 mysql 中,执行以下命令进行修改(新密码为:`Aa123456`): ``` MariaDB [(none)]> update mysql.user set password=password('Aa123456') where user='root'; MariaDB [(none)]> flush privileges; ``` ### 配置 root 用户远程访问 默认安装的 MySQL 实例 root 用户只有本地访问权限,需要通过修改 `mysql.user` 表,给 root 用户授权。 执行以下命令: ``` MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root123' WITH GRANT OPTION; MariaDB [(none)]> flush privileges; ``` ### 遇到问题 1: ``` $ mysql_install_db --basedir=/opt/mariadb/ --defaults-file=/etc/my.cnf [95/19157] Installing MariaDB/MySQL system tables in '/home/mysql/mysql3306' ... 2016-12-12 8:59:36 140187907016544 [Note] Using unique option prefix 'extra-max-connection' is error-prone and can break in the future. Please use the full name 'extra_max_conne ctions' instead. 2016-12-12 8:59:36 140187907016544 [Note] /opt/mariadb//bin/mysqld (mysqld 10.1.19-MariaDB) starting as process 14447 ... Installation of system tables failed! Examine the logs in /home/mysql/mysql3306 for more information. The problem could be conflicting information in an external my.cnf files. You can ignore these by doing: shell> /opt/mariadb//scripts/scripts/mysql_install_db --defaults-file=~/.my.cnf You can also try to start the mysqld daemon with: shell> /opt/mariadb//bin/mysqld --skip-grant --general-log & and use the command line tool /opt/mariadb//bin/mysql to connect to the mysql database and look at the grant tables: shell> /opt/mariadb//bin/mysql -u root mysql mysql> show tables; Try 'mysqld --help' if you have problems with paths. Using --general-log gives you a log in /home/mysql/mysql3306 that may be helpful. The latest information about mysql_install_db is available at https://mariadb.com/kb/en/installing-system-tables-mysql_install_db MariaDB is hosted on launchpad; You can find the latest source and email lists at http://launchpad.net/maria Please check all of the above before submitting a bug report at http://mariadb.org/jira $ cat /home/mysql/mysql3306/logs/error3306.log 2016-12-12 08:59:36 7f800a664760 InnoDB: Warning: Using innodb_additional_mem_pool_size is DEPRECATED. This option may be removed in future releases, together with the option in$ odb_use_sys_malloc and with the InnoDB's internal memory allocator. innodb_open_files should not be greater than the open_files_limit. 2016-12-12 8:59:36 140187907016544 [Note] InnoDB: Using mutexes to ref count buffer pool pages 2016-12-12 8:59:36 140187907016544 [Note] InnoDB: The InnoDB memory heap is disabled 2016-12-12 8:59:36 140187907016544 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2016-12-12 8:59:36 140187907016544 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier 2016-12-12 8:59:36 140187907016544 [Note] InnoDB: Compressed tables use zlib 1.2.3 2016-12-12 8:59:36 140187907016544 [Note] InnoDB: Using Linux native AIO 2016-12-12 8:59:36 140187907016544 [Note] InnoDB: Using SSE crc32 instructions 2016-12-12 8:59:36 140187907016544 [Note] InnoDB: Initializing buffer pool, size = 512.0M 2016-12-12 8:59:36 140187907016544 [Note] InnoDB: Completed initialization of buffer pool 2016-12-12 8:59:36 140187907016544 [Note] InnoDB: The first specified data file /home/mysql/mysql3306/ibdata1 did not exist: a new database to be created! 2016-12-12 8:59:36 140187907016544 [Note] InnoDB: Setting file /home/mysql/mysql3306/ibdata1 size to 128 MB 2016-12-12 8:59:36 140187907016544 [Note] InnoDB: Database physically writes the file full: wait... InnoDB: Progress in MB: 100 2016-12-12 8:59:36 140187907016544 [Note] InnoDB: Setting log file /home/mysql/mysql3306/ib_logfile101 size to 1000 MB InnoDB: Progress in MB: 100 200 300 400 500 600 700 800 900 1000 2016-12-12 8:59:38 140187907016544 [Note] InnoDB: Setting log file /home/mysql/mysql3306/ib_logfile1 size to 1000 MB InnoDB: Progress in MB: 100 200 300 400 500 600 700 800 900 1000 2016-12-12 8:59:39 140187907016544 [Note] InnoDB: Setting log file /home/mysql/mysql3306/ib_logfile2 size to 1000 MB InnoDB: Progress in MB: 100 200 300 400 500 600 700 800 900 1000 2016-12-12 8:59:40 140187907016544 [Note] InnoDB: Setting log file /home/mysql/mysql3306/ib_logfile3 size to 1000 MB InnoDB: Progress in MB: 100 200 300 400 500 600 700 8002016-12-12 08:59:41 7f800a664760 InnoDB: Error: Write to file /home/mysql/mysql3306/ib_logfile3 failed at offset 894435 328. InnoDB: 1048576 bytes should have been written, only 126976 were written. InnoDB: Operating system error number 28. InnoDB: Check that your OS and file system support files of this size. InnoDB: Check also that the disk is not full or a disk quota exceeded. InnoDB: Error number 28 means 'No space left on device'. InnoDB: Some operating system error numbers are described at InnoDB: http://dev.mysql.com/doc/refman/5.6/en/operating-system-error-codes.html 2016-12-12 8:59:41 140187907016544 [ERROR] InnoDB: Cannot set log file /home/mysql/mysql3306/ib_logfile3 to size 1000 MB 2016-12-12 8:59:41 140187907016544 [ERROR] Plugin 'InnoDB' init function returned error. 2016-12-12 8:59:41 140187907016544 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. 2016-12-12 8:59:41 140187907016544 [ERROR] Unknown/unsupported storage engine: InnoDB 2016-12-12 8:59:41 140187907016544 [ERROR] Aborting 2016-12-12 8:59:41 140186063206144 [Warning] mysqld: Disk is full writing '/home/mysql/mysql3306/aria_log.00000001' (Errcode: 28 "No space left on device"). Waiting for some one to free space... (Expect up to 60 secs delay for server to continue after freeing disk space) 2016-12-12 8:59:41 140186063206144 [Warning] mysqld: Retry in 60 secs. Message reprinted in 600 secs ``` 修改 /etc/my.cnf 改小:innodb\_log\_file\_size=128M 删除 /home/myql/mysql3306 目录后重新初始化目录,并重新执行 mysql\_install\_db 命令 ### 遇到问题 2: ``` mysql_install_db --basedir=/opt/mariadb/ --defaults-file=/etc/my.cnf WARNING: The host 'vagrant-centos64.vagrantup.com' could not be looked up with resolveip. This probably means that your libc libraries are not 100 % compatible with this binary MariaDB version. The MariaDB daemon, mysqld, should work normally with the exception that host name resolving will not work. This means that you should use IP addresses instead of hostnames when specifying MariaDB privileges ! ``` `vagrant-centos64.vagrantup.com` 是本机的 hostname,可以通过 `hostname` 命令查看当前主机名 修改 /etc/hosts ``` # vi /etc/hosts # 添加以下内容 127.0.0.1 vagrant-centos64.vagrantup.com ``` ### 遇到问题 3: 使用服务方式和 mysqld\_safe 方式启动,均不成功。并且没有错误日志: ``` $ /opt/mariadb/bin/mysqld_safe --datadir='/home/mysql/mysql3306' --default-files='/etc/my.cnf' 161213 02:40:33 mysqld_safe Logging to '/home/mysql/mysql3306/mysql3306.err'. $ service mysqld start Starting MySQL.161213 02:52:34 mysqld_safe Logging to '/home/mysql/mysql3306/error3306.log'. ERROR! ``` 因为这两个都是 mysqld\_safe 方式启动的,怀疑是 my.cnf 里面 `[mysqld_safe]` 节点配置错误,遂检查 my.cnf 配置文件,发现 `[mysqld_safe]` 节点下的 `ledir` 配置的是 `ledir=/home/mysql/mysql3306`,查看 MySQL 官方文档:[[[5.3.2 mysqld\_safe — MySQL Server Startup Script](http://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html)\],此参数需要配置的是指向 mysqld 程序的目录路径,使用该选项来显式表示服务器位置。故此,修改为 `ledir=/opt/mariadb/bin`。重启服务成功。]]> 数据库 mariadb <![CDATA[MySQL 安装部署]]> %2F2017%2F11%2F17%2Finstall-mysql%2F SET PASSWORD = PASSWORD('Aa123456'); mysql> flush privileges; ``` ### 配置 root 用户远程访问 默认安装的 MySQL 实例 root 用户只有本地访问权限,需要通过修改 `mysql.user` 表,给 root 用户授权。 执行以下命令: ```mysql mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Aa123456' WITH GRANT OPTION; mysql> flush privileges; ``` **==至此,MySQL 的安装及配置全部完成!==** ## 访问 MySQL 安装完成后,我们就可以正常访问该 MySQL 实例了: ``` shell $ mysql -h127.0.0.1 -P3309 -uroot -p Password: ``` ## 数据导入 ### 进入 MySQL ``` shell $ mysql -h127.0.0.1 -P3309 -uroot -p Password: ... ``` ### 切换到我们要的 Database 上 这里假设我们要用到的数据库名叫:itrace\_startup ``` mysql mysql> use itrace_startup; ### 如果没有这个库我们要先创建: mysql> create database itrace_startup; mysql> use itrace_startup; ``` ### 导入数据 这里假设我们要导入的SQL文件名叫:`cust.sql`,且放在 `/home/vagrant` 目录下。 ``` mysql mysql> source /home/vagrant/cust.sql ``` **==导入数据文件 `cust.sql` 成功!==**]]> 数据库 mysql <![CDATA[MySQL Streaming 的使用和约束]]> %2F2017%2F11%2F16%2Fmysql-streaming%2F 数据库 mysql java <![CDATA[Elasticsearch 的一些使用经验]]> %2F2017%2F07%2F03%2Felasticsearch-best-practices%2F Elastic Stack elasticsearch <![CDATA[Elasticsearch 日常运维操作]]> %2F2017%2F07%2F03%2Fmaintain-elasticsearch%2F Elastic Stack elasticsearch <![CDATA[Elastic Stack 的相关监控]]> %2F2017%2F07%2F03%2Fmonitoring-elastic-stack%2F Elastic Stack elasticsearch logstash filebeat <![CDATA[通过 Zabbix 实现 Logstash 的监控]]> %2F2017%2F06%2F27%2Fuse-metrics-filter-monitoring-logstash-tps-with-zabbix%2F "events" # 统计每一个经过 filter 的事件 add_tag => "metric" add_field => {"[@metadata][zabbix_key]" => "logstash_events"} # zabbix item 的 key,这个要和 zabbix 的配置一致 add_field => { "[@metadata][zabbix_host]" => "logstash-indexer-1" } # zabbix 写入的主机 flush_interval => 10 # 每隔 10s 写一次 } } output { ... if "metric" in [tags] { zabbix { zabbix_server_host => "192.168.56.113" zabbix_host => "[@metadata][zabbix_host]" zabbix_key => "[@metadata][zabbix_key]" zabbix_value => "[events][count]" # [events][count] 是事件统计数据,还有其他字段内容,具体参考官网文档 } } } #+END_SRC 配置好 logstash 后,reload 配置或重启服务即可。 具体配置参考官方文档说明。 至此,查看 Zabbix web 界面的 item 项即可看到监控 TPS 的图表了: [[./logstash-tps-graph.png]] ** 参考内容 - [[https://www.elastic.co/guide/en/logstash/current/plugins-filters-metrics.html][metrics]] - [[https://www.elastic.co/guide/en/logstash/current/plugins-outputs-zabbix.html#plugins-outputs-zabbix-zabbix_server_host][zabbix]]]]> Elastic Stack logstash zabbix %2F2017%2F06%2F22%2Fdistributed-transactions-introduce%2F %2F2017%2F06%2F05%2Fusing-plantuml-in-emacs%2F <![CDATA[使用 Hexo + Orgmode 构建博客]]> %2F2017%2F06%2F04%2Fblogging-with-hexo-orgmode%2F hexo emacs orgmode hexo <![CDATA[Elasticsearch 核心概念]]> %2F2017%2F06%2F04%2Felasticsearch-introduction%2F Elastic Stack elasticsearch