preface

LNMP Distributed Cluster deployment Practice

  • Nginx+PHP Platform Construction and Load Balancing Configuration
  • (2) NFS File Server Setup and File Buffer Upload Configuration
  • (3) : Setup of MySQL Primary and Secondary Database Server
  • (4) : Memcached Server Construction
  • (5) ThinkPHP Project Deployment
  • Keepalived High Availability Solution (VI)

To review the basic architecture:

This article we deploy 7, 8 machines, MySQL database server.

configuration

MySQL > install MySQL

The mysql version is Generic Linux (Architecture Independent), Compressed TAR Archive(mysql-5.5.61.tar.gz).

# install dependenciesYum -y install GCC - c + + cmake ncurses - devel wget tar at https://downloads.mysql.com/archives/get/file/mysql-5.5.61.tar.gz ZXF mysql - 5.5.61. Tar. GzcdMysql -5.5.61 cmake -ddefault_charset =utf8 -ddefault_collation =utf8_general_ci make && make install &&cd.Copy the code

MySQL > configure MySQL

Configure the directory for saving data and sock files
vi /etc/my.cnf
datadir=/data/mysql
socket=/tmp/mysql.sock

You must grant permissions to the directory
chown -R mysql:mysql /data/mysql

Create a mysql user
useradd -s /sbin/nologin -M mysql  # -m: automatically create user login directory; -m: do not automatically create the user login directory. -s
      
        : specifies the shell used by the user after login.
      

Initialize the database
cd /usr/local/mysql
./scripts/mysql_install_db

Start MySQL and add it to the service
cp support-files/mysql.server /etc/init.d/mysql
chkconfig --add mysql
service mysql start
Open port 3306
netstat -tnlp | grep mysql
iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
service iptables save  If it doesn't work, either update or change the configuration file, as discussed in the previous article
MySQL > select user from MySQL
cd /usr/local/mysql/bin
./mysql
UPDATE mysql.user SET password=password('123456') WHERE user='root';
DELETE FROM mysql.user WHERE user=' ';
FLUSH PRIVILEGES;
EXIT
Copy the code

Implement MySQL primary/secondary replication

  1. After installing mysql on machine 7 (master), clone machine 8 (slave, pay attention to network IP configuration).

  2. Enable bin logs (binary logs used for incremental database backup and inter-database replication) on machine 7 (primary).

vi /etc/my.cnf
[mysqld]
...
log-bin=mysqlbin-log  # indicates the file name mysqlbin-log
server-id=17 # represents the unique ID of the server, the last bit of the available server IP

service mysql restart
cd /data/mysql
ll | grep mysqlbin These logs are used to read database changes when synchronizing data with other servers
Copy the code
  1. Create a user for primary/secondary replication
/usr/local/mysql/bin/mysql -uroot -p123456
GRANT REPLICATION SLAVE ON *.* TO 'slave'@'192.168.177.18' IDENTIFIED BY '123456';
SHOW MASTER STATUS;
EXIT;
Copy the code

  1. Configuring the slave Server
vi /etc/my.cnf
server-id=18

service mysql restart

/usr/local/mysql/bin/mysql -uroot -p123456
CHANGE MASTER TO master_host='192.168.177.17', master_user='slave',
master_password='123456', master_log_file='mysqlbin-log.000001', master_log_pos=263;
START SLAVE;
SHOW SLAVE STATUS \G
Copy the code

LNMP Distributed Cluster deployment Practice

  • Nginx+PHP Platform Construction and Load Balancing Configuration
  • (2) NFS File Server Setup and File Buffer Upload Configuration
  • (3) : Setup of MySQL Primary and Secondary Database Server
  • (4) : Memcached Server Construction
  • (5) ThinkPHP Project Deployment
  • Keepalived High Availability Solution (VI)

dffaceCopyright notice: All articles are valid unless otherwise statedCC BY – NC – SA 4.0License agreement. Reproduced please indicate the source, commercial use is strictly prohibited!