mysql主從搭建-源碼篇

一、安裝mysql

150,151上安裝mysql,安裝步驟如下:

yum install  gcc-c++ cmake ncurses-devel bison perl -y
useradd  -s  /sbin/nologin  mysql 
mkdir  -p  /data/mysql
chown  -R  mysql.mysql  /data/mysql
tar –zxvf mysql-5.5.44.tar.gz
cd  mysql-5.5.44
cmake  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
-DMYSQL_DATADIR=/data/mysql -DWITH_MYISAM_STORAGE_ENGINE=1            
-DWITH_INNOBASE_STORAGE_ENGINE=1  
-DWITH_MEMORY_STORAGE_ENGINE=1 
-DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 
-DENABLED_LOCAL_INFILE=1 
-DWITH_PARTITION_STORAGE_ENGINE=1  
-DEXTRA_CHARSETS=all  
-DDEFAULT_CHARSET=utf8  
-DDEFAULT_COLLATION=utf8_general_ci 
-DWITH_DEBUG=0 -DMYSQL_USER=mysql 
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock
make  -j2   &&   make install



二、配置mysql

在150上做如下操作:

cp /usr/local/src/mysql-5.5.44/support-files/mysql.server  /etc/init.d/mysqld

chmod  755  /etc/init.d/mysqld

編輯/etc/my.cnf,把它的內容改爲如下:

[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
user = mysql
server_id = 1
port = 3306
socket = /tmp/mysql.sock
datadir = /data/mysql
old_passwords = 1
lower_case_table_names = 1
character-set-server = utf8
default-storage-engine = MYISAM
log-bin = bin.log
log-error = error.log
pid-file = mysql.pid
long_query_time = 2
slow_query_log
slow_query_log_file = slow.log
binlog_cache_size = 4M
binlog_format = mixed
max_binlog_cache_size = 16M
max_binlog_size = 1G
expire_logs_days = 30
ft_min_word_len = 4
back_log = 512
max_allowed_packet = 64M
max_connections = 4096
max_connect_errors = 100
join_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 2M
sort_buffer_size = 2M
query_cache_size = 64M
table_open_cache = 10000
thread_cache_size = 256
max_heap_table_size = 64M
tmp_table_size = 64M
thread_stack = 192K
thread_concurrency = 24
local-infile = 0
skip-show-database
skip-name-resolve
skip-external-locking
connect_timeout = 600
interactive_timeout = 600
wait_timeout = 600
#*** MyISAM
key_buffer_size = 512M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 64M
myisam_max_sort_file_size = 1G
myisam_repair_threads = 1
concurrent_insert = 2
myisam_recover
#*** INNODB
innodb_buffer_pool_size = 16G
innodb_additional_mem_pool_size = 32M
innodb_data_file_path = ibdata1:1G;ibdata2:1G:autoextend
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 2
innodb_lock_wait_timeout = 120
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_thread_concurrency = 16
innodb_open_files = 10000
#innodb_force_recovery = 4
#*** Replication Slave
read-only
#skip-slave-start
relay-log = relay.log
log-slave-updates

/usr/local/mysql/scripts/mysql_install_db  --basedir=/usr/local/mysql   --datadir=/data/mysql  --user=mysql

/etc/init.d/mysqld  start

echo "PATH=$PATH:/usr/local/mysql/bin">>/etc/profile

source  /etc/profile

在151上的操作和150一樣,只是在my.cnf文件裏將server-id 改爲2,log-bin=bin-log  去掉


三、配置mysql主從

在150上操作:

grant replication slave on *.* to tongbu@'192.168.10.151'identified by '123456';    #授權

show masterstatus;  

wKiom1XYc92SakLBAADCW5jR6Zk596.jpg

在151上操作:

change master to

master_host='192.168.10.150',master_user='tongbu',master_password='123456',master_log_file='bin.000003',master_log_pos=262;

flush privileges;   ##刷新權限

slave start;        ##開啓從

show  slave  status\G;

查看mysql主從狀態,如果看到如下所示的兩個YES就表示mysql主從同步已經做好

wKiom1XYdAHg9jZCAAGTCebcFOc418.jpg


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章