rpm部署mysql_使用rpm快速安装部署MySQL5.6以及主从设置
1、首先再linux上配置好yum源和epel源
若以配置,則直接跳過這步
2、首先,登錄MySQL官網,下載rpm包
https://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-5.6.37-1.el6.x86_64.rpm-bundle.tar
3、將rpm包上傳至服務器,可以是rz上傳,也可以是Xshell的Xftp上傳
這里采用Xftp,將rpm包傳至相關目錄下
4、解壓安裝包
#tar -xvf MySQL-5.6.37-1.el6.x86_64.rpm-bundle.tar
MySQL-shared-5.6.37-1.el6.x86_64.rpm
MySQL-shared-compat-5.6.37-1.el6.x86_64.rpm
MySQL-server-5.6.37-1.el6.x86_64.rpm
MySQL-test-5.6.37-1.el6.x86_64.rpm
MySQL-client-5.6.37-1.el6.x86_64.rpm
MySQL-devel-5.6.37-1.el6.x86_64.rpm
MySQL-embedded-5.6.37-1.el6.x86_64.rpm
5、移除已經安裝的早期版本
由于centos6.5的yum源中默認有MySQL 5.1.73版,因此由于沖突原因,刪除老版本
rpm -qa | grep mysql
rpm -e --nodeps mysql
6、使用rpm命令安裝
rpm -ivh MySQL-*.rpm
warning: MySQL-client-5.6.37-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...? ? ? ? ? ? ? ? ########################################### [100%]
1:MySQL-devel? ? ? ? ? ? ########################################### [ 14%]
2:MySQL-client? ? ? ? ? ########################################### [ 29%]
3:MySQL-test? ? ? ? ? ? ########################################### [ 43%]
4:MySQL-embedded? ? ? ? ########################################### [ 57%]
5:MySQL-shared-compat? ? ########################################### [ 71%]
6:MySQL-shared? ? ? ? ? ########################################### [ 86%]
7:MySQL-server? ? ? ? ? ########################################### [100%]
。。。。。。。。。。。
7、注意,在Mysql-server安裝完成后,要注意下面的提示,查看/root/.mysql_secret文件的內容,記錄下其中l臨時生成的密碼:
查看文件的內容:cat /root/.mysql_secret
The random password set for the root user at Tue Aug? 1 15:42:46 2017 (local time): yRRpKLZ2Y6KFIGG9
8、啟動mysql服務
service mysql start
注意:這里面不是"servicemysqld start",在5.6這個版本里,命令和以前的有點區別。
# service mysql start
Starting MySQL.Logging to '/var/lib/mysql/jksyy.err'.
SUCCESS!
9、查找配置文件
mysql --help | grep my.cnf
10、啟動客戶端
先查看默認密碼
[root@localhost mysql]# cat /root/.mysql_secret
# The random password set for the root user at Wed Aug? 2 10:40:22 2017 (local time): 0Ix5DP8Gi7Yna9nd
連接客戶端,并且輸入密碼
#mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.37
11、更改root用戶密碼
set password for 'root'@'localhost' =password('123456');
創建一個用戶,并且授權
create user admin;
grant all privileges on *.* to admin@'%' with grant option;
flush privileges;
12.主從配置
mysql主從復制
(超簡單)
怎么安裝mysql數據庫,這里不說了,只說它的主從復制,步驟如下:
1、主從服務器分別作以下操作:
1.1、版本一致
1.2、初始化表,并在后臺啟動mysql
1.3、修改root的密碼
2、修改主服務器master:
#vi /etc/my.cnf
[mysqld]
log-bin=mysql-bin? //[必須]啟用二進制日志
server-id=222? ? ? //[必須]服務器唯一ID,默認是1,一般取IP最后一段
3、修改從服務器slave:
#vi /etc/my.cnf
[mysqld]
log-bin=mysql-bin? //[不是必須]啟用二進制日志
server-id=226? ? ? //[必須]服務器唯一ID,默認是1,一般取IP最后一段
4、重啟兩臺服務器的mysql
/etc/init.d/mysql restart
5、在主服務器上建立帳戶并授權slave:
#/usr/local/mysql/bin/mysql -uroot -pmttang
mysql>GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by 'q123456'; //一般不用root帳號,“%”表示所有客戶端都可能連,只要帳號,密碼正確,此處可
用具體客戶端IP代替,如192.168.145.226,加強安全。
6、登錄主服務器的mysql,查詢master的狀態
mysql>show master status;
+------------------+----------+--------------+------------------+
| File? ? ? ? ? ? | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000004 |? ? ? 308 |? ? ? ? ? ? ? |? ? ? ? ? ? ? ? ? |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
注:執行完此步驟后不要再操作主服務器MYSQL,防止主服務器狀態值變化
7、配置從服務器Slave:
mysql>change master to master_host='192.168.145.222',master_user='mysync',master_password='q123456',
master_log_file='mysql-bin.000004',master_log_pos=308;? //注意不要斷開,308數字前后無單引號。
Mysql>start slave;? ? //啟動從服務器復制功能
8、檢查從服務器復制功能狀態:
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.2.222? //主服務器地址
Master_User: mysync? //授權帳戶名,盡量避免使用root
Master_Port: 3306? ? //數據庫端口,部分版本沒有此行
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 600? ? //#同步讀取二進制日志的位置,大于等于Exec_Master_Log_Pos
Relay_Log_File: ddte-relay-bin.000003
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql-bin.000004
Slave_IO_Running: Yes? ? //此狀態必須YES
Slave_SQL_Running: Yes? ? //此狀態必須YES
......
注:Slave_IO及Slave_SQL進程必須正常運行,即YES狀態,否則都是錯誤的狀態(如:其中一個NO均屬錯誤)。
以上操作過程,主從服務器配置完成。
9、主從服務器測試:
主服務器Mysql,建立數據庫,并在這個庫中建表插入一條數據:
mysql> create database hi_db;
Query OK, 1 row affected (0.00 sec)
mysql> use hi_db;
Database changed
mysql>? create table hi_tb(id int(3),name char(10));
Query OK, 0 rows affected (0.00 sec)
mysql> insert into hi_tb values(001,'bobu');
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database? ? ? ? ? |
+--------------------+
| information_schema |
| hi_db? ? ? ? ? ? ? ? |
| mysql? ? ? ? ? ? ? ? |
| test? ? ? ? ? ? ? ? |
+--------------------+
4 rows in set (0.00 sec)
從服務器Mysql查詢:
mysql> show databases;
+--------------------+
| Database? ? ? ? ? ? ? |
+--------------------+
| information_schema |
| hi_db? ? ? ? ? ? ? ? |? ? ? //I'M here,大家看到了吧
| mysql? ? ? ? ? ? ? ? |
| test? ? ? ? ? |
+--------------------+
4 rows in set (0.00 sec)
mysql> use hi_db
Database changed
mysql> select * from hi_tb;? ? ? ? ? //查看主服務器上新增的具體數據
+------+------+
| id? | name |
+------+------+
|? ? 1 | bobu |
+------+------+
1 row in set (0.00 sec)
10、完成:
編寫一shell腳本,用nagios監控slave的兩個yes(Slave_IO及Slave_SQL進程),如發現只有一個或零個yes,就表明主從有問題了,發短信警報吧。
授權的語句:
grant all privileges on *.* to root@'%' with grant option;
create user admin;
grant all privileges on *.* to admin@'%' with grant option;
flush privileges;
從服務器“read_only=1”只讀模式開啟的解鎖命令為設定“read_only=0”;設定全局鎖“flush tables with read lock;”,對應的解鎖模式命令為:“unlock tables;”
set global read_only=1;####給從服務器設置只讀
set global read_only=0;####取消設置只讀屬性
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的rpm部署mysql_使用rpm快速安装部署MySQL5.6以及主从设置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql登陆salt_salt把返回写
- 下一篇: python 网络编程_Python网络