【CentOS 7LAMP架構2】,MariaDB安裝與配置#

shallow丿ovehtml


安裝MariaDBmysql

  • cd /usr/lcoal/src
  • wget https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
  • tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
  • mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
  • cd /usr/local/mariadb
  • ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb
  • cp support-files/my-small.cnf /usr/local/mariadb/my.cnf
  • vi /usr/local/mariadb/my.cnf #定義basedir和datadir
  • cp support-file/mysql.server /etc/init.d/mariadb
  • vi /etc/init.d/mariadb #定義basedir、datadir、conf以及啓動參數
  • /etc/init.d/mariadb start

下載MariaDB

[root@localhost ~]# cd /usr/local/src
[root@localhost src]# wget https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
--2017-12-14 17:03:43--  https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
Resolving downloads.mariadb.com (downloads.mariadb.com)... 51.255.94.155, 2001:41d0:1004:249b::
Connecting to downloads.mariadb.com (downloads.mariadb.com)|51.255.94.155|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 541295045 (516M) [application/octet-stream]
Saving to: ‘mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz’

100%[=====================================================>] 541,295,045  322KB/s   in 37m 44s

2017-12-14 17:41:29 (233 KB/s) - ‘mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz’ saved [541295045/541295045]
[root@localhost src]# tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
	#mariadb拆包解壓過程
	.
	.
	.
[root@localhost src]# mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
[root@localhost src]# cd !$
	cd /usr/local/mariadb

編譯

[root@localhost mariadb]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mariadb
Installing MariaDB/MySQL system tables in '/data/mariadb' ...
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:

'./bin/mysqladmin' -u root password 'new-password'
'./bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
'./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 '.' ; ./bin/mysqld_safe --datadir='/data/mariadb'

You can test the MariaDB daemon with mysql-test-run.pl
cd './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/

[root@localhost mariadb]# echo $?
0
[root@localhost mariadb]# ls /data/mariadb/
aria_log.00000001  ib_buffer_pool  ib_logfile0  mysql               test
aria_log_control   ibdata1         ib_logfile1  performance_schema
[root@localhost mariadb]# ls support-files/
binary-configure  my-innodb-heavy-4G.cnf  my-small.cnf         mysql.server  wsrep_notify
magic             my-large.cnf            mysqld_multi.server  policy
my-huge.cnf       my-medium.cnf           mysql-log-rotate     wsrep.cnf
                  test

根據內存大小選擇配置文件,而後適當調整參數linux

配置MariaDB

[root@localhost mariadb]# cp support-files/my-small.cnf /usr/local/mariadb/my.cnf

拷貝啓動腳本

[root@localhost mariadb]# cp support-files/mysql.server /etc/init.d/mariadb

編輯啓動腳本

[root@localhost mariadb]# vi /usr/local/mariadb/my.cnf
# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
# http://dev.mysql.com/doc/mysql/en/option-files.html
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 240K

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (using the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking
server-id       = 1

# Uncomment the following if you want to log updates
#log-bin=mysql-bin

# binary logging format - mixed recommended
#binlog_format=mixed

# Causes updates to non-transactional engines using statement format to be
# written directly to binary log. Before using this option make sure that
# there are no dependencies between transactional and non-transactional
# tables such as in the statement INSERT INTO t_myisam SELECT * FROM
# t_innodb; otherwise, slaves may diverge from the master.
#binlog_direct_non_transactional_updates=TRUE

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/data
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/data
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M

[mysqlhotcopy]
interactive-timeout
[root@localhost mariadb]# vi +46 /etc/init.d/mariadb
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.

# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.

basedir=
datadir=

# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overridden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900

"/etc/init.d/mariadb" 447L, 12227C

將46行basedir和datadir指定路徑 basedir=/usr/local/mariadb datadir=/data/mariadb 而且添加conf=/usr/local/mariadb/my.cnf或conf=$basedir/my.cnf 定義完成後,須要啓動命令,在命令模式下搜索/'start',找到一行爲 bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" & 添加--defaults-file="$conf" 爲 $bindir/mysqld_safe --defaults-file="$conf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" "$@" &sql

檢測是否有mysqld啓動,是則會形成衝突app

[root@localhost mariadb]# ps aux | grep mysql
root       6662  0.0  0.0 112660   976 pts/0    S+   18:29   0:00 grep --color=auto mysql

啓動mariadb

[root@localhost mariadb]# /etc/init.d/mariadb start
Reloading systemd:                                         [  OK  ]
Starting mariadb (via systemctl):                          [  OK  ]
[root@localhost mariadb]# ps aux | grep mariadb
root       6711  0.0  0.0 115392  1748 ?        S    18:32   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/localhost.localdomain.pid
mysql      6827  8.7  2.7 1583876 51500 ?       Sl   18:32   0:01 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mysql --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mysql/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root       6874  0.0  0.0 112660   976 pts/0    S+   18:33   0:00 grep --color=auto mariadb
[root@localhost mariadb]# netstat -ltnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2470/master         
tcp        0      0 0.0.0.0:2049            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:52133           0.0.0.0:*               LISTEN      1496/rpc.statd      
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/systemd           
tcp        0      0 0.0.0.0:20048           0.0.0.0:*               LISTEN      1951/rpc.mountd     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1406/sshd           
tcp        0      0 0.0.0.0:37559           0.0.0.0:*               LISTEN      -                   
tcp6       0      0 ::1:25                  :::*                    LISTEN      2470/master         
tcp6       0      0 :::2049                 :::*                    LISTEN      -                   
tcp6       0      0 :::48771                :::*                    LISTEN      -                   
tcp6       0      0 :::46184                :::*                    LISTEN      1496/rpc.statd      
tcp6       0      0 :::3306                 :::*                    LISTEN      6827/mysqld         
tcp6       0      0 :::111                  :::*                    LISTEN      1/systemd           
tcp6       0      0 :::20048                :::*                    LISTEN      1951/rpc.mountd     
tcp6       0      0 :::22                   :::*                    LISTEN      1406/sshd

問題

[root@localhost mariadb]# ps aux | grep mariadb
root       6711  0.0  0.0 115392  1748 ?        S    18:32   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mysql --pid-file=/data/mysql/localhost.localdomain.pid
mysql      6827  8.7  2.7 1583876 51500 ?       Sl   18:32   0:01 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mysql --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mysql/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root       6874  0.0  0.0 112660   976 pts/0    S+   18:33   0:00 grep --color=auto mariadb
  • 解決方案一 到datadir=/data/mysql註釋掉datadir=/data/mysqlless

  • 解決方案二 到/usr/local/mariadb/my.cnf的[mysqld]下添加datadir = /data/mariadbdom

而後restart,若不行直接killallssh

[root@localhost mariadb]# killall mysqld]
[root@localhost mariadb]# /etc/init.d/mariadb start
Starting mariadb (via systemctl):                          [  OK  ]
[root@localhost mariadb]# ps aux | grep mariadb
root       3078  0.6  0.0 115392  1744 ?        S    05:20   0:00 /bin/sh /usr/local/mariadb/bin/mysqld_safe --defaults-file=/usr/local/mariadb/my.cnf --datadir=/data/mariadb --pid-file=/data/mariadb/localhost.localdomain.pid
mysql      3197  7.2  2.9 1583776 55964 ?       Sl   05:20   0:00 /usr/local/mariadb/bin/mysqld --defaults-file=/usr/local/mariadb/my.cnf --basedir=/usr/local/mariadb --datadir=/data/mariadb --plugin-dir=/usr/local/mariadb/lib/plugin --user=mysql --log-error=/data/mariadb/localhost.localdomain.err --pid-file=/data/mariadb/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
root       3236  0.0  0.0 112660   980 pts/0    S+   05:20   0:00 grep --color=auto mariadb

若ps aux | grep mariadb沒有任何效果,則重啓主機socket

相關文章
相關標籤/搜索