189 8069 5689

LNMP博客以及数据库分离搭建实战

nginx搭建命令

创新互联专注为客户提供全方位的互联网综合服务,包含不限于网站设计制作、网站设计、海曙网络推广、小程序定制开发、海曙网络营销、海曙企业策划、海曙品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供海曙建站搭建服务,24小时服务热线:18982081108,官方网址:www.cdcxhl.com

cd /home/oldboy/tools 安装存放软件包路径

yum install openssl openssl-devel -y 安装Nginx所需的库、和加密协议 

yum install pcre pcre-devel -y 安装Nginx所需的库、和加密协议

rpm -qa openssl-devel pcre-devel  openssl openssl-devel 检查是否安装好

wget -q http://nginx.org/download/nginx-1.6.3.tar.gz 下载软件包

useradd www -s /sbin/nologin -M  创建用户

tar xf nginx-1.6.3.tar.gz 解压软件

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/ 编译安装

make 

make install

ln -s /application/nginx-1.6.3/ /application/nginx 

/application/nginx/sbin/nginx 开启服务

ps -ef|grep nginx 检查

创建网页目录

[root@web02 html]# mkdir {www,bbs,blog} -p

[root@web02 www]# echo "www.etiantian.org" >index.html

修改主配置文件

添加access日志及虚拟主机目录

    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;

创建存放虚拟主机的目录

[root@web02 conf]# mkdir extra

[root@web02 extra]# touch www.conf

[root@web02 extra]# touch bbs.conf

[root@web02 extra]# touch blog.conf

修改每个虚拟主机的conf目录

   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;

        }

设置开机启动

[root@web02 oldboy]# echo "/application/nginx/sbin/nginx " >>/etc/rc.local 

[root@web02 oldboy]# tail -1 /etc/rc.local

/application/nginx/sbin/nginx 

MySQL搭建命令

安装MySQL

上传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 创建用户和授权目录

chown -R mysql.mysql /application/mysql/ 创建用户和授权目录

cd /application/mysql 

./scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data/ 初始化时数据库

ll data/

\cp support-files/my-small.cnf  /etc/my.cnf 创建基本需求

cp support-files/mysql.server /etc/init.d/mysqld 创建基本需求

chmod +x /etc/init.d/mysqld  给执行权限

sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld 修改配置文件

/etc/init.d/mysqld start 开启服务、

netstat -lntup|grep mysql 检查

echo "PATH="/application/mysql/bin:$PATH"" >>/etc/profile

chkconfig --add mysqld 开启服务

chkconfig mysqld on 开启服务

cp -a /application/mysql/bin/* /usr/local/sbin/ 

ln -s /application/mysql/bin/* /usr/local/sbin/

mysql 

1、安装PHP基础库

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

需要先安装支持的软件包

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相关扩展库

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

解压php安装包,编辑

上传PHP包

tar xf php-5.5.32.tar.gz 解压php安装包

./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

配置php解析文件

cp php.ini-production /application/php/lib/php.ini

配置php-fpm配置文件

cp php-fpm.conf.default php-fpm.conf

启动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 

        $link_id=mysql_connect('localhost','root','oldboy123') or mysql_error();

        if($link_id){

                echo "mysql successful by oldboy !";

        }else{

                echo mysql_error();

        }

?>

搭建blog命令

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;

下载博客安装

 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 

分离命令

wed命令

mysqldump -uroot -poldboy123 wordpress -B |gzip>bak.sql.gz

scp bak.sql.gz  root@10.0.0.51:/tmp

数据库MySQL命令

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;

更改.8配置文件 wp-config.php

32 define('DB_HOST', '172.16.1.51');

关闭本地数据库

/etc/init.d/mysqld stop

chkconfig mysqld off

成功。

2、将blog的资源文件迁移到NFS

[root@web01 blog]# tree wp-content/uploads/

资源目录为:wp-content/uploads/

nfs命令

echo "/uploads 172.16.1.0/24(rw,sync)" /etc/exports

MySQL数据库命令

mount -t nfs  172.16.1.31:/uploads /application/nginx/html/blog/

根据老男孩老师的讲解,和实际操作搭建出来


名称栏目:LNMP博客以及数据库分离搭建实战
文章链接:http://cdxtjz.cn/article/ipcegp.html

其他资讯