|
一、安装mysql
在150,151上安装mysql,安装步骤如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| 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,把它的内容改为如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
| [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;
在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主从同步已经做好
|
|