首页 > 数据库 > MongoDB > 正文

Linux服务器下MariaDB 10自动化安装部署

2020-10-29 18:48:49
字体:
来源:转载
供稿:网友

去MariaDB官网下载MariaDB本文用的是MariaDB 10.1.16
https://downloads.mariadb.org

选择二进制版本,下载到/root目录下
mariadb-10.1.16-linux-x86_64.tar.gz

开始安装
[root@HE3 ~]# cat mariadb_auto_install.sh

###### 二进制自动安装数据库脚本root密码MANAGER将脚本和安装包放在/root目录即可#####################数据库目录/usr/local/mysql##################数据目录/data/mysql##################日志目录/log/mysql##################端口号默认3306其余参数按需自行修改############ ###################author:rrhelei@126.com####################!/bin/bashPATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:~/binexport PATH # Check if user isrootif [ $(id -u) !="0" ]; then  echo "Error: You must be root to runthis script, please use root to install"  exit 1fi clearecho"========================================================================="echo "A tool toauto-compile & install MariaDB-10.1.16 on Redhat/CentOS Linux "echo"========================================================================="cur_dir=$(pwd) #set mysql rootpasswordecho"===========================" mysqlrootpwd="MANAGER"echo -e "Please input the root password of mysql:"read -p "(Default password: MANAGER):" mysqlrootpwdif[ "$mysqlrootpwd" = "" ]; thenmysqlrootpwd="MANAGER"fiecho"==========================="echo"MySQL root password:$mysqlrootpwd"echo"===========================" #which MySQL Versiondo you want to install?echo"===========================" isinstallmysql56="n"echo"Install mariadb-10.1.16,Please input y"read -p "(Please input y , n):" isinstallmysql56 case"$isinstallmysql56" iny|Y|Yes|YES|yes|yES|yEs|YeS|yeS)echo"You will install MariaDB 10.1.16"isinstallmysql56="y";;*)echo"INPUT error,You will exit install MariaDB 10.1.16"isinstallmysql56="n"  exitesac get_char(){SAVEDSTTY=`stty-g`stty-echosttycbreak#ddif=/dev/tty bs=1 count=1 2> /dev/nullstty-rawsttyechostty$SAVEDSTTY}echo""echo"Press any key to start...or Press Ctrl+c to cancel"char=`get_char` # Initialize the installation related content.functionInitInstall(){cat/etc/issueuname -aMemTotal=`free -m | grep Mem | awk '{print $2}'` echo -e "/n Memory is: ${MemTotal} MB "#Settimezonerm -rf /etc/localtimeln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime    #Delete Old Mysql programrpm -qa|grep mysqlrpm -e mysql #DisableSeLinuxif[ -s /etc/selinux/config ]; thensed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/configfi  setenforce 0  }  #Installation ofdepend on and optimization options.functionInstallDependsAndOpt(){cd $cur_dir cat>>/etc/security/limits.conf<<EOF* soft nproc 65535* hard nproc 65535* soft nofile 65535* hard nofile 65535EOF echo"fs.file-max=65535" >> /etc/sysctl.conf} #Install MySQLfunctionInstallMySQL56(){echo"============================Install MariaDB 10.1.16=================================="cd $cur_dir #Backup old my.cnf#rm -f /etc/my.cnfif [ -s /etc/my.cnf]; then  mv /etc/my.cnf /etc/my.cnf.`date+%Y%m%d%H%M%S`.bakfi #mysql directoryconfigurationgroupadd mysql -g512useradd -u 512 -gmysql -s /sbin/nologin -d /home/mysql mysqltar xvf/root/mariadb-10.1.16-linux-x86_64.tar.gzmv /root/mariadb-10.1.16-linux-x86_64 /usr/local/mysqlmkdir -p /data/mysqlmkdir -p /log/mysqlchown -R mysql:mysql/data/mysqlchown -R mysql:mysql/usr/local/mysqlchown -R mysql:mysql/log SERVERID=`ifconfigeth0 | grep "inet addr" | awk '{ print $2}'| awk -F. '{ print$4"3306"}'`cat>>/etc/my.cnf<<EOF[client]port    =3306socket    =/tmp/mysql.sockdefault-character-set=utf8 [mysql]default-character-set=utf8 [mysqld]port    =3306socket    =/tmp/mysql.sockbasedir    =/usr/local/mysqldatadir    =/data/mysqlopen_files_limit  = 3072back_log = 103max_connections =800max_connect_errors =100000table_open_cache =512external-locking =FALSEmax_allowed_packet =32Msort_buffer_size =2Mjoin_buffer_size =2Mthread_cache_size =51query_cache_size =32Mtmp_table_size = 96Mmax_heap_table_size= 96Mslow_query_log = 1slow_query_log_file= /log/mysql/slow.loglog-error =/log/mysql/error.loglong_query_time = 1server-id =$SERVERIDlog-bin =/log/mysql/mysql-binsync_binlog = 1binlog_cache_size =4Mmax_binlog_cache_size= 8Mmax_binlog_size =1024Mexpire_logs_days =60key_buffer_size =32Mread_buffer_size =1Mread_rnd_buffer_size= 16Mbulk_insert_buffer_size= 64Mcharacter-set-server=utf8default-storage-engine= InnoDBbinlog_format = rowinnodb_buffer_pool_dump_at_shutdown= 1innodb_buffer_pool_load_at_startup= 1binlog_rows_query_log_events= 1explicit_defaults_for_timestamp= 1 #log_slave_updates=1#gtid_mode=on#enforce_gtid_consistency=1 #innodb_write_io_threads= 8#innodb_read_io_threads= 8#innodb_thread_concurrency= 0 transaction_isolation= REPEATABLE-READinnodb_additional_mem_pool_size= 16Minnodb_buffer_pool_size= 512M#innodb_data_home_dir=innodb_data_file_path= ibdata1:1024M:autoextendinnodb_flush_log_at_trx_commit= 1innodb_log_buffer_size= 16Minnodb_log_file_size= 512Minnodb_log_files_in_group= 2innodb_max_dirty_pages_pct= 50innodb_file_per_table= 1innodb_locks_unsafe_for_binlog= 0wait_timeout = 14400interactive_timeout= 14400skip-name-resolve[mysqldump]quickmax_allowed_packet =32M EOF    /usr/local/mysql/scripts/mysql_install_db--basedir=/usr/local/mysql --datadir=/data/mysql --defaults-file=/etc/my.cnf--user=mysql cp/usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldchmod 700 /etc/init.d/mysqldchkconfig --add mysqlchkconfig --leve l2345 mysqld on cat >>/etc/ld.so.conf.d/mysql-x86_64.conf<<EOF/usr/local/mysql/libEOFldconfig if [ -d"/proc/vz" ];thenulimit -s unlimitedfi /etc/init.d/mysqldstart  cat >>/etc/profile <<EOFexport PATH=$PATH:/usr/local/mysql/binexport LD_LIBRARY_PATH=/usr/local/mysql/libEOF  /usr/local/mysql/bin/mysqladmin-u root password $mysqlrootpwd cat >/tmp/mysql_sec_script<<EOFuse mysql;delete frommysql.user where user!='root' or host!='localhost';flush privileges;EOF /usr/local/mysql/bin/mysql-u root -p$mysqlrootpwd -h localhost < /tmp/mysql_sec_script #rm -f/tmp/mysql_sec_script  /etc/init.d/mysqldrestart source /etc/profile  echo"============================MariaDB 10.1.16 installcompleted========================="}  functionCheckInstall(){echo"===================================== Check install==================================="clearismysql=""echo"Checking..." if [ -s/usr/local/mysql/bin/mysql ] && [ -s /usr/local/mysql/bin/mysqld_safe ]&& [ -s /etc/my.cnf ]; then echo "MySQL: OK" ismysql="ok" else echo "Error: /usr/local/mysql notfound!!!MySQL install failed."fi if ["$ismysql" = "ok" ]; thenecho "MariaDB 10.1.16 completed! enjoy it."echo"========================================================================="netstat -ntlelseecho"Sorry,Failed to install MySQL!"echo "You cantail /root/mysql-install.log from your server."fi} #The installationlogInitInstall2>&1 | tee /root/mysql-install.logCheckAndDownloadFiles2>&1 | tee -a /root/mysql-install.logInstallDependsAndOpt2>&1 | tee -a /root/mysql-install.logInstallMySQL562>&1 | tee -a /root/mysql-install.logCheckInstall2>&1 | tee -a /root/mysql-install.log

[root@HE3 ~]# mysql -uroot -p

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or /g.
Your MariaDB connection id is 6
Server version: 10.1.16-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

至此,mariadb-10.1.16安装成功

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表