数据仓库006 - MySQL 5.6.x - Linux最佳生产环境离线部署
Posted 王者★孤傲
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据仓库006 - MySQL 5.6.x - Linux最佳生产环境离线部署相关的知识,希望对你有一定的参考价值。
一、离线安装包 文件准备
这里以mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz为例,记一次MySQL 5.6.x 的生产环境离线部署过程。使用SecureCRT连接生产部署的机器,这里注意使用root用户进行操作。
mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz文件,已放到网盘(为什么不放到仓库的原因:****,习惯了 ),
链接:https://pan.baidu.com/s/1aOC4jUiVa5KcLS7dQwyCbA 提取码:kvuo
1、检查是否安装过mysqld
[root@slave054 local]# ps -ef|grep mysqld root 2428 2282 0 20:25 pts/0 00:00:00 grep --color=auto mysqld
[root@slave054 local]# rpm -qa |grep -i mysql
[root@slave054 local]# ps -ef|grep mysqld root 2432 2282 0 20:25 pts/0 00:00:00 grep --color=auto mysqld
2、切换到/usr/local目录下
[root@slave054 ~]# cd /usr/local [root@slave054 local]# pwd /usr/local [root@slave054 local]#
3、使用rz 上传mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz压缩文件
[root@slave054 local]# ll total 0 drwxr-xr-x. 2 root root 6 Apr 11 2018 bin drwxr-xr-x. 2 root root 6 Apr 11 2018 etc drwxr-xr-x. 2 root root 6 Apr 11 2018 games drwxr-xr-x. 2 root root 6 Apr 11 2018 include drwxr-xr-x. 2 root root 6 Apr 11 2018 lib drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64 drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin drwxr-xr-x. 5 root root 49 Nov 24 00:00 share drwxr-xr-x. 2 root root 6 Apr 11 2018 src [root@slave054 local]# rz rz waiting to receive. zmodem trl+C ȡ 100% 304464 KB 2495 KB/s 00:02:02 0 Errorssc2.5-x86_64.tar.gz... [root@slave054 local]#
[root@slave054 local]# ll total 304468 drwxr-xr-x. 2 root root 6 Apr 11 2018 bin drwxr-xr-x. 2 root root 6 Apr 11 2018 etc drwxr-xr-x. 2 root root 6 Apr 11 2018 games drwxr-xr-x. 2 root root 6 Apr 11 2018 include drwxr-xr-x. 2 root root 6 Apr 11 2018 lib drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64 drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec -rw-r--r--. 1 root root 311771412 Nov 23 19:48 mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin drwxr-xr-x. 5 root root 49 Nov 24 00:00 share drwxr-xr-x. 2 root root 6 Apr 11 2018 src [root@slave054 local]#
二、解压文件并建立软连接
1、解压mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz
[root@slave054 local]# tar xzvf mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz
2、建立软连接
[root@slave054 local]# ln -s mysql-5.6.23-linux-glibc2.5-x86_64 mysql
[root@slave054 local]# ll total 304468 drwxr-xr-x. 2 root root 6 Apr 11 2018 bin drwxr-xr-x. 2 root root 6 Apr 11 2018 etc drwxr-xr-x. 2 root root 6 Apr 11 2018 games drwxr-xr-x. 2 root root 6 Apr 11 2018 include drwxr-xr-x. 2 root root 6 Apr 11 2018 lib drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64 drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec lrwxrwxrwx. 1 root root 34 Nov 25 20:32 mysql -> mysql-5.6.23-linux-glibc2.5-x86_64 drwxr-xr-x. 13 root root 213 Nov 25 20:31 mysql-5.6.23-linux-glibc2.5-x86_64 -rw-r--r--. 1 root root 311771412 Nov 23 19:48 mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin drwxr-xr-x. 5 root root 49 Nov 24 00:00 share drwxr-xr-x. 2 root root 6 Apr 11 2018 src [root@slave054 local]#
三、用户和用户组
1、添加dba用户组
[root@slave054 local]# groupadd -g 101 dba
2、新建mysqladmin用户
[root@slave054 local]# useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin useradd: warning: the home directory already exists. Not copying any file from skel directory into it. [root@slave054 local]# id mysqladmin uid=514(mysqladmin) gid=101(dba) groups=101(dba),0(root) [root@slave054 local]# passwd mysqladmin Changing password for user mysqladmin. New password: BAD PASSWORD: The password is shorter than 8 characters Retype new password: passwd: all authentication tokens updated successfully. [root@slave054 local]#
如果mysqladmin 已经存在,则执行如下命令:
usermod -u 514 -g dba -G root -d /usr/local/mysql mysqladmin
3、复制环境变量配置文件至mysqladmin用户的home目录
[root@slave054 local]# cp /etc/skel/.* /usr/local/mysql cp: omitting directory ‘/etc/skel/.’ cp: omitting directory ‘/etc/skel/..’ cp: omitting directory ‘/etc/skel/.mozilla’ [root@slave054 local]#
4、my.cnf文件配置
[root@slave054 local]# cd /etc/
[root@slave054 etc]# vi my.cnf
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d ~ ~ ~ ~ "my.cnf" 19L, 570C
将以下的内容,替换掉原来默认的my.cnf默认配置内容,注意vim要进入-- INSERT --模式才能开始粘贴,否则粘贴的内容会不完全:
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d [client] port = 3306 socket = /usr/local/mysql/data/mysql.sock [mysqld] port = 3306 socket = /usr/local/mysql/data/mysql.sock skip-external-locking key_buffer_size = 256M sort_buffer_size = 2M read_buffer_size = 2M read_rnd_buffer_size = 4M query_cache_size= 32M max_allowed_packet = 16M myisam_sort_buffer_size=128M tmp_table_size=32M table_open_cache = 512 thread_cache_size = 8 wait_timeout = 86400 interactive_timeout = 86400 max_connections = 600 # Try number of CPU\'s*2 for thread_concurrency thread_concurrency = 32 #isolation level and default engine default-storage-engine = INNODB transaction-isolation = READ-COMMITTED server-id = 1 basedir = /usr/local/mysql datadir = /usr/local/mysql/data pid-file = /usr/local/mysql/data/hostname.pid #open performance schema log-warnings sysdate-is-now binlog_format = MIXED log_bin_trust_function_creators=1 log-error = /usr/local/mysql/data/hostname.err log-bin=/usr/local/mysql/arch/mysql-bin #other logs #general_log =1 #general_log_file = /usr/local/mysql/data/general_log.err #slow_query_log=1 #slow_query_log_file=/usr/local/mysql/data/slow_log.err #for replication slave #log-slave-updates #sync_binlog = 1 #for innodb options innodb_data_home_dir = /usr/local/mysql/data/ innodb_data_file_path = ibdata1:500M:autoextend innodb_log_group_home_dir = /usr/local/mysql/arch innodb_log_files_in_group = 2 innodb_log_file_size = 200M innodb_buffer_pool_size = 2048M innodb_additional_mem_pool_size = 50M innodb_log_buffer_size = 16M innodb_lock_wait_timeout = 100 #innodb_thread_concurrency = 0 innodb_flush_log_at_trx_commit = 1 innodb_locks_unsafe_for_binlog=1 #innodb io features: add for mysql5.5.8 performance_schema innodb_read_io_threads=4 innodb-write-io-threads=4 innodb-io-capacity=200 #purge threads change default(0) to 1 for purge innodb_purge_threads=1 innodb_use_native_aio=on #case-sensitive file names and separate tablespace innodb_file_per_table = 1 lower_case_table_names=1 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [mysqlhotcopy] interactive-timeout [myisamchk] key_buffer_size = 256M sort_buffer_size = 256M read_buffer = 2M write_buffer = 2M
如果需要进行mysql调优,只需要调整*_buffer_size的参数即可,切记根据实际需求修改。
注意:
defualt start: /etc/my.cnf->/etc/mysql/my.cnf->SYSCONFDIR/my.cnf->$MYSQL_HOME/my.cnf-> --defaults-extra-file->~/my.cnf
5、权限与文件所有者
[root@slave054 etc]# cd - /usr/local [root@slave054 local]# chown mysqladmin:dba /etc/my.cnf [root@slave054 local]# chmod 640 /etc/my.cnf [root@slave054 local]# ll /etc/my.cnf -rw-r-----. 1 mysqladmin dba 2218 Nov 25 20:48 /etc/my.cnf [root@slave054 local]# ll |grep mysql lrwxrwxrwx. 1 root root 34 Nov 25 20:32 mysql -> mysql-5.6.23-linux-glibc2.5-x86_64 drwxr-xr-x. 13 root root 269 Nov 25 20:42 mysql-5.6.23-linux-glibc2.5-x86_64 -rw-r--r--. 1 root root 311771412 Nov 23 19:48 mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz [root@slave054 local]# chown -R mysqladmin:dba /usr/local/mysql [root@slave054 local]# ll |grep mysql lrwxrwxrwx. 1 mysqladmin dba 34 Nov 25 20:32 mysql -> mysql-5.6.23-linux-glibc2.5-x86_64 drwxr-xr-x. 13 root root 269 Nov 25 20:42 mysql-5.6.23-linux-glibc2.5-x86_64 -rw-r--r--. 1 root root 311771412 Nov 23 19:48 mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz [root@slave054 local]# chown -R mysqladmin:dba /usr/local/mysql-5.6.23-linux-glibc2.5-x86_64 [root@slave054 local]# ll |grep mysql lrwxrwxrwx. 1 mysqladmin dba 34 Nov 25 20:32 mysql -> mysql-5.6.23-linux-glibc2.5-x86_64 drwxr-xr-x. 13 mysqladmin dba 269 Nov 25 20:42 mysql-5.6.23-linux-glibc2.5-x86_64 -rw-r--r--. 1 root root 311771412 Nov 23 19:48 mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz [root@slave054 local]# chmod -R 755 /usr/local/mysql [root@slave054 local]# chmod -R 755 /usr/local/mysql-5.6.23-linux-glibc2.5-x86_64 [root@slave054 local]# ll |grep mysql lrwxrwxrwx. 1 mysqladmin dba 34 Nov 25 20:32 mysql -> mysql-5.6.23-linux-glibc2.5-x86_64 drwxr-xr-x. 13 mysqladmin dba 269 Nov 25 20:42 mysql-5.6.23-linux-glibc2.5-x86_64 -rw-r--r--. 1 root root 311771412 Nov 23 19:48 mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz [root@slave054 local]#
四、mysqladmin用户配置mysql
1、登录mysqladmin用户
[root@slave054 local]# su - mysqladmin [mysqladmin@slave054 ~]$ pwd /usr/local/mysql [mysqladmin@slave054 ~]$ ll total 148 drwxr-xr-x. 2 mysqladmin dba 4096 Nov 25 20:31 bin -rwxr-xr-x. 1 mysqladmin dba 17987 Jan 19 2015 COPYING drwxr-xr-x. 3 mysqladmin dba 18 Nov 25 20:30 data drwxr-xr-x. 2 mysqladmin dba 55 Nov 25 20:31 docs drwxr-xr-x. 3 mysqladmin dba 4096 Nov 25 20:31 include -rwxr-xr-x. 1 mysqladmin dba 102315 Jan 19 2015 INSTALL-BINARY drwxr-xr-x. 3 mysqladmin dba 4096 Nov 25 20:31 lib drwxr-xr-x. 4 mysqladmin dba 30 Nov 25 20:31 man drwxr-xr-x. 10 mysqladmin dba 4096 Nov 25 20:31 mysql-test -rwxr-xr-x. 1 mysqladmin dba 2496 Jan 19 2015 README drwxr-xr-x. 2 mysqladmin dba 30 Nov 25 20:31 scripts drwxr-xr-x. 28 mysqladmin dba 4096 Nov 25 20:31 share drwxr-xr-x. 4 mysqladmin dba 4096 Nov 25 20:31 sql-bench drwxr-xr-x. 2 mysqladmin dba 136 Nov 25 20:31 support-files [mysqladmin@slave054 ~]$
2、新建backup目录
[mysqladmin@slave054 ~]$ mkdir arch backup
3、使用scripts安装mysql_install_db
[mysqladmin@slave054 ~]$ scripts/mysql_install_db Installing MySQL system tables...2019-11-25 21:01:32 0 [Warning] \'THREAD_CONCURRENCY\' is deprecated and will be removed in a future release. 2019-11-25 21:01:32 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). OK Filling help tables...2019-11-25 21:01:38 0 [Warning] \'THREAD_CONCURRENCY\' is deprecated and will be removed in a future release. 2019-11-25 21:01:38 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 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 MySQL root USER ! To do so, start the server, then issue the following commands: /usr/local/mysql/bin/mysqladmin -u root password \'new-password\' /usr/local/mysql/bin/mysqladmin -u root -h slave054 password \'new-password\' Alternatively you can run: /usr/local/mysql/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 manual for more instructions. You can start the MySQL daemon with: cd . ; /usr/local/mysql/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com New default config file was created as ./my.cnf and will be used by default by the server when you start it. You may edit this file to change server settings WARNING: Default config file /etc/my.cnf exists on the system This file will be read by default by the MySQL server If you do not want to use this, either remove it, or use the --defaults-file argument to mysqld_safe when starting the server [mysqladmin@slave054 ~]$
注意:如果第3步骤中,报了一个
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory #缺少libaio.so 包 错误,为了修正这个错误,就需要 先执行 如下命令,之后再切换回mysqladmin用户,继续执行第3步骤中的内容:
* 4-1、查看Linux version
[mysqladmin@slave054 ~]$ cat /proc/version
Linux version 3.10.0-1062.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Wed Aug 7 18:08:02 UTC 2019
[mysqladmin@slave054 ~]$
* 4-2、gcc (建议使用root用户进行操作)
[mysqladmin@slave054 ~]$ rpm -qa |grep gcc gcc-c++-4.8.5-39.el7.x86_64 gcc-4.8.5-39.el7.x86_64 libgcc-4.8.5-39.el7.x86_64 gcc-gfortran-4.8.5-39.el7.x86_64 [mysqladmin@slave054 ~]$
* 4-3、切换root用户,安装libaio 包
[mysqladmin@slave054 ~]$ su - root Password: Last login: Mon Nov 25 20:15:13 CST 2019 on pts/0 [root@slave054 ~]# yum -y install libaio Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.lzu.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com base | 3.6 kB 00:00 extras | 2.9 kB 00:00 updates | 2.9 kB 00:00 Package libaio-0.3.109-13.el7.x86_64 already installed and latest version Nothing to do [root@slave054 ~]#
Loaded plugins: fastestmirror Determining fastest mirrors base-tn54 | 1.1 kB 00:00 tn-appv1 | 951 B 00:00 updates-tn54 | 951 B 00:00 Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package libaio.i386 0:0.3.106-3.2 set to be updated ---> Package libaio.x86_64 0:0.3.106-3.2 set to be updated --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================== Package Arch Version Repository Size ============================================================================================================================== Installing: libaio i386 0.3.106-3.2 base-tn54 19 k libaio x86_64 0.3.106-3.2 base-tn54 19 k Transaction Summary ============================================================================================================================== Install 2 Package(s) Update 0 Package(s) Remove 0 Package(s) Total download size: 38 k Downloading Packages: (1/2): libaio-0.3.106-3.2.i386.rpm | 19 kB 00:00 (2/2): libaio-0.3.106-3.2.x86_64.rpm | 19 kB 00:00 ------------------------------------------------------------------------------------------------------------------------------ Total 452 kB/s | 38 kB 00:00 Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing : libaio 1/2 Installing : libaio 2/2 Installed: libaio.i386 0:0.3.106-3.2 libaio.x86_64 0:0.3.106-3.2 Complete!
* 4-4、重新切换mysqladmin用户
[root@slave054 ~]# su - mysqladmin Last login: Mon Nov 25 20:59:20 CST 2019 on pts/0 [mysqladmin@slave054 ~]$ pwd /usr/local/mysql [mysqladmin@slave054 ~]$
五、初始化db
[mysqladmin@slave054 ~]$ scripts/mysql_install_db --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
[mysqladmin@slave054 ~]$ scripts/mysql_install_db --user=mysqladmin --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
Install以上是关于数据仓库006 - MySQL 5.6.x - Linux最佳生产环境离线部署的主要内容,如果未能解决你的问题,请参考以下文章