Linux学习之路--Mariadb源码编译安装19---20180120
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux学习之路--Mariadb源码编译安装19---20180120相关的知识,希望对你有一定的参考价值。
一、源码编译安装mariadb
生产环境中,大部分使用的都是二进制安装或者源码编译安装,yum安装很多要求和设置很繁琐,容易出现错误
此次源码编译安装需要先安装 cmake
1、准备cmake
[[email protected]~]#rpm -q cmake package cmake is not installed [[email protected]~]#yum install cmake ..... ========================================================================================================================== Package Arch Version Repository Size ========================================================================================================================== Installing: cmake x86_64 2.8.12.2-4.el6 base 8.0 M ..... Installed: cmake.x86_64 0:2.8.12.2-4.el6 .....
2、清除其他版本的mariadb软件文件
[[email protected]~]#rpm -q mariadb package mariadb is not installed [[email protected]~]#rpm -q mariadb-server package mariadb-server is not installed [[email protected]~]#find / -name mysql* | xargs rm -rf
3、创建软件用户账号
[[email protected]~]#useradd -r -s /sbin/nologin mysql [[email protected]~]#id mysql uid=496(mysql) gid=495(mysql) groups=495(mysql)
4、安装编译安装的包组及准备相关文件
[[email protected]~]#yum groupinstall "development tools" [[email protected]~]#ls anaconda-ks.cfg mariadb-10.2.12 mariadb-10.2.12.tar.gz reset68.sh [[email protected]~]#mkdir /data/mysqldb [[email protected]~]#chown mysql.mysql /data/mysqldb [[email protected]]#ls appveyor.yml config.h.cmake debian INSTALL-WIN-SOURCE mysql-test README.md strings win BUILD configure.cmake Docs KNOWN_BUGS.txt mysys scripts support-files wsrep BUILD-CMAKE COPYING EXCEPTIONS-CLIENT libmariadb mysys_ssl sql tests zlib client COPYING.thirdparty extra libmysqld pcre sql-bench unittest cmake CREDITS include libservices plugin sql-common VERSION CMakeLists.txt dbug INSTALL-SOURCE man randgen storage vio [[email protected]]#gcc --version gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18) Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5、准备安装配置选项
cmake . -DCMAKE_INSTALL_PREFIX=/app/mysql -DMYSQL_DATADIR=/data/mysqldb/ -DSYSCONFDIR=/etc -DMYSQL_USER=mysql -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/app/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_DEBUG=0 -DWITHOUT_MROONGA_STORAGE_ENGINE=1 make && make install [[email protected]]#cmake . > -DCMAKE_INSTALL_PREFIX=/app/mysql > -DMYSQL_DATADIR=/data/mysqldb/ > -DSYSCONFDIR=/etc > -DMYSQL_USER=mysql > -DWITH_INNOBASE_STORAGE_ENGINE=1 > -DWITH_ARCHIVE_STORAGE_ENGINE=1 > -DWITH_BLACKHOLE_STORAGE_ENGINE=1 > -DWITH_READLINE=1 > -DWITH_SSL=system > -DWITH_ZLIB=system > -DWITH_LIBWRAP=0 > -DMYSQL_UNIX_ADDR=/app/mysql/mysql.sock > -DDEFAULT_CHARSET=utf8 > -DDEFAULT_COLLATION=utf8_general_ci > -DENABLED_LOCAL_INFILE=1 > -DWITH_PARTITION_STORAGE_ENGINE=1 > -DWITH_DEBUG=0 > -DWITHOUT_MROONGA_STORAGE_ENGINE=1 ...... -- Configuring done -- Generating done -- Build files have been written to: /root/mariadb-10.2.12 -- Configuring done -- Generating done CMake Warning: Manually-specified variables were not used by the project: MYSQL_USER SYSCONFDIR WITHOUT_MROONGA_STORAGE_ENGINE WITH_DEBUG -- Build files have been written to: /root/mariadb-5.5.59
6、补充其他包
[[email protected]]#yum install ncurse-devel [[email protected]]#yum install gnutls-devel [[email protected]]#yum install libevent-devel [[email protected]]#yum install "libaio-devel" [[email protected]]#yum install "openssl-devel" [[email protected]]#yum install libxml2-devel [[email protected]]#yum install xz-devel [[email protected]~]#yum install ncurses-devel
7、调试相关选项
添加环境变量
[[email protected]~]#ls /data/mysqldb/ [[email protected]~]#ls /app/mysql/bin/ aria_chk myisam_ftdump mysql_convert_table_format mysql_plugin replace aria_dump_log myisamlog mysqld mysql_secure_installation resolveip aria_ftdump myisampack mysqld_multi mysql_setpermission resolve_stack_dump aria_pack my_print_defaults mysqld_safe mysqlshow wsrep_sst_common aria_read_log mysql mysqld_safe_helper mysqlslap wsrep_sst_mariabackup innochecksum mysqlaccess mysqldump mysqltest wsrep_sst_mysqldump mariabackup mysqladmin mysqldumpslow mysql_tzinfo_to_sql wsrep_sst_rsync mariadb_config mysqlbinlog mysql_find_rows mysql_upgrade wsrep_sst_xtrabackup mbstream mysqlcheck mysql_fix_extensions mysql_waitpid wsrep_sst_xtrabackup-v2 msql2mysql mysql_client_test mysqlhotcopy mytop myisamchk mysql_config mysqlimport perror [[email protected]~]#echo 'PATH=/app/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh [[email protected]~]#cat /etc/profile.d/mysql.sh PATH=/app/mysql/bin/:$PATH [[email protected]~]#. /etc/profile.d/mysql.sh [[email protected]~]#/app/mysql/scripts/mysql_install_db --basedir=/app/mysql --datadir=/data/mysqldb/3306/data --user=mysql #因为我使用的是Cenots6.9安装的10.12,所以报了一些警告! WARNING: The host 'Centos6-server' could not be looked up with /app/mysql/bin/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 ! Installing MariaDB/MySQL system tables in '/data/mysqldb/3306/data' ... ------------------------------------------------------------------------------------- 警告:无法使用/app/mysql/bin/resolveip查找主机“Centos6-server”。这可能意味着您的libc库与此二进制MariaDB版本不是100%兼容的。 MariaDB守护进程mysqld应该正常工作,但主机名解析不起作用。这意味着你应该使用IP地址而不是主机名 指定MariaDB权限时!在'/data /mysqldb/3306/data'中安装MariaDB /MySQL系统表 ------------------------------------------------------------------------------------- OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system ------------------------------------------------------------------------------------- 要在启动时启动mysqld,必须将support-files/mysql.server复制到系统的正确位置 ------------------------------------------------------------------------------------- PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER ! --->请记住为MariaDB root用户设置密码! To do so, start the server, then issue the following commands: '/app/mysql/bin/mysqladmin' -u root password 'new-password' '/app/mysql/bin/mysqladmin' -u root -h Centos6-server password 'new-password' Alternatively you can run: '/app/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 MariaDB Knowledgebase at http://mariadb.com/kb or the MySQL manual for more instructions. You can start the MariaDB daemon with: cd '/app/mysql' ; /app/mysql/bin/mysqld_safe --datadir='/data/mysqldb/3306/data' You can test the MariaDB daemon with mysql-test-run.pl cd '/app/mysql/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 Consider joining MariaDB's strong and vibrant community: https://mariadb.org/get-involved/ [[email protected]~]#tree -d /data/mysqldb/ /data/mysqldb/ └── 3306 └── data ├── mysql ├── performance_schema └── test [[email protected]~]#ls /app/mysql/support-files/ --->选取适合配置文件 binary-configure my-huge.cnf my-large.cnf my-small.cnf mysql-log-rotate policy wsrep_notify magic my-innodb-heavy-4G.cnf my-medium.cnf mysqld_multi.server mysql.server wsrep.cnf [[email protected]~]#cp /app/mysql/support-files/my-large.cnf /etc/my.cnf cp: overwrite `/etc/my.cnf'? y [[email protected]~]#vim /etc/my.cnf --->修改配置文件 [mysqld] datadir=/data/mysqldb/3306/data [[email protected]~]#cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld --->用给定的模板当作启动配置文件 [[email protected]~]#vim /etc/init.d/mysqld [[email protected]~]#chkconfig --list mysqld service mysqld supports chkconfig, but is not referenced in any runlevel (run 'chkconfig --add mysqld') [[email protected]~]#chkconfig --add mysqld --->加入启动服务 [[email protected]~]#chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off [[email protected]~]#chown -R mysql.mysql /data/mysqldb/3306/ --->修改数据库所属主组 [[email protected]~]#ll -d /data/mysqldb/3306/ drwxr-xr-x 3 mysql mysql 4096 Jan 23 02:29 /data/mysqldb/3306/ [[email protected]~]#chmod -R 700 /data/mysqldb/ --->修改数据库权限 [[email protected]~]#ll -d /data/mysqldb/3306/ drwx------ 3 700 mysql 4096 Jan 23 02:29 /data/mysqldb/3306/ [[email protected]~]#ll /app/mysql/ -d --->给mysql在 /app/mysql添加属组 drwxr-xr-x 12 root root 4096 Jan 23 02:21 /app/mysql/ [[email protected]~]#chgrp -R mysql /app/mysql/ --->给mysql在 /app/mysql添加写权限 [[email protected]~]#chmod 775 /app/mysql/ [[email protected]~]#ll /app/mysql/ -d drwxrwxr-x 12 root mysql 4096 Jan 23 02:21 /app/mysql/ [[email protected]~]#service mysqld start --->启动成功 Starting MySQL.180123 18:54:29 mysqld_safe Logging to '/data/mysqldb/3306/data/Centos6-server.err'. 180123 18:54:29 mysqld_safe Starting mysqld daemon with databases from /data/mysqldb/3306/data .. SUCCESS!
二、教材二进制编译过程
(1) 准备用户
groupadd -r -g 306 mysql
useradd -r -g 306 -u 306 –m –d /app/data mysql(2) 准备数据目录
以/app/data为例,建议使用逻辑卷
chown mysql:mysql /app/data(3) 准备二进制程序
tar xf mariadb-VERSION-linux-x86_64.tar.gz -C /usr/local
cd /usr/local;ln -sv mariadb-VERSION mysql
chown -R root:mysql /usr/local/mysql/(4) 准备配置文件
配置格式:类ini格式,各程序由单个配置文件提供配[prog_name]
配置文件查找次序:后面覆盖前面的配置文件
/etc/my.cnf -->/etc/mysql/my.cnf --> --default-extra-file=/PATH/TO/CONF_FILE --> ~/.my.cnf
mkdir /etc/mysql/
cp support-files/my-large.cnf /etc/mysql/my.cnf
[mysqld]中添加三个选项:
datadir = /app/data
innodb_file_per_table = on
skip_name_resolve = on 禁止主机名解析,建议使用(5)创建数据库文件
cd /usr/local/mysql/
./scripts/mysql_install_db --datadir=/app/data --user=mysql(6)准备日志文件
touch /var/log/mysqld.log
chown mysqld /var/log/mysqld.log(7)准备服务脚本,并启动服务
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
service mysqld start(8)安全初始化
/user/local/mysql/bin/mysql_secure_installation
三、实现多实例
1、准备多实例数据库
[[email protected]~]#mkdir /data/mysqldb/{3306,3307,3308}/{pid,log,etc,data} -pv [[email protected]~]#/app/mysql/scripts/mysql_install_db --basedir=/app/mysql --datadir=/data/mysqldb/3307/data --user=mysql WARNING: The host 'Centos6-server' could not be looked up with /app/mysql/bin/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 ! Installing MariaDB/MySQL system tables in '/data/mysqldb/3307/data' ... 180123 18:59:25 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release. --->'THREAD_CONCURRENCY'已被弃用,并将在未来版本中删除 180123 18:59:25 [Note] /app/mysql/bin/mysqld (mysqld 5.5.59-MariaDB) starting as process 20253 ... --->作为进程20253开始 OK Filling help tables... 180123 18:59:26 [Warning] 'THREAD_CONCURRENCY' is deprecated and will be removed in a future release. 180123 18:59:26 [Note] /app/mysql/bin/mysqld (mysqld 5.5.59-MariaDB) starting as process 20262 ... OK [[email protected]~]#/app/mysql/scripts/mysql_install_db --basedir=/app/mysql --datadir=/data/mysqldb/3308/data --user=mysql ..... [[email protected]~]#tree -d /data/mysqldb /data/mysqldb/ ├── 3306 │ ├── data │ │ ├── mysql │ │ ├── performance_schema │ │ └── test │ ├── etc │ ├── log │ └── pid ├── 3307 │ ├── data │ │ ├── mysql │ │ ├── performance_schema │ │ └── test │ ├── etc │ ├── log │ └── pid └── 3308 ├── data │ ├── mysql │ ├── performance_schema │ └── test ├── etc ├── log └── pid/data/mysqldb [[email protected]~]#vim /data/mysqldb/3307/etc/my.cnf ..... [mysqld] --->修改端口号 datadir=/data/mysqldb/3307/data port=3307 [mysql_safe] --->添加的日志和pid路径 log-error=/data/mysqldb/3307/log/mariadb.log pid-file=/mysqldb/3307/pid/mariadb.pid [[email protected]]#./mysqld start Starting MySQL... [[email protected]]#./mysqld start Starting MySQL... [[email protected]]#ss -ntlp State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 50 *:3306 *:* users:(("mysqld",20163,15)) LISTEN 0 50 *:3307 *:* users:(("mysqld",21976,15)) LISTEN 0 50 *:3308 *:* users:(("mysqld",21662,15))
[[email protected]]#vim mysqld #!/bin/bash port=3307 mysql_user="root" mysql_pwd="centos" cmd_path="/app/mysql/bin" mysql_basedir="/data/mysqldb" mysql_sock="${mysql_basedir}/${prot}/mysql.sock" function_start_mysql() { if [ ! -e "$mysql_sock" ] ; then printf "^[[1;32m Starting MySQL...^[[0m \n" ${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/{port}/etc/my.cnf &> /dev/null & else |--->启动服务配置文件的路径,配置文件内有启动命令 printf "^[[1;5;33m MySQL is running...^[[0m \n" exit fi } function_stop_mysql() { if [ ! -e "$mysql_sock" ] ; then printf "^[[1;5;33m MySQL is stopped...^[[0m \n" exit else printf "^[[1;31m Stoping MySQL...^[[0m \n" ${cmd_path}/mysqladmin -u ${mysql_user } -p${mysql_pwd} -S ${mysql_sock} shutdown fi |--->关闭数据库专用语句,不要用kill关闭,容易导致数据丢失 } |--->并且建议加上密码才能关闭,防止他人误操作 function_restart_mysql() { printf "^[[1;36m Restarting MySQL...^[[0m \n" function_stop_mysql sleep 2 function_start_mysql } case $ in start) function_start_mysql ;; stop) function_stop_mysql ;; restart) function_restart_mysql ;; *) printf "Usage: ${mysql_basedir}/${prot}/bing/mysqld {start|stop|restart}\n" esac [[email protected]]#vim mysqld #!/bin/bash port=3308 mysql_user="root" mysql_pwd="centos" cmd_path="/app/mysql/bin" mysql_basedir="/data/mysqldb" mysql_sock="${mysql_basedir}/${port}/mysql.sock" function_start_mysql() { if [ ! -e "$mysql_sock" ] ; then pritnf "^[[1;32m Starting MySQL...^[[0m \n" ${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf &> /dev/null & else printf "^[[1;5;33m MySQL is running...^[[0m \n" exit fi } function_stop_mysql() { if [ ! -e "$mysql_sock" ] ; then printf "^[[1;5;33m MySQL is stopped...^[[0m \n" exit else printf "^[[1;31m Stoping MySQL...^[[0m \n" ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown fi } function_restart_mysql() { printf "^[[1;36m Restarting MySQL...^[[0m \n" function_stop_mysql sleep 2 function_start_mysql } case $1 in start) function_start_mysql ;; stop) function_stop_mysql ;; restart) function_restart_mysql ;; *) pritnf "Usage: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}\n" esca
8、配置文件内启动过程
[[email protected]~]#vim /etc/my.cnf ..... $exec --datadir="$datadir" --socket="$socketfile" --pid-file="mypidfile" --basedir=/usr --user=mysql > /dev/null 2>&1 & safe_pid=$!
9、配置mysql服务密码及删除空用户
生成数据库时,提示修改密码及删除空用户
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER ! --->请记住为MariaDB root用户设置密码! To do so, start the server, then issue the following commands: '/app/mysql/bin/mysqladmin' -u root password 'new-password' '/app/mysql/bin/mysqladmin' -u root -h Centos6-server password 'new-password' Alternatively you can run: '/app/mysql/bin/mysql_secure_installation' --->建议先使用这个脚本,修改密码并删除空用户
使用命令修改密码
#在centos命令行加密码 [[email protected]~]#mysqladmin -uroot -S /data/mysqldb/3308/mysql.sock password 'centos' [[email protected]~]#/data/mysqldb/3308/mysqld stop Stoping MySQL... [[email protected]~]#/data/mysqldb/3308/mysqld start Starting MySQL... #在mysql里面修改密码,下面登陆的就是使用空用户及空口令登陆的 [[email protected]~]#mysql -S /data/mysqldb/3307/mysql.sock Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 1 Server version: 5.5.59-MariaDB Source distribution Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> select user,password,host from mysql.user; +------+----------+----------------+ | user | password | host | +------+----------+----------------+ | root | | localhost | | root | | centos6-server | | root | | 127.0.0.1 | | root | | ::1 | | | | localhost | | | | centos6-server | +------+----------+----------------+ 6 rows in set (0.01 sec) #使用update命令,修改root账号密码,使用了password()函数,生成加密口令 MariaDB [(none)]> update mysql.user set password=password("centos") where user='root'; Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0 MariaDB [(none)]> select user,password,host from mysql.user; +------+-------------------------------------------+----------------+ | user | password | host | +------+-------------------------------------------+----------------+ | root | *128977E278358FF80A246B5046F51043A2B1FCED | localhost | | root | *128977E278358FF80A246B5046F51043A2B1FCED | centos6-server | | root | *128977E278358FF80A246B5046F51043A2B1FCED | 127.0.0.1 | | root | *128977E278358FF80A246B5046F51043A2B1FCED | ::1 | | | | localhost | | | | centos6-server | +------+-------------------------------------------+----------------+ 6 rows in set (0.00 sec) #使用dorp命令,删除空用户 MariaDB [(none)]> drop user ''@'localhost e; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> drop user ''@'centos6-server'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> drop user '@'::1'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> drop user centos6-server'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> select user,password,host from mysql.user ; +------+-------------------------------------------+----------------+ | user | password | host | +------+-------------------------------------------+----------------+ | root | *128977E278358FF80A246B5046F51043A2B1FCED | localhost | | root | *128977E278358FF80A246B5046F51043A2B1FCED | 127.0.0.1 | +------+-------------------------------------------+----------------+ 2 rows in set (0.00 sec) #修改后,要刷新,才能生效 MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> quit Bye [[email protected]~]#mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 5.5.59-MariaDB Source distribution ..... MariaDB [(none)]> show variables like 'port' ; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | port | 3306 | +---------------+-------+ 1 row in set (0.01 sec)
以上是关于Linux学习之路--Mariadb源码编译安装19---20180120的主要内容,如果未能解决你的问题,请参考以下文章