Deploy social networking sites-MySQL master-slave and MFS file system

Source: Internet
Author: User
Tags php language php server svn create database nginx server

Case overview

The company's social networking site in the PHP language development, in order to manage the code developed by PHP programmers, the senior leaders asked to build SVN server version control. The first version of the social networking site is deployed on top of the LNMP platform, with an Nginx server and access to the backend's PHP server via the FASTCGI protocol. To keep your data safe,
Request to build MySQL database master-slave cluster.

The social networking site project contains the user's album feature, allows users to upload photos, upload photos need to use the share
Storage to store. There are many open source solutions available for shared storage, such as MFS, Fastdfs, and so on. Public
Implemented using the MFS Distributed File system, and the MFS is mounted in the relevant directory division of the PHP server to determine

Case implementation

According to the company's needs, the implementation process is broadly divided into the following steps

Deploy the SVN server, create an access account for the PHP Programmer's Repo directory, and notify the programmer to
To import the code

Deploy MySQL master-slave server, create database and table according to PHP Programmer's requirements

Deploying Nginx Servers

Use keepalived to make hot spare for Nginx server

Deploying a PHP Server

Deploy MFS to mount the MFS file system in the relevant directory of the front-end PHP server

Notifies the on-line deployer to be released on-line.

Ensure that database services, PHP services, Nginx Services are started sequentially, and notify testers to start testing,
Site maintenance personnel Check Nginx, PHP and database server is working properly.

This article will deploy MySQL master-slave service with the MFS file system MySQL Master service deployment

Primary server (IP 192.168.100.105)
From the server (IP 192.168.100.106)

MySQL 5.7 Installation
Yum install ncurses ncurses-devel Bison cmake-y # #安装依赖包useradd-S/sbin/nologin mysqltar zxvf mysql-5.7.17.tar.gz-c t Ar zxvf boost_1_59_0.tar.gz-c/usr/local/cd/usr/local/mv boost_1_59_0 boostcd Mysql-5.7.17/cmake-dcmake_install_ Prefix=/usr/local/mysql # # Specifies the installation directory-dmysql_unix_addr=/usr/local/mysql/mysql.sock-dsysconfdir=/etc # # Specify initialization Parameters file directory-dsystemd_pid_dir=/usr/local/mysql-ddefault_charset=utf8 # #指定默认字符集-ddefault_collation=utf8_general_ CI #默认使用的字符集校对规则-dwith_innobase_storage_engine=1-dwith_archive_storage_engine=1-dwith_blackhole_storage_engine= 1-dwith_perfschema_storage_engine=1-dmysql_datadir=/usr/local/mysql/data-dwith_boost=/usr/local/boost # # Specifying the location of the boost library, version 5.7 must be added-dwith_systemd=1!! Note: If there is an error in the process of CMake, when the error is resolved, you need to remove the CMakeCache.txt file from the source directory, and then re-cmake, or the bug is still made && make install # # Long installation time Chown-r mysql.mysql/usr/local/mysql/# #权限设置vi/etc/my.cnf[client]port = 3306default-character-set= Utf8socket =/usr/local/mysql/mysql.sock[mysql]port = 3306defauLt-character-set=utf8socket =/usr/local/mysql/mysql.sock[mysqld]user = mysql # #用户basedir =/usr/local/mysql # #基础目录 DataDir =/usr/local/mysql/data # #数据目录port = 3306 # #端口character_set_server =utf8 # #服务语言设置pid-file =/usr/local/mys Ql/mysqld.pid # #pid文件位置socket =/usr/local/mysql/mysql.sock # #socket文件位置server-id = 1 # #服务IDsql_mode =no_engine_s Ubstitution,strict_trans_tables,no_auto_create_user,no_auto_value_on_zero,no_zero_in_date,no_zero_date,error_ For_division_by_zero,pipes_as_concat,ansi_quoteschown Mysql:mysql/etc/my.cnfecho ' PATH=/usr/local/mysql/bin:/usr /local/mysql/lib: $PATH ' >>/etc/profileecho ' export PATH ' >>/etc/profilesource/etc/profile## easy to use MySQL command , set environment variables/usr/local/mysql/bin/mysqld--initialize-insecure--user=mysql--basedir=/usr/local/mysql--datadir=/usr/ local/mysql/data## initializing the database CP Usr/lib/systemd/system/mysqld.service/usr/lib/systemd/system/systemctl Daemon-reloadsystemctl Start MYSQLDNETSTAT-ANPT | grep 3306## 3306 Port Open service open successfully SystEmctl Enable mysqldmysqladmin-u root-p password "abc123" to root account set password for abc123 
MySQL Master-slave replication
Vim/etc/my.cnf[mysqld]binlog-ignore-db=mysql,information_schemacharacter_set_server=utf8log_bin= from the primary and the MySQL server Mysql_binserver_id=1 # # server_id is not the same as the master-slave server Log_slave_updates=truesync_binlog=1auto_increment_increment=2auto_ Increment_offset=1systemctl Restart MYSQLD grant permissions from server on primary MySQL mysql-u root-pgrant replication Slave on * * to ' Replicati On ' @ ' 192.168.100.% ' identified by ' 123456 '; show master status; +-------------------+----------+--------------+------------------+| File | Position | binlog_do_db | binlog_ignore_db |+-------------------+----------+--------------+------------------+|      master-bin.000002 |              335 |                  | |+-------------------+----------+--------------+------------------+ mysql-u Root-pchange master to master_ from the server Host= ' 192.168.100.105 ', master_user= ' replication ', master_password= ' 123456 ', master_log_file= ' mysql_bin.000002 ',  Master_log_pos=335;start slave;show slave status \g; Slave_io_running:yes slave_sql_running:yes## appearedThis two yes indicates that MySQL master-slave replication is complete 
MFS File System Deployment

MFS Master (IP 192.168.100.107)
MFS Metalogger (IP 192.168.100.108)
MFS Chunk1 (IP 192.168.100.109)
MFS Chunk2 (IP 192.168.100.110)

MFS Master
yum install zlib-devel gcc gcc-c++ male -yuseradd -s /sbin/nologin mfstar xzvf mfs-1.6.27-5.tar.gzcd mfs-1.6.27-5./configure --prefix=/usr/local/mfs  ##安装目录--with-default-user=mfs    ##默认用户--with-default-group=mfs    ##默认用户基本组--disable-mfschunkserver    ##不启动节点服务器--disable-mfsmount     ##不启动mount服务器make && make installcd /usr/local/mfs/etc/mfs/cp mfsmaster.cfg.dist mfsmaster.cfgcp mfsexports.cfg.dist mfsexports.cfg    ##挂载权限cp mfstopology.cfg.dist mfstopology.cfg     ##架构感知cd/usr/local/mfs/var/mfscp metadata.mfs.empty metadata.mfs  ##防断电/usr/local/mfs/sbin/mfsmaster start  ##启动服务/usr/local/mfs/sbin/mfsmaster -s ##停止服务用这条命令
MFS Metalogger
yum install zlib-devel gcc gcc-c++ male -yuseradd -s /sbin/nologin mfstar xzvf mfs-1.6.27-5.tar.gzcd mfs-1.6.27-5./configure --prefix=/usr/local/mfs  ##安装目录--with-default-user=mfs    ##默认用户--with-default-group=mfs    ##默认用户基本组--disable-mfschunkserver    ##不启动节点服务器--disable-mfsmount     ##不启动mount服务器make && make installcd /usr/local/mfs/etc/mfs/cp mfsmetalogger.cfg.dist mfsmetalogger.cfgvi mfsmetalogger.cfgMASTER_HOST = 192.168.100.107/usr/local/mfs/sbin/mfsmetalogger start  ##启动服务/usr/local/mfs/sbin/mfsmetalogger -s  ##停止服务用这条命令
MFS Chunk
两台Chunk服务器的配置相同yum install zlib-devel gcc gcc-c++ male -yuseradd -s /sbin/nologin mfstar xzvf mfs-1.6.27-5.tar.gzcd mfs-1.6.27-5./configure --prefix=/usr/local/mfs  ##安装目录--with-default-user=mfs    ##默认用户--with-default-group=mfs    ##默认用户基本组--disable-mfsmaster    ##不启动主服务器--disable-mfsmount     ##不启动mount服务器make && make installcd /usr/local/mfs/etc/mfs/cp mfschunkserver.cfg.dist mfschunkserver.cfgcp mfshdd.cfg.dist mfshdd.cfgvim mfschunkserver.cfgMASTER_HOST = 192.168.100.107vim mfshdd.cfg添加一行/datamkdir /datachown -R mfs:mfs /data/usr/local/mfs/sbin/mfschunkserver start   ##启动服务/usr/local/mfs/sbin/mfschunkserver -s     ##停止服务用这条命令
MFS Client

Since the MFS file system is attached to the front-end PHP server as a storage for uploading images to the user, the MFS client needs to be installed on the PHP server

安装FUSE,MFS客户端依赖于FUSEtar xzvf fuse-2.9.2.tar.gzcd fuse-2.9.2./configuremake && make installvi /etc/profileexport PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH## 设置环境变量source /etc/profile安装mfs客户端yum install zlib-devel gcc gcc-c++ male -yuseradd -s /sbin/nologin mfstar xzvf mfs-1.6.27-5.tar.gzcd mfs-1.6.27-5./configure --prefix=/usr/local/mfs  ##安装目录--with-default-user=mfs    ##默认用户--with-default-group=mfs    ##默认用户基本组--disable-mfschunkserver ##不启动节点服务器--enable-mfsmount     ##启动mount服务器make && make installmodprobe fuse          ##加载fuse模块到内核/usr/local/mfs/bin/mfsmount /var/www/html/webphp/uploads/photos -H 192.168.100.107   ##将MFS 文件系统 挂载到 PHP服务器上df -hT## 查看挂载情况

Deploy social networking sites-MySQL master-slave and MFS file system

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.