Practice of LNMP blog and database separation
Nginx build command
Cd / home/oldboy/tools installation storage package path
Yum install openssl openssl-devel-y installs the libraries and encryption protocols required for Nginx
Yum install pcre pcre-devel-y installs the libraries and encryption protocols required for Nginx
Rpm-qa openssl-devel pcre-devel openssl openssl-devel check to see if it is installed
Wget-Q http://nginx.org/download/nginx-1.6.3.tar.gz download package
Useradd www-s / sbin/nologin-M create user
Tar xf nginx-1.6.3.tar.gz decompression software
Cd nginx-1.6.3
. / configure-- user=www-- group=www-- with-http_ssl_module-- with-http_stub_status_module-- prefix=/application/nginx-1.6.3/ compilation installation
Make
Make install
Ln-s / application/nginx-1.6.3/ / application/nginx
/ application/nginx/sbin/nginx activate the service
Ps-ef | grep nginx check
Create a web page directory
[root@web02 html] # mkdir {www,bbs,blog}-p
[root@web02 www] # echo "www.etiantian.org" > index.html
Modify the master configuration file
Add access log and virtual host directory
Log_format main'$remote_addr-$remote_user [$time_local] "$request"'
'$status $body_bytes_sent "$http_referer"'
'"$http_user_agent"$http_x_forwarded_for"'
# nginx vhosts config
Include extra/www.conf
Include extra/bbs.conf
Include extra/blog.conf
Create a directory where the virtual host is stored
[root@web02 conf] # mkdir extra
[root@web02 extra] # touch www.conf
[root@web02 extra] # touch bbs.conf
[root@web02 extra] # touch blog.conf
Modify the conf directory of each virtual host
Server {
Listen 80
Server_name www.etiantian.org etiantian.org
Location / {
Root html/www
Index index.html index.htm
}
Access_log logs/access_www.log main
}
Set up boot boot
[root@web02 oldboy] # echo "/ application/nginx/sbin/nginx" > > / etc/rc.local
[root@web02 oldboy] # tail-1 / etc/rc.local
/ application/nginx/sbin/nginx
MySQL build command
Install MySQL
Upload MySQL
Ls mysql-5.5.49-linux2.6-x86_64.tar.gz
Tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz
Mkdir / application-p
Mv mysql-5.5.49-linux2.6-x86_64 / application/mysql-5.5.49
Ln-s / application/mysql-5.5.49 / application/mysql
Useradd mysql-s / sbin/nologin-M creates user and authorization directories
Chown-R mysql.mysql / application/mysql/ create user and authorization directories
Cd / application/mysql
. / scripts/mysql_install_db-- user=mysql-- basedir=/application/mysql-- Database when datadir=/application/mysql/data/ initializes
Ll data/
\ cp support-files/my-small.cnf / etc/my.cnf create basic requirements
Cp support-files/mysql.server / etc/init.d/mysqld creates basic requirements
Chmod + x / etc/init.d/mysqld gives executive permission
Sed-I's application/mysql/bin/mysqld_safe _ etc/init.d/mysqld modify the configuration file for usr _ application/mysql/bin/mysqld_safe _ etc/init.d/mysqld
/ etc/init.d/mysqld start starts the service,
Netstat-lntup | grep mysql check
Echo "PATH=" / application/mysql/bin:$PATH "" > > / etc/profile
Chkconfig-add mysqld starts the service
Chkconfig mysqld on enables the service.
Cp-a / application/mysql/bin/* / usr/local/sbin/
Ln-s / application/mysql/bin/* / usr/local/sbin/
Mysql
1. Install the PHP basic library
Yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel-y
Yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel-y
Rpm-qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel
You need to install supported packages first.
Cd / home/oldboy/tools
Wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
Tar zxf libiconv-1.14.tar.gz
Cd libiconv-1.14
. / configure-- prefix=/usr/local/libiconv
Make
Make install
Cd.. /
2. PHP-related extension libraries
Wget-O / etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
Yum-y install libmcrypt-devel
Yum-y install mhash
Yum-y install mcrypt
Rpm-qa libmcrypt-devel mhash mcrypt
Extract the php installation package, edit
Upload PHP package
Tar xf php-5.5.32.tar.gz unzipped php installation package
. / configure\
-- prefix=/application/php5.5.32\
-- with-mysql=/application/mysql/\
-- with-pdo-mysql=mysqlnd\
-- with-iconv-dir=/usr/local/libiconv\
-- with-freetype-dir\
-- with-jpeg-dir\
-- with-png-dir\
-- with-zlib\
-- with-libxml-dir=/usr\
-- enable-xml\
-- disable-rpath\
-- enable-bcmath\
-- enable-shmop\
-- enable-sysvsem\
-- enable-inline-optimization\
-- with-curl\
-- enable-mbregex\
-- enable-fpm\
-- enable-mbstring\
-- with-mcrypt\
-- with-gd\
-- enable-gd-native-ttf\
-- with-openssl\
-- with-mhash\
-- enable-pcntl\
-- enable-sockets\
-- with-xmlrpc\
-- enable-soap\
-- enable-short-tags\
-- enable-static\
-- with-xsl\
-- with-fpm-user=www\
-- with-fpm-group=www\
-- enable-ftp\
-- enable-opcache=no
Ln-s / application/mysql/lib/libmysqlclient.so.18 / usr/lib64/
Touch ext/phar/phar.phar
Make
Make install
Ln-s / application/php5.5.32/ / application/php
Ls / application/php/
Cp php.ini-production / application/php/lib/php.ini
Configure php parsing file
Cp php.ini-production / application/php/lib/php.ini
Configure php-fpm Profil
Cp php-fpm.conf.default php-fpm.conf
Start php-fpm
/ application/php/sbin/php-fpm
Lsof-I: 9000
Ps-ef | grep php-fpm
Root@web01 extra] # cat blog.conf
Server {
Listen 80
Server_name blog.etiantian.org
Location / {
Root html/blog
Index index.html index.htm
}
Location. *\. (php | php5)? ${
Root html/blog
Fastcgi_pass 127.0.0.1:9000
Fastcgi_index index.php
Include fastcgi.conf
}
}
[root@web01 extra] #.. /.. / sbin/nginx-t
Nginx: the configuration file / application/nginx-1.6.3//conf/nginx.conf syntax is ok
Nginx: configuration file / application/nginx-1.6.3//conf/nginx.conf test is successful
[root@web01 extra] #.. / sbin/nginx-s reload
[root@web01 blog] # cat test_mysql.php
Build blog command
Mysql-uroot-poldboy123
Create database wordpress
Show databases
Grant all on wordpress.* to wordpress@'localhost' identified by '123456'
Select user,host from mysql.user
Show grants for wordpress@'localhost'
Flush privileges
Download blog installation
Wget https://cn.wordpress.org/wordpress-4.5.1-zh_CN.tar.gz
Ll
Tar xf wordpress-4.5.1-zh_CN.tar.gz
Ls wordpress
Cp-a wordpress/* / application/nginx/html/blog/
Ls / application/nginx/html/blog/
Chown-R www.www / application/nginx/html/blog/
Ls / application/nginx/html/blog/
Ls / application/nginx/html/blog/-l
History
Detach command
Wed command
Mysqldump-uroot-poldboy123 wordpress-B | gzip > bak.sql.gz
Scp bak.sql.gz root@10.0.0.51:/tmp
Database MySQL command
Cd / tmp
Gzip xf bak.sql.tar.gz
Mysql-uroot-poldboy123-e "show databases like 'wordpress';"
Mysql-uroot-poldboy123-e "use wordpress;show tables;"
Mysql-uroot-poldboy123
Grant all on wordpress.* to wordpress@'172.16.1.%' identified by '123456'
Flush privileges
Select user,host from mysql.user
Change .8 profile wp-config.php
32 define ('DB_HOST',' 172.16.1.51')
Close the local database
/ etc/init.d/mysqld stop
Chkconfig mysqld off
Success.
2. Migrate the resource files of blog to NFS
[root@web01 blog] # tree wp-content/uploads/
The resource directory is: wp-content/uploads/
Nfs command
Echo "/ uploads 172.16.1.0 echo 24 (rw,sync)" / etc/exports
MySQL database command
Mount-t nfs 172.16.1.31:/uploads / application/nginx/html/blog/
Build it according to the explanation of the old boy teacher and the actual operation.