寫在前面 linux
項目到目前爲止,前面將全部應用工程的安裝與配置已闡述完成,今天將要介紹的是數據庫的安裝、配置、主從同步等相關過程redis
至於數據庫的安裝與配置,在以前的文章中也介紹過不少種方法,通常數據庫的幾種安裝方法以下:sql
一、yum安裝數據庫
此種安裝,通常用於內網對數據庫要求不高的環境,如監控服務等vim
二、常規編譯安裝segmentfault
5.5以前的版本可直接使用./configure make && make install 直接進行編譯安裝便可,但以後的版本須要引用第三方軟件cmake,而後進行編譯安裝服務器
三、rpm包安裝架構
下載相應的rpm包進行安裝socket
四、二進制安裝
下載相應版本的二進制安裝包,解壓、初始化便可完成安裝
對於哪一種方法安裝好,按實際生需求來
今天介紹的就是使用二進制安裝包進行安裝mysql
安裝相關依賴庫
yum install libao libao-devel -y
添加用戶
groupadd mysql useradd -g mysql mysql -s /sbin/nologin –M
下載軟件
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86\_64.tar.gz
解壓至目錄
[root@mysql-m ~]# tar zxf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz -C /usr/local/ [root@mysql-m ~]# ln -s /usr/local/mysql-5.7.17-linux-glibc2.5-x86_64 /usr/local/mysql [root@mysql-m mysql]# mkdir /data [root@mysql-m mysql]#chown –R mysql.mysql /data
初始化數據庫
[root@mysql-m ~]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql 2017-09-23T09:14:16.724707Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2017-09-23T09:14:17.698204Z 0 [Warning] InnoDB: New log files created, LSN=45790 2017-09-23T09:14:17.888059Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2017-09-23T09:14:17.977944Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 93b7f20c-a03f-11e7-b91d-000c29d812ec. 2017-09-23T09:14:17.988894Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2017-09-23T09:14:17.995157Z 1 [Note] A temporary**password is generated for root@localhost: csnbtzNIf0-6**
拷貝啓動文件
[root@mysql-m ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@mysql-m ~]# chmod +x /etc/init.d/mysqld [root@mysql-m ~]# /etc/init.d/mysqld start Starting MySQL. SUCCESS! [root@mysql-m ~]# lsof -i :3306 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 1639 mysql 20u IPv6 15683 0t0 TCP *:mysql (LISTEN) [root@mysql-m ~]# ln -s /data/mysql.sock /tmp/
默認登錄是經過/tmp/mysql.sock文件來鏈接mysql,能夠在配置文件裏指定路徑也能夠實現此種效果,不然登陸就會報錯
########以上配置另外的從庫同上述操做###############
其實相關的配置以前的文章也有介紹過,但爲了整個項目的完整性,在此再次介紹一遍整個操做過程
修改主從服務器的配置文件
[root@mysql-m ~]# vim /etc/my.cnf [mysqld] basedir = /usr/local/mysql/ datadir = /data socket = /data/mysql.sock server-id = 1 log-bin = /data/mysql-bin relay-log = /data/master.relay-bin relay-log-info-file = /data/master.relay-log.info user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 replicate-ignore-db=mysql [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
[root@mysql-s ~]# vim /etc/my.cnf [mysqld] basedir=/usr/local/mysql datadir=/data socket=/data/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 server-id = 2 #log-bin = /data/mysql-bin relay-log = /data/slave.relay-bin relay-log-info-file = /data/slave.relay-log.info [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
配置文件註釋就不過多介紹,可參考前面的文章
主庫建立並受權同步的用戶
mysql> grant replication slave on *.* to rep@'10.0.0.%' identified by'123456'; Query OK, 0 rows affected, 1 warning (0.04 sec) mysql> flush privileges; Query OK, 0 rows affected (0.04 sec)
主從服務器重啓服務,主庫進行全備
將全備文件推送至從庫
恢復從庫
執行change master語句
[root@mysql-s ~]# mysql -uroot -p123456 </root/master.sql [root@mysql-s ~]# mysql -uroot -p123456 mysql> change master to -> master_host='10.0.0.11', -> master_port=3306, -> master_user='rep', -> master_password='123456', -> master_log_file='mysql-bin.000001', -> master_log_pos=154; Query OK, 0 rows affected, 2 warnings (0.04 sec) mysql> start slave; Query OK, 0 rows affected (0.02 sec)
查看同步狀態
測試主從同步
主從同步整個過程配置完成,實際生產環境此種架構後面會擴展成讀寫分離,一主多從,雙主多從等,看實際生產需求與我的技術點與學習成本,後續會介紹相關讀寫分離與高可用的架構實戰,敬請期待!!!
redis安裝很是簡單
下載、解壓至指定目錄、啓動便可完成
可參考前面的相關文章介紹
監控安裝這裏也再也不贅述了,前面有大幅文章介紹安裝與配置過程