mysql master slave yum 卸載selinux yum remove selinux* -y 所涉及到軟件版本 mysql-5.1.40.tar.gz 將上述軟件包都放到/software/mysql下 ---------------------------------------------------------------- 一 解壓、安裝mysql tar zxvf mysql-5.1.40.tar.gz cd mysql-5.1.40 ./configure --prefix=/usr/local/mysql --with-extra-charsets=all --with-plugins=all 如果提示error: No curses/termcap library found yum以下內容: yum list|grep ncurses yum -y install ncurses-devel yum install ncurses-devel make make install 添加mysql用戶和組 groupadd mysql useradd -g mysql mysql 拷貝mysql配置文件my.cnf cp support-files/my-medium.cnf /etc/my.cnf 初始化數據庫 /usr/local/mysql/bin/mysql_install_db --user=mysql 以下步驟目的是把數據文件放到/data/(早期數據磁盤是單獨掛載到此目錄下的)目錄下,方便遷移。可以選作 ******************** mkdir /data/mysqldata cp -au /usr/local/mysql/var/* /data/mysqldata rm -rf /usr/local/mysql/var/ cd /usr/local/mysql/ ln -s /data/mysqldata var chown -R mysql /data/mysqldata/ chgrp -R mysql /data/mysqldata/ ********************* 添加環境變量 vi /etc/profile 添加 PATH=$PATH:/usr/local/mysql/bin/ source /etc/profile 關閉啟動 mysqladmin -uroot -p shutdown /usr/local/mysql/bin/mysqld_safe --user=mysql & **安裝最好采用centos4.8環境和rpm包安裝,和公網保持一致,避免沒必要的麻煩,如果想更換版本要進行測試** GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON bankaccount.* TO custom@localhost IDENTIFIED BY 'stupid'; GRANT all privileges ON *.* TO root@'172.16.4.44' IDENTIFIED BY '123456'; 調整 mysql>use mysql 刪除用於本機匿名連接的空密碼帳號 mysql>delete from user where user=""; 更改root密碼 mysql>update user set Password=password('newpassword') where User='root'; mysql>flush privileges; 授權新用戶 mysql>grant all privileges on DB.* to user@'172.22.5.%' identified by '123456'; 移除用戶 revoke all on *.* from dba@localhost; 二 主從配置 保證主庫和從庫的server-id不能一樣 1) 主庫 mysql > GRANT REPLICATION SLAVE ON *.* TO repl@'172.22.5.%' IDENTIFIED BY '123456'; mysql > FLUSH TABLES WITH READ LOCK dump一份數據庫的sql文件,完成後。 mysql >show master status; +------------------+-----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+-----------+--------------+------------------+ | mysql-bin.000001 | 106 | | | +------------------+-----------+--------------+------------------+ 記錄一下status文件 mysql> UNLOCK TABLES; 2) 從庫 把sql文件拷貝到從庫上,並source mysql>CHANGE MASTER TO MASTER_HOST='172.22.5.22', MASTER_USER='repl', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=106; mysql>start slave; mysql>show slave status; ---------------------------------------------------------------- 七 涉及其他關聯 1.內核參數調優 2.iptables防火牆策略(開放80等端口) 3.使用iptables不跟蹤連接,解決連接跟蹤問題(鏈接跟蹤表滿了,導致不能創建新的連接) 3.利用iptables-connlimit模塊控制並發連接數(防止使用工具刷web頁面等) 4.lvs後端realserver配置