In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will bring you an article on mariadb automation installation and parsing. The editor thinks it's pretty good, so I'll share it for you as a reference. Let's follow the editor and have a look.
Chapter Preview:
1. Brief introduction of mariadb database.
2. Compile and install mariadb manually
3. Automatic installation implementation script
I. mariadb database
MariaDB database management system is a branch of MySQL and is mainly maintained by the open source community. The purpose of licensing MariaDB with GPL is to be fully compatible with MySQL, including API and the command line, making it an easy replacement for MySQL.
MariaDB's transaction-based Maria storage engine replaces MySQL's MyISAM storage engine, which uses a variant of Percona's XtraDB,InnoDB, and branch developers want to provide access to the upcoming MySQL 5.4 InnoDB performance. This version also includes PrimeBase XT (PBXT) and the FederatedX storage engine.
Manual compilation and installation of mariadb
1. Download the binary mariadb installation package
Download http://mariadb.org from the official website
Download: mariadb-10.2.8-linux-x86_64.tar.gz
2. Decompress the downloaded package
Since the installation package customizes the binary program placement directory, the unzipped directory must be customized according to the package. Extract it to the / usr/local/ directory by default, and the name of the extracted directory must be mysql
Decompression operation:
Tarxvf mariadb-10.2.8-linux-x86_64.tar.gz-C/usr/local/
The directory after normal decompression is called mariadb-10.2.8-linux-x86_64, and the data in this directory needs to be placed in the directory called mysql, which is the default of the installation package. There are two ways:
Modify the directory name:
Mv / usr/local/mariadb-10.2.8-linux-x86_64 / usr/local/mysql
2) create a soft link:
Ln-s / usr/local/mariadb-10.2.8-linux-x86_64 / usr/local/mysql
3. Manually create mysql system users
You need to create a system user mysql, which mysql user is used to manage mysql.
Useradd-r-d / app/mariadb-m-s / sbin/nologin mysql
-r: create a system user
-d: create a home directory, which is the directory where the database is stored, so it is as large as possible
-m; force the creation of users, system users do not create users by default.
-s: specifies the login shell type
4. Create a mariadb configuration file
There is a configuration file in the / usr/local/mysql/support-files/ directory. Select one of the appropriate configuration files, copy it to the / etc/mysql/ directory, and rename it to my.cnf.
(1) mkdir/etc/mysql
(2): cp/usr/local/mysql/support-files/my-huge.cnf / etc/my.cnf
You need to make simple changes to the configuration file to take effect:
Vim / etc/mysql/my.cnf
Add the following after [mysqld]:
# the database directory is the home directory where the mysql user is created, and all the database files should be placed here.
Datadir = / app/mariadb
Innodb_file_per_table= on
Skip_name_resolve = on
5. Create a system database
When a system starts, it must have its own database, otherwise it cannot be started, and the system database places some data needed by the system itself.
The installation package itself comes with a script to create a system database, so we don't need to manually create this script in / usr/local/mysql/scripts/mysql_install_db
The change script must be executed in the / usr/local/mysql/ directory because there are files in that directory that the script needs to run.
Cd / usr/local/mysql
. / scripts/mysql_install_db-user=mysql-datadir=/app/mariadb
6. Create a mariadb service startup script
In order to enable the system to start the service, you need to create a service running process, which is included in the installation package: / usr/local/mysql/support-files/mysql.server
You need to copy the running program to the / etc/init.d/ directory and rename it mysqld
Cp / usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld
7. Add mysqld service to the list of running levels
Services need to be added to the run level at which the system can load and run
Chkconfig-add mysqld
Chkconfig-list mysqld can see which runlevels can be turned on.
8. Create mariadb log files and mail files
You must create a mariadb log file and modify the owner of the log file, otherwise mysql system users cannot write to the log data, which will cause the service to fail to start. Also create mail files.
There is a difference between Centos6 and Centos7:
Centos7:
Mkdir / var/log/mariadb/
Touch / var/log/mariadb/mariadb.log
Touch / var/spool/mail/mysql
Chown mysql:mail / var/spool/mail/mysql
Chown mysql / var/log/mariadb/
Chown mysql / var/log/mariadb/mariadb.log
The owner is modified so that mysql users can write to the log file
Centos6:
Touch / var/log/mysqld.log
Touch / var/spool/mail/mysql
Chown mysql:mail / var/spool/mail/mysql
Chown mysql / var/log/mysqld.log
9. Add the environment variable PATH for mariadb
Add a mariadbpath.sh file in the / etc/profile.d/ directory that defines the environment variable PATH.
Echo 'export PATH=/usr/local/mysql/bin:$PATH' > / etc/profile.d/mariadbpath.sh
Run the script to make it effective:
Source / etc/profile.d/mariadbpath.sh
10. Start the service
Since we have created a service startup script, we can start it directly with the service command:
Service mysqld start
To see if it is started, you can determine whether port 3306 is open:
Ss-tnul
11. Run mariadb's own security script
This script is similar to the mariadb initialization script and is located at: / usr/local/mysql/bin/mysql_secure_installation
The specific process is shown in the following figure:
12. Login test
Mysql-u (username)-p (password)
Third, the realization of automatic installation script
1. Automatic installation and display
2. Automatically uninstall the display
Autoinstallmariadb.sh:
#! / bin/bash
# *
# Author: jiake
# QQ:
# Date: 2017-10-12 19:25:27
# Filename: autoinstallmariadb.sh
# Description:
# Copyright (C): All right reserved
# *
Read-p "Please tell me where the mariadb installation package is:" package
Read-p "Please tell me where the mariadb database directory is located:" dbdir
# whether the scan file exists. A non-zero value is returned.
Scanfile () {
Ls $1 & > / dev/null & & return 1 | | return 2
}
# whether the scan file exists. A non-zero value is returned.
Scandir () {
Ls-d "$1" & > / dev/null & & return 3 | | return 4
}
# determine whether the specified software package exists
Echo "find the location of the specified installation package."
Scanfile $package
Achilles?
[$A-eq 2] & & {echo "the specified path to the mariadb installation package is incorrect!" ; exit 110;}
# decompress the installation package
Scandir / usr/local
Blossom?
[$B-eq3] & & {echo "extract the installation package to the specified / usr/local." ; tar xvf $package-C / usr/local/ & > / dev/null;}
# create mysql soft links
Echo "create mysql soft links."
Mulu= `basename $package | sed-r's / (. *)\ .tar.gz /\ 1Uniple'`
Ln-s / usr/local/$mulu / usr/local/mysql
# create a mysql user
Echo "create a mysql system account."
Id mysql & > / dev/null & & userdel-r mysql & > / dev/null
Useradd-r-d $dbdir-m-s / sbin/nologin mysql
# prepare the configuration file
Scandir / etc/mysql
Caterpillar?
[$C-eq4] & & {echo "copy the configuration file." ; mkdir / etc/mysql & > / dev/null;}
Cp / usr/local/mysql/support-files/my-huge.cnf / etc/mysql/my.cnf
# modify the configuration file (since variables cannot be written in sed, the fixed datadir directory is / app/mariadb. If there is any difference, please modify it manually)
Echo "modify the configuration file."
Sed-ri's @\ [mysqld\] @ &\ ndatadir = / app/mariadb\ ninnodb_file_per_table = on\ nskip_name_resolve = on\ nfolk'/ etc/mysql/my.cnf
# create a system database
Echo "create a system database."
Cd / usr/local/mysql/
Scripts/mysql_install_db-user=mysql-datadir=$dbdir & > / dev/null
# copy service script
Echo "copy the service script to the init.d/ directory."
Cp / usr/local/mysql/support-files/mysql.server / etc/init.d/mysqld
Chkconfig-- add mysqld & > / dev/null
# determine the system version
Echo "create database log files."
Version= `cat / etc/redhat-release | sed-r's Universe. * ([0-9])\. ([0-9]). * $/\ 1Cat'`
# create a log file
[$version-eq 7] & & {mkdir / var/log/mariadb/ & > / dev/null; touch/var/ log/mariadb/mariadb.log & > / dev/null; chown mysql/var/log/mariadb/; chown mysql/var/log/mariadb/ mariadb.log;touch/var/spool/mail/mysql;chmod 660 / var/spool/mail/mysql; chown mysql:mail/var/spool/mail/mysql;}
[$version-eq 6] & & {touch / var/log/mysqld.log & > / dev/null;chmod 644 / var/log/mysqld.log; chown mysql:mysql / var/log/mysqld.log; touch / var/spool/mail/mysql;chmod 660 / var/spool/mail/mysql;chown mysql:mail / var/spool/mail/mysql;}
# add environment variable PATH
Echo "add environment variables to the specified / etc/profile.d/mariadbpath.sh file."
Echo 'export PATH=/usr/local/mysql/bin:$PATH' > / etc/profile.d/mariadbpath.sh
Source / etc/profile.d/mariadbpath.sh
# start the service
Echo "start the service."
Service mysqld start & > / dev/null | | echo "Service failed to start! please start it manually."
# run a security script
Echo "run the security script mysql_secure_installation."
Echo-e "\ nY\ njiake\ njiake\ nY\ nN\ nY\ nY\ n" | mysql_secure_installation & > / dev/null
Autodeletemariadb.sh:
#! / bin/bash
# *
# Author: jiake
# QQ:
# Date: 2017-10-14 09:27:29
# Filename: autodeletemariadb.sh
# Description: automatically delete compiled and installed mariadb databases
# Copyright (C): All right reserved
# *
Read-p "Please tell me where the dbdir is:" dbdir
# kill the mysqld process first
Echo "stoping mysqld service."
Service mysqld stop & > / dev/null
# Delete mysql account
Echo "delete mysql number."
Userdel-r mysql & > / dev/null
# Delete chkconfig
Echo "chkconfig del."
Chkconfig-del mysqld
# Delete database directory
Echo "delete dbdir."
Rm-fr $dbdir & > / dev/null
# Delete a service script
Echo "delete mysqld.service"
Rm-f / etc/init.d/mysqld & > / dev/null
# Delete program directory
Echo "delete bindir."
Rm-fr / usr/local/mariadb-* & > / dev/null
Rm-f / usr/local/mysql & > / dev/null
# Delete configuration file directory
Echo "delete configfile."
Rm-fr / etc/mysql & > / dev/null
# Delete log files and mail files
Echo "delete log_file and mail_file."
Version= `cat / etc/redhat-release | sed-r's Universe. * ([0-9])\. ([0-9]). * $/\ 1Cat'`
[$version-eq 7] & & {rm-fr/var/log/mariadb & > / dev/null; rm-f / var/spool/mail/mysql & > / dev/null;}
[$version-eq 6] & & {rm-f/var/log/mysqld.log & > / dev/null; rm-f/var/ spool/mail/mysql & > / dev/null;}
# Delete the environment variable configuration file
Echo "delete path.file."
Rm-f / etc/profile.d/mariadbpath.sh & > / dev/null
Echo "removed mariadb!"
After reading the appeal, have you mastered the method of automatic installation of mariadb? If you want to know more about it, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.