当前位置: 澳门新濠3559 > 操作系统 > 正文

5.6.30  依赖软件包版本, 卸载本机自带MySQL

时间:2019-11-28 21:09来源:操作系统
********测试前向本地hosts文件添加解析,windows下测试也必须添加hosts解析******** 快速安装方法:     1) 解决PHP软件的依赖关系         yum install zlib-devel libxml2-devel libjpeg-devellibjpeg

********测试前向本地hosts文件添加解析,windows下测试也必须添加hosts解析********

快速安装方法:

    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

            #查看是否下载成功

 

 

        libiconv软件安装--和字符集转换相关的软件

      

 #mkdir -p /server/tools

        cd /server/tools

           #wget

        tar zxf libiconv-1.14.tar.gz

        cd libiconv-1.14

        ./configure --prefix=/usr/local/libiconv

        make

        make install

        cd ../

       

 

                   和数据加密相关的三个软件安装

        #wget -O /etc/yum.repos.d/epel.repo

          #更换源

      yum -y install libmcrypt-devel mhash mcrypt

         #查看是否安装成功

rpm -qa libmcrypt-devel mhash mcrypt

                  

部署LNMP架构Blog博客平台,部署lnmp架构blog

部署环境:VM虚拟机  操作系统:CentOS-6.8-x64  IP地址:192.168.31.91

Mysql数据库版本:5.6.34  Cmake软件包版本:3.5.2

Nginx软件包版本:1.10.2  PHP软件包版本:5.6.30  依赖软件包版本:libiconv-1.14.tar.gz

免费开源博客软件包版本:wordpress-4.7.2-zh_CN.tar.gz

 

作者:惟净(刘琪)

软件下载地址:

 

[[email protected] ~]# setenforce 0

[[email protected] ~]# /etc/init.d/iptables stop

[[email protected] ~]# yum groupinstall "开发工具" -y

[[email protected] ~]# yum install vim wget pcre pcre-devel openssl openssl-devel -y

 

开始安装Nginx --->

[[email protected] Nginx]# tar xvzf nginx-1.10.2.tar.gz

[[email protected] Nginx]# cd nginx-1.10.2

[[email protected] nginx-1.10.2]# useradd nginx -s /sbin/nologin -M

[[email protected] nginx-1.10.2]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.10.2 --with-http_stub_status_module --with-http_ssl_module && make && make install

[[email protected] nginx-1.10.2]# ln -s /usr/local/nginx-1.10.2/ /usr/local/nginx

[[email protected] nginx-1.10.2]# cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bck

[[email protected] nginx-1.10.2]# /usr/local/nginx/sbin/nginx

[[email protected] nginx-1.10.2]# netstat -tnlp | grep :80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      6338/nginx

 

开始安装Mysql --->

[[email protected] Mysql]# tar xvzf cmake-3.5.2.tar.gz

[[email protected] Mysql]# cd cmake-3.5.2

[[email protected]1 cmake-3.5.2]# yum install ncurses-devel -y

[[email protected] cmake-3.5.2]# ./configure --prefix=/usr/local/cmake && make && make install

[[email protected] Mysql]# tar xvzf mysql-5.6.34.tar.gz

[[email protected] Mysql]# cd mysql-5.6.34

[[email protected] Mysql]# cd mysql-5.6.34

[[email protected] mysql-5.6.34]# /usr/local/cmake/bin/cmake
>  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
>  -DMYSQL_DATADIR=/usr/local/mysql/data
>  -DSYSCONFDIR=/etc
>  -DWITH_READLINE=1
>  -DMYSQL_TCP_PORT=3306
>  -DMYSQL_UNIX_ADDR=/tmp/mysql.sock
>  -DENABLED_LOCAL_INFILE=1
>  -DEXTRA_CHARSETS=all
>  -DDEFAULT_CHARSET=utf8
>  -DDEFAULT_COLLATION=utf8_general_ci

[[email protected] mysql-5.6.34]# make && make install

[[email protected] mysql-5.6.34]# rpm -qa | grep mysql
mysql-libs-5.1.73-7.el6.x86_64

[[email protected] mysql-5.6.34]# yum remove mysql-libs-5.1.73-7.el6.x86_64 -y

重点说明:如果rpm -qa没有检测出“mysql-libs-5.1.73-7.el6.x86_64”这个包?就不用执行yum remove这条命令啦!

[[email protected] mysql-5.6.34]# useradd -M -u 27 -s /sbin/nologin mysql

[[email protected] mysql-5.6.34]# groupmod -g 27 mysql

[[email protected] mysql-5.6.34]# chown mysql.mysql -R /usr/local/mysql/

[[email protected] mysql-5.6.34]# echo '#Mysql-5.6.34' >> /etc/profile

[[email protected] mysql-5.6.34]# echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile

[[email protected] mysql-5.6.34]# source /etc/profile

[[email protected] mysql-5.6.34]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

[[email protected] mysql-5.6.34]# chmod +x /etc/init.d/mysqld

[[email protected] mysql-5.6.34]# chkconfig --add mysqld

[[email protected] mysql-5.6.34]# chkconfig --list mysqld
mysqld             0:关闭    1:关闭    2:启用    3:启用    4:启用    5:启用    6:关闭

[[email protected] mysql-5.6.34]# chown mysql.mysql -R /usr/local/mysql/data/

[[email protected] mysql]# cd /usr/local/mysql/

[[email protected] mysql]# pwd
/usr/local/mysql

[[email protected] mysql-5.6.34]# ./scripts/mysql_install_db --user=mysql

[[email protected] mysql]# service mysqld start
Starting MySQL. SUCCESS!
 
[[email protected] mysql]# /usr/local/mysql/bin/mysqladmin -u root password "123456"
Warning: Using a password on the command line interface can be insecure.

[[email protected] mysql]# /usr/local/mysql/bin/mysql -u root -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.6.34 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> exit
Bye

[[email protected] mysql]# netstat -tnalp | grep :80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      6338/nginx          

[[email protected] mysql]# netstat -tnalp | grep :3306
tcp        0      0 :::3306                     :::*                        LISTEN      29405/mysqld

 

开始安装PHP --->

[[email protected] mysql]# yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-turbo-devel libiconv-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel -y

[[email protected] PHP]# tar xvzf libiconv-1.14.tar.gz

[[email protected] libiconv-1.14]# ./configure --prefix=/usr/local/libiconv && make && make install

[[email protected] libiconv-1.14]# wget -O /etc/yum.repos.d/epel.repo

重点解释:安装epel-6.repo扩展Yum源,如果不执行这条命令?下面所有Yum安装都会失败!

[[email protected] libiconv-1.14]# yum install libmcrypt-devel  mhash mcrypt -y

[[email protected] PHP]# tar xvzf php-5.6.30.tar.gz

[[email protected] PHP]# cd php-5.6.30

[[email protected] php-5.6.30]# pwd
/usr/local/src/PHP/php-5.6.30

[[email protected] php-5.6.30]# ./configure
> --prefix=/usr/local/php-5.6.30
> --with-mysql=/usr/local/mysql/
> --with-iconv-dir=/usr/local/libiconv
> --with-freetype-dir
> --with-jpeg-dir
> --with-zlib
> --with-png-dir
> --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
> --enable-opcache=no
> --with-fpm-user=nginx
> --with-fpm-group=nginx
> --enable-ftp

[[email protected] php-5.6.30]# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/

[[email protected] php-5.6.30]# touch ext/phar/phar.phar

[[email protected] php-5.6.30]# make && make install

[[email protected] php-5.6.30]# ln -s /usr/local/php-5.6.30/ /usr/local/php

[[email protected] php-5.6.30]# cp php.ini-production /usr/local/php-5.6.30/lib/php.ini

[[email protected] php-5.6.30]# cd /usr/local/php/etc/

[[email protected] etc]# pwd
/usr/local/php/etc

[[email protected] etc]# cp php-fpm.conf.default php-fpm.conf

[[email protected] etc]# /usr/local/php/sbin/php-fpm

[[email protected] etc]# ps aux | grep php-fpm
root      28621  0.0  0.2 223092  4548 ?        Ss   20:01   0:00 php-fpm: master process (/usr/local/php-5.6.30/etc/php-fpm.conf)
nginx     28622  0.0  0.2 223092  4264 ?        S    20:01   0:00 php-fpm: pool www          
nginx     28623  0.0  0.2 223092  4264 ?        S    20:01   0:00 php-fpm: pool www          
root      28625  0.0  0.0 103324   892 pts/0    S+   20:01   0:00 grep php-fpm

[[email protected] etc]# netstat -tanlp | grep :9000
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      28621/php-fpm

配置Nginx --->

[[email protected] etc]# vim /usr/local/nginx/conf/nginx.conf
worker_processes 1;

error_log       logs/error.log;

events {
        worker_connections 1024;
}

http {
        include         mime.types;
        default_type    application/octet-stream;

        log_format      main    '$remote_addr - $remote_user [$time_local] "$request"'
                                '$status $body_bytes_sent "http_referer"'
                                '"$http_user_agent" "$http_x_forwarded_for"';

        sendfile        on;

        keepalive_timeout 65;
        
        include extra/blog.conf;        
        }

图片 1

[[email protected] etc]# cd /usr/local/nginx/conf/

[[email protected] conf]# mkdir extra

[[email protected] conf]# pwd
/usr/local/nginx/conf

[[email protected] conf]# cd extra/

[[email protected] extra]# vim blog.conf
server {

        listen          80;
        server_name     blog.liuqi.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;

                }

}

[[email protected] extra]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx-1.10.2/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.10.2/conf/nginx.conf test is successful

[[email protected] html]# mkdir blog

[[email protected] html]# cd blog/

[[email protected] blog]# touch liuqi_info.php

[[email protected] blog]# echo "<?php phpinfo();?>" > liuqi_info.php

[ro[email protected] blog]# pwd
/usr/local/nginx/html/blog

[[email protected] blog]# /usr/local/nginx/sbin/nginx -s reload

在Windows客户端上打开Hosts文件

C:WindowsSystem32driversetchosts

192.168.31.91    blog.liuqi.org            --->  把这一行写入文件的尾处!保存退出!

在浏览器上输入:

 

 

图片 2

 

 

[[email protected] blog]# netstat -tnalp | grep :80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      6338/nginx
         
[[email protected] blog]# netstat -tnalp | grep :9000
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      28621/php-fpm       

[[email protected] blog]# netstat -tnalp | grep :3306
tcp        0      0 :::3306                     :::*                        LISTEN      29405/mysqld

 

配置Mysql数据库 --->

[[email protected] blog]# /usr/local/mysql/bin/mysql -u root -p123456

mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)

mysql> show databases like 'wordpress';
+----------------------+
| Database (wordpress) |
+----------------------+
| wordpress            |
+----------------------+
1 row in set (0.00 sec)

mysql> grant all on wordpress.* to [email protected]'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on wordpress.* to [email protected]'192.168.1.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> show grants for [email protected]'localhost';
+------------------------------------------------------------------------------------------------------------------+
| Grants for [email protected]                                                                                   |
+------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'wordpress'@'localhost' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |
| GRANT ALL PRIVILEGES ON `wordpress`.* TO 'wordpress'@'localhost'                                                 |
+------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> select user,host from mysql.user;
+-----------+-------------+
| user      | host        |
+-----------+-------------+
| root      | 127.0.0.1   |
| wordpress | 192.168.1.% |
| root      | ::1         |
|           | localhost   |
| root      | localhost   |
| wordpress | localhost   |
|           | master-01   |
| root      | master-01   |
+-----------+-------------+
8 rows in set (0.00 sec)

mysql> quit
Bye

[[email protected] blog]# cd /usr/local/nginx/conf/extra/

[[email protected] extra]# pwd
/usr/local/nginx/conf/extra

[[email protected] src]# cp wordpress-4.7.2-zh_CN.tar.gz /usr/local/nginx/html/blog/

[[email protected] src]# cd /usr/local/nginx/html/blog/

[[email protected] blog]# tar xvzf wordpress-4.7.2-zh_CN.tar.gz

 

配置Nginx --->

[[email protected] wordpress]# vim /usr/local/nginx/conf/extra/blog.conf
server {

        listen          80;
        server_name     blog.liuqi.org;
        location / {

                root    html/blog;
                index   index.php index.html index.htm;
                   }

        location ~ .*.(php|php5)?$ {

                root    html/blog;

                fastcgi_pass    127.0.0.1:9000;
                fastcgi_index   index.php;
                include         fastcgi.conf;

                }

}

[[email protected] wordpress]# /usr/local/nginx/sbin/nginx -s reload

[[email protected] blog]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!

[[email protected] blog]# rm -rf liuqi_info.php

[[email protected] blog]# mv wordpress/* .

重点解释:这步很关键!如果不执行“mv wordpress/* .”?Blog博客平台会安装失败!

[[email protected] blog]# /bin/mv wordpress-4.7.2-zh_CN.tar.gz /usr/local/src/

[[email protected] blog]# chown -R nginx.nginx /usr/local/nginx/html/blog/

[[email protected] blog]# /usr/local/nginx/sbin/nginx -s reload

在浏览器上输入:

 

图片 3

 

图片 4

 

图片 5

 

图片 6

 

图片 7

部署环境:VM虚拟机 操作系统:CentOS-6.8-x64 IP地址:192.168.31.91 Mysql数据库版本:5.6.34 Cmake软件包...

   sed -n '10,17p' nginx.conf >extra/www.conf

安装mhash加密扩展库

Mhash是基于离散数学原理的不可逆向的php加密方式扩展库,其在默认情况下不开启。mhash可以用于创建校验数值、消息摘要、消息认证码,以及无需原文的关键信息保持(如密码)等。

  1. [root@lnmp ~]# yum install mhash mhash-devel -y

  2. [root@lnmp ~]# rpm -qa mhash mhash-devel

  3. mhash-devel-0.9.9.9-3.el6.x86_64

  1. mhash-0.9.9.9-3.el6.x86_64

      3) PHP软件程序创建软链接

        ln -s /application/php-5.5.32/ /application/php

 

设置mysql启动脚本

安装yum无法安装的libiconv库

  1. [root@lnmp tools]# wget
  1. [root@lnmp tools]# tar zxf libiconv-1.14.tar.gz

  2. [root@lnmp tools]# cd libiconv-1.14

  1. [root@lnmp libiconv-1.14]# ./configure --prefix=/usr/local/libiconv

  2. [root@lnmp libiconv-1.14]# make && make install

03:wordpress博客站点部署配置

[root@localhost ~]# source /etc/profile  

配置PHP与MySQL

  1. [root@lnmp blog]# pwd

  2. /application/nginx/html/blog

  3. [root@lnmp blog]# cat test_mysql.php

  4. <?php

  5. //$link_id=mysql_connect('主机名','用户','密码');

  1.   $link_id=mysql_connect('localhost','root','system');
  1. //$link_id=mysql_connect('localhost','test','');
  1.   if($link_id){

  2.     echo "mysql successful by oldboy!";

  3.   }else{

  4.     echo mysql_error();

  5.   }

  6. //php单行注释

  7. /*php多行注释*、

  1. ?>

图片 8

  1. [root@lnmp blog]# rm -f phpinfo.php test_mysql.php

nginx编译安装步骤

初始时这两个配置文件是一致的

安装libicov

同上。

mysql软件

    mysql软件下载地址信息: www.mysql.com   mirrors.sohu.com

    mysql软件下载完毕后,查看mysql解压后目录文件大小

    讲解安装mysql步骤

mysql> select user,host from mysql.user* ;*

配置PHP引擎配置文件php.ini

  1. [root@lnmp php-5.3.28]# cp php.ini-production /application/php/lib/php.ini

    3) 设置mysql数据库登录用户名与密码

        ####12.给MySQL root用户设置密码

        /application/mysql/bin/mysqladmin -u root password 'oldboy123'

        mysql  -u   root -p  oldboy123

       

                   初级 添加删除系列

        #创建数据库

        create database wordpress;

        #删除数据库

        drop database wordpress;

        #############################################################################################################

 

tar fx /home/software/tools/wordpress-4.9.4.tar.gz -C /application/nginx/html/www/

配置PHP服务(FastCGI模式)配置文件php-fpm.conf

  1. [root@lnmp php-5.3.28]# cd /application/php/etc/

  2. [root@lnmp etc]# ls

  3. pear.conf php-fpm.conf.default

  4. [root@lnmp etc]# cp php-fpm.conf.default php-fpm.conf

  1. [root@lnmp etc]# ls

  2. pear.conf php-fpm.conf php-fpm.conf.default

指定pid路径:pid = /app/logs/php-fpm.pid

进程管理的错误日志路径:error_log = /app/logs/php-fpm.log

错误日志级别:log_level = error

主进程文件描述符:rlimit_files = 32768

模型:events.mechanism = epoll

用户和组:

listen.owner = nginx

listen.group = nginx

最大进程数:pm.max_children = 1024

开始启动进程数:pm.start_servers = 16

最小空闲进程数:pm.min_spare_servers = 5

最大空闲进程数:pm.max_spare_servers = 20

超时时间:pm.process_idle_timeout = 15s;

每个进程最大请求:pm.max_requests = 2048

慢查询:slowlog = /app/logs/$pool.log.slow

超时时间:request_slowlog_timeout = 10

邮箱地址:php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f xxxxxxx@xxx.com

    2) 编辑nginx与php连通性测试文件,并进行测试

        echo '<?php phpinfo(); ?>'        >/application/nginx/html/blog/test_info.php   #创建测试文件

      

 

 测试站点

        curl              <-- 静态请求站点文件信息测试    

        curl           <-- 动态请求站点文件信息测试

        说明:当php服务停止时,9000端口信息消失,即停止PHP错误报502错误

                   linux系统测试完毕后,建议利用浏览器进行最终测试,测试效果更明显些

 

 

启动PHP服务

安装mcrypt加密扩展库

PHP程序员在编写代码程序时,除了要保证代码的高性能之外,还有一点是非常重要的,那就是程序的安全性保障。PHP除了自带的几种加密函数外,还有功能更全面的PHP加密扩展库mcrypt和mhash。

  1. [root@lnmp ~]# yum install mcrypt -y
  1. [root@lnmp ~]# rpm -qa mcrypt
  1. mcrypt-2.6.8-10.el6.x86_64

    ②. 安装nginx的依赖包(pcre-devel openssl-devel)---假设不进行安装

        yum install -y pcre-devel openssl-devel  

 

安装PHP依赖包

  1. [root@lnmp ~]# yum -y install libxml2-devel gd-devel libcurl-devel libxslt-devel libmcrypt-devel mhash mcrypt

      ④. 编译安装软件步骤

        a. 解压要编译安装的软件(解压软件---配置(./configure)---做菜(编译 make)---上菜(安装 make install))

           tar xf nginx-1.10.2.tar.gz

ps -ef |grep sshd

id www   #查看用户

uid=666(www) gid=666(www) groups=666(www)

userdel -r www  #删除虚拟用户

useradd www -s /sbin.nologin -M  #创建虚拟用户

id www

 

           cd nginx-1.10.2

           ls (里面的内容就是源代码(config readme安装说明)---默认编译会安装到/usr/local目录)

           useradd -s /sbin/nologin -M www                                                                                    <--- 创建web服务程序www用户

           ./configure --prefix=/application/nginx-1.10.2 --user=www --group=www --with-http_stub_status_module  --with-http_ssl_module      #配置文件

echo $?

                 (编译参数说明后续补充说明)

           make   编译

echo $?

           make install    编译安装

                 软件编译过程中,利用返回值,判断操作是否正确

           echo $?

            cd /application/

           ln -s /application/nginx-1.10.2  /application/nginx                                  <--- 安装完成一个软件要做一个软链接

        b. 启动nginx软件程序进行测试

           /application/nginx/sbin/nginx

           lsof -i:80

netstat -lntup|grep 80    查看80端口

           浏览器访问 10.0.0.8:80

           至此软件安装完毕:

配置nginx支持PHP程序访问

安装PHP

04:

    ③. nginx软件使用过程中疑难杂症(参考教案说明)

        · Nginx启动的疑难杂症汇总

 

    ④. nginx软件排查问题三部曲说明

         a 在客户端上ping服务器端IP,检查链路是否通畅

              b 在客户端上telnet服务器端IP、端口,检查链路访问是否通畅

              c 在客户端上wget检测模拟页面访问是否正常

 

## nginx命令说明

# nginx 启动方法

[[email protected] application]# /application/nginx/sbin/nginx

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] still could not bind()

[[email protected] application]#

 

# nginx 停止方法

[[email protected] application]# /application/nginx/sbin/nginx -s stop

[[email protected] application]# ps -ef|grep nginx

root       4283   1773  0 21:52 pts/0    00:00:00 grep --color=auto nginx

[[email protected] application]# netstat -lntup|grep 80

[[email protected] application]# /application/nginx/sbin/nginx

[[email protected] application]#

 

# nginx 重启方法(平滑)

[[email protected] application]# /application/nginx/sbin/nginx -s reload

 

# nginx 配置文件语法检查

[[email protected] application]# /application/nginx/sbin/nginx -t

nginx: the configuration file /application/nginx-1.10.3/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.10.3/conf/nginx.conf test is successful

 

清理无用的mysql用户及库

安装epel源

  1. [root@lnmp ~]# wget -O /etc/yum.repos.d/epel.repo

      1) 下载解压mysql二进制软件包

             tar xf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz

        #解压数据库压缩包

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 7074/mysqld

什么是FastCGI

FastCGI是一个可伸缩地、高速地在HTTP服务器和动态脚本语言间通信的接口(FastCGI接口在Linux下是socket(可以是文件socket,也可以是ip socket)),主要优点是把动态语言和HTTP服务器分离开来。多数流行的HTTP服务器都支持FastCGI,包括Apache、Nginx和lightpd。

同时,FastCGI也被许多脚本语言所支持,比较流行的脚本语言之一为PHP。FastCGI接口方式采用C/S架构,可以将HTTP服务器和脚本解析服务器分开,同时在脚本解析服务器上启动一个或多个脚本解析守护进程。当HTTP服务器每次遇到动态程序时,可以将其直接交付给FastCGI进程执行,然后将得到的结构返回给浏览器。这种方式可以让HTTP服务器专一地处理静态请求或者将动态脚本服务器的结果返回给客户端,这在很大程度上提高了整个应用系统的性能。

FastCGI的重要特点:

1、FastCGI是HTTP服务器和动态脚本语言间通信的接口或者工具。

2、FastCGI优点是把动态语言解析和HTTP服务器分离开来。

3、Nginx、Apache、Lighttpd以及多数动态语言都支持FastCGI。

4、FastCGI接口方式采用C/S架构,分为客户端(HTTP服务器)和服务端(动态语言解析服务器)。

5、PHP动态语言服务端可以启动多个FastCGI的守护进程。

6、HTTP服务器通过FastCGI客户端和动态语言FastCGI服务端通信。

    01:先将原有目录中数据移出

        cd /application/nginx/html/blog/wp-content/uploads

        mkdir /tmp/wordpress_backup -p

        mv ./* /tmp/wordpress_backup/

   

 图片 9

什么是CGI

CGI全称"通用网关接口"(Common Gateway Interface),用于HTTP服务器与其它机器上的程序服务通信交流的一种工具,CGI程序须运行在网络服务器上。

传统CGI接口方式的主要缺点是性能较差,因为每次HTTP服务器遇到动态程序时都需要重启解析器来执行解析,然后结果被返回给HTTP服务器。这在处理高并发访问几乎是不可用的,因此就诞生了FastCGI。另外传统的CGI接口方式安全性也很差。

原创:LNMP架构部署个人博客网站 禁止转载复制,lnmp禁止转载

[root@localhost libiconv-1.14]# ./configure --prefix=/usr/local/libiconv

lnmp服务器

  1. [root@lnmp tools]# tar xf php-5.3.28.tar.gz

  2. [root@lnmp tools]# ls -ld php-5.3.28

  1. drwxr-xr-x 13 nginx games 4096 Dec 11 2013 php-5.3.28

  2. [root@lnmp tools]# cd php-5.3.28

编译安装

  1. ###################输入以下内容
  1. ./configure

  2. --prefix=/application/php5.3.28

  1. --with-mysql=/application/mysql #使用php自带mysql参数:--with-mysql=mysqlnd

  2. --with-iconv-dir=/usr/local/libiconv

  1. --with-freetype-dir

  2. --with-jpeg-dir

  3. --with-png-dir

  4. --with-zlib

  5. --with-libxml-dir=/usr

  6. --enable-xml

  7. --disable-rpath

  8. --enable-safe-mode

  9. --enable-bcmath

  10. --enable-shmop

  11. --enable-sysvsem

  12. --enable-inline-optimization

  13. --with-curl

  14. --with-curlwrappers

  15. --enable-mbregex

  16. --enable-fpm

  17. --enable-mbstring

  18. --with-mcrypt

  19. --with-gd

  20. --enable-gd-native-ttf

  21. --with-openssl

  22. --with-mhash

  23. --enable-pcntl

  24. --enable-sockets

  25. --with-xmlrpc

  26. --enable-zip

  27. --enable-soap

  28. --enable-short-tags

  29. --enable-zend-multibyte

  30. --enable-static

  31. --with-xsl

  32. --with-fpm-user=nginx

  33. --with-fpm-group=nginx

  34. --enable-ftp

  35. ####################编译结果

  1. creating main/internal_functions.c
  1. creating main/internal_functions_cli.c

  2. +--------------------------------------------------------------------+

  1. | License: |

  2. | This software is subject to the PHP License, available in this |

  3. | distribution in the file LICENSE. By continuing this installation |

  4. | process, you are bound by the terms of this license agreement. |

  1. | If you do not agree with the terms of this license, you must abort |

  2. | the installation process at this point. |

  3. +--------------------------------------------------------------------+

  1.  

  2. Thank you for using PHP.

  3.  

  4. [root@lnmp php-5.3.28]# echo $?

  1. 0

 

  1. [root@lnmp php-5.3.28]# make

  2. /usr/bin/ld: cannot find -lltdl

  3. collect2: ld returned 1 exit status

  1. make: *** [sapi/fpm/php-fpm] Error 1

  2. [root@lnmp php-5.3.28]# echo $?

  1. 2

cannot find –lltdl解决办法,需要安装libltdl。

  1. [root@lnmp tools]# cd libmcrypt-2.5.8/libltdl/

  2. [root@lnmp libltdl]# ./configure -enable-ltdl-install

  3. [root@lnmp libltdl]# make && make install

重新回到PHP的安装目录下进行查询编译PHP。

  1. [root@lnmp php-5.3.28]# make

  2. clicommand.inc

  3. pharcommand.inc

  4. directorytreeiterator.inc

  5. invertedregexiterator.inc

  6. phar.inc

  7.  

  8. Build complete.

  9. Don't forget to run 'make test'.

  1.  

  2. [root@lnmp php-5.3.28]# echo $?

  1. 0

  2. [root@lnmp php-5.3.28]# make install

创建软连接

  1. /home/oldboy/tools/php-5.3.28/build/shtool install -c ext/phar/phar.phar /application/php5.3.28/bin

  2. ln -s -f /application/php5.3.28/bin/phar.phar /application/php5.3.28/bin/phar

  1. Installing PDO headers: /application/php5.3.28/include/php/ext/pdo/

  2. [root@lnmp php-5.3.28]# echo $?

  1. 0

  2. [root@lnmp php-5.3.28]# ln -s /application/php5.3.28/ /application/php

    ①. 检查软件安装的系统环境

         cat /etc/redhat-release

              uname -r

                                 

cd /home/software/tools/

mysql服务器

  1. [root@mysql tools]# tar xf php-5.5.38.tar.gz

  2. [root@mysql tools]# ls -ld php-5.5.38

  3. drwxr-xr-x 14 1000 1000 4096 Jul 20 2016 php-5.5.38

  4. [root@mysql tools]# cd php-5.5.38

编译安装

  1. #############输入以下内容
  1. ./configure

  2. --prefix=/application/php5.5.38

  1. --with-mysql=mysqlnd

  2. --with-iconv-dir=/usr/local/libiconv

  1. --with-freetype-dir

  2. --with-jpeg-dir

  3. --with-png-dir

  4. --with-zlib

  5. --with-libxml-dir=/usr

  6. --enable-xml

  7. --disable-rpath

  8. --enable-bcmath

  9. --enable-shmop

  10. --enable-sysvsem

  11. --enable-inline-optimization

  12. --with-curl

  13. --enable-mbregex

  14. --enable-fpm

  15. --enable-mbstring

  16. --with-mcrypt

  17. --with-gd

  18. --enable-gd-native-ttf

  19. --with-openssl

  20. --with-mhash

  21. --enable-pcntl

  22. --enable-sockets

  23. --with-xmlrpc

  24. --enable-soap

  25. --enable-short-tags

  26. --enable-static

  27. --with-xsl

  28. --with-fpm-user=nginx

  29. --with-fpm-group=nginx

  30. --enable-ftp

  31. ############编译结果

  1.  

  2. Thank you for using PHP.

  3.  

  4. config.status: creating php5.spec

  1. config.status: executing default commands

  2. [root@mysql php-5.5.38]# echo $?

  1. 0

 

  1. [root@mysql php-5.5.38]# make
  1. invertedregexiterator.inc

  2. clicommand.inc

  3. directorytreeiterator.inc

  4. directorygraphiterator.inc

  5. pharcommand.inc

  6. phar.inc

  7.  

  8. Build complete.

  9. Don't forget to run 'make test'.

  1.  

  2. [root@mysql php-5.5.38]# echo $?

  1. 0

  2. [root@mysql php-5.5.38]# make install

  3. ln -s -f phar.phar /application/php5.5.38/bin/phar

  4. Installing PDO headers: /application/php5.5.38/include/php/ext/pdo/

  5. [root@mysql php-5.5.38]# echo $?

  1. 0

创建软连接

  1. [root@mysql php-5.5.38]# ln -s /application/php5.5.38/ /application/php

  2. [root@mysql php-5.5.38]# ls -ld /application/php

  3. lrwxrwxrwx 1 root root 23 Feb 26 16:08 /application/php -> /application/php5.5.38/

      5) 启动php-fpm程序

             /application/php/sbin/php-fpm

}
}

配置PHP与Nginx

  1. [root@lnmp ~]# cd /application/nginx/conf/extra/

  2. [root@lnmp extra]# cat blog.conf

  1. server {

  2.   listen 80;

  3.   server_name blog.etiantian.org;

  1.   root html/blog;

  2.   location / {

  3.     index index.html index.htm;

  4.   }

  5.  

  6.   location ~ .*.(php|php5)?$ {

  1.     fastcgi_pass 127.0.0.1:9000;
  1.     fastcgi_index index.php;

  2.     include fastcgi.conf;

  3.   }

  4. }

  5. [root@lnmp extra]# ../../sbin/nginx -t

  6. nginx: the configuration file /application/nginx-1.6.1/conf/nginx.conf syntax is ok

  7. nginx: configuration file /application/nginx-1.6.1/conf/nginx.conf test is successful

  8. [root@lnmp extra]# ../../sbin/nginx -s reload

  9. [root@lnmp extra]# cd /application/nginx/html/blog/

  10. [root@lnmp blog]# cat phpinfo.php

  1. <?php

  2. phpinfo();

  3. ?>

浏览器访问

图片 10

                  

                  

        下面是解释

 

To start mysqld at boot time you have to copy

        support-files/mysql.server to the right place for your system

        mysql启动脚本 默认放在support-files/mysql.server 

       

        记得给MySQL设置个密码

        PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

        To do so, start the server, then issue the following commands:

        创建密码的代码

 /application/mysql/bin/mysqladmin -u root          password 'new-password'

          远程创建密码

/application/mysql/bin/mysqladmin -u root -h web01 password 'new-password'

                   ==================================================================================================                  

chown -R mysql.mysql /application/mysql

Nginx FastCGI的运行原理

Nginx不支持对外部动态程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用。FastCGI接口在Linux下是socket(可以是文件socket,也可以是ip socket)。为了调用CGI程序,还需要一个FastCGI的wrapper,这个wrapper绑定在某个固定socket上,如端口或者文件socket。当Nginx将CGI请求发送给这个socket的时候,通过FastCGI接口,wrapper接收到请求,然后派生出一个新的线程,这个线程调用解释器或者外部程序处理脚本并读取返回数据;接着,wrapper再将返回的数据通过FastCGI接口,沿着固定的socket传递给Nginx;最后,Nginx将返回的数据发送给客户端,这就是Nginx+FastCGI的整个运作过程。

图片 11

FastCGI的主要优点是把动态语言和HTTP服务器分离开来,是Nginx专一处理静态请求和向后转发动态请求,而PHP/PHP-FPM服务器专一解析PHP动态请求。

    2) 设置mysql服务开机自启动    

        ####11.加入开机自启动

        chkconfig --add mysqld

        chkconfig mysqld on

 

mkdir -p /application/mysql/data

检查安装PHP所需lib库

php程序在开发及运行时会调用一些zlib、gb 函数库,因此需要安装下面的库。

  1. [root@lnmp tools]# yum install zlib-devel libxml2-devel libjpeg-devel libiconv-devel freetype-devel libpng-devel gd-devel curl-devel libxslt-devel -y

    2) 添加mysql程序运行时的管理用户

        useradd -s /sbin/nologin  -M mysql

        #创建虚拟用户

执行上述命令后,最后正确的输出提示如下

启动PHP

  1. [root@lnmp etc]# /application/php/sbin/php-fpm

  2. [root@lnmp etc]# ps -ef|grep php-fpm

  1. root 1695 1 0 17:32 ? 00:00:00 php-fpm: master process (/application/php5.3.28/etc/php-fpm.conf)

  2. nginx 1696 1695 0 17:32 ? 00:00:00 php-fpm: pool www

  3. nginx 1697 1695 0 17:32 ? 00:00:00 php-fpm: pool www

  4. nginx 1698 1695 0 17:32 ? 00:00:00 php-fpm: pool www

  5. nginx 1699 1695 0 17:32 ? 00:00:00 php-fpm: pool www

  6. nginx 1700 1695 0 17:32 ? 00:00:00 php-fpm: pool www

  7. nginx 1701 1695 0 17:32 ? 00:00:00 php-fpm: pool www

  8. nginx 1702 1695 0 17:32 ? 00:00:00 php-fpm: pool www

  9. nginx 1703 1695 0 17:32 ? 00:00:00 php-fpm: pool www

  10. nginx 1704 1695 0 17:32 ? 00:00:00 php-fpm: pool www

  11. nginx 1705 1695 0 17:32 ? 00:00:00 php-fpm: pool www

  12. nginx 1706 1695 0 17:32 ? 00:00:00 php-fpm: pool www

  13. nginx 1707 1695 0 17:32 ? 00:00:00 php-fpm: pool www

  14. nginx 1708 1695 0 17:32 ? 00:00:00 php-fpm: pool www

  15. nginx 1709 1695 0 17:32 ? 00:00:00 php-fpm: pool www

  16. nginx 1710 1695 0 17:32 ? 00:00:00 php-fpm: pool www

  17. nginx 1711 1695 0 17:32 ? 00:00:00 php-fpm: pool www

  18. root 1713 1360 0 17:33 pts/0 00:00:00 grep php-fpm

  19. [root@lnmp etc]# ps -ef|grep php-fpm|wc -l

  20. 18

查看端口

  1. [root@lnmp etc]# netstat -lntup|grep php-fpm

  2. tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 1695/php-fpm

  3. [root@lnmp etc]# ss -lntup|grep php-fpm

  4. tcp LISTEN 0 128 127.0.0.1:9000 *:* users:(("php-fpm",1695,7),("php-fpm",1696,0),("php-fpm",1697,0),("php-fpm",1698,0),("php-fpm",1699,0),("php-fpm",1700,0),("php-fpm",1701,0),("php-fpm",1702,0),("php-fpm",1703,0),("php-fpm",1704,0),("php-fpm",1705,0),("php-fpm",1706,0),("php-fpm",1707,0),("php-fpm",1708,0),("php-fpm",1709,0),("php-fpm",1710,0),("php-fpm",1711,0))

04:wordpress博客站点数据库迁移

    迁移数据库:利用数据库备份命令

    1) 备份数据库数据库信息

        mysqldump -uroot -poldboy123 --all-databases >/tmp/bak.sql

        ll /tmp/bak.sql -h

        scp /tmp/bak.sql 172.16.1.51:/tmp/

 

    2) 恢复数据库数据库信息                  

        ##db01

        mysql -uroot -poldboy123 </tmp/bak.sql

        ###db01添加新的用户

        grant all on wordpress.* to [email protected]'172.16.1.0/255.255.255.0' identified by 'oldboy123';

        flush privileges;

        mysql -uwordpress -poldboy123 -h 172.16.1.51

 

    3) 数据库迁移完毕,修改网站连接数据库的配置文件

        mysql -uwordpress -poldboy123 -h 172.16.1.51       <-- 修改配置文件之前,先测试网站web服务器与迁移后的数据库连通性    

                   vim wp-config.php                                  <-- 修改wordpress上的数据库连接参数信息

                   /** MySQL主机 */

                   define('DB_HOST','172.16.1.51')                    <-- 修改连接的主机信息,将localhost修改为172.16.1.51

                   说明:web服务器数据库此时可以关闭了

                  

[root@localhost php-5.3.27]# ln -s /application/php5.3.27 /application/php

安装libmcrypt库

  1. [root@lnmp tools]# wget
  1. [root@lnmp libmcrypt-2.5.8]# ./configure

  2. [root@lnmp libmcrypt-2.5.8]# make && make install

    5) 让mysql用户管理 /application/mysql/

        chown -R mysql.mysql /application/mysql/data

         ## 用虚拟用户管理

 

安装libmcrypt

  1. [root@lnmp yum.repos.d]# yum install libmcrypt-devel -y

  2. [root@lnmp yum.repos.d]# rpm -qa libmcrypt-devel

  3. libmcrypt-devel-2.5.8-9.el6.x86_64

    )6检查

        lsof -i :9000                    <--- 确认php 9000端口是否正确启动

        ps -ef|grep php-fpm

                  

mysql> grant all on wordpress.* to wordpress@'localhost' identified by '123456';    创建一个专用的Wordpress blog管理用户
Query OK, 0 rows affected (0.01 sec)

部署一个BLOG程序服务

图片 12

WordPress是一套利用PHP语言和MySQL数据库开发的开源免费的Blog(博客、网站)程序,用户可以在支持PHP环境和MySQL数据库的服务器上建立Blog站点。

WordPress是一个功能非常强大的博客系统,插件众多,易于扩展功能。安装和使用都非常方便。目前WordPress已经成为主流的Blog搭建平台,很多发布平台也是根据WordPress二次开发的。

  1. [root@lnmp blog]# pwd

  2. /application/nginx/html/blog

  3. [root@lnmp blog]# wget

创建一个专用的数据库WordPress用于存放blog数据。

  1. [root@lnmp blog]# mysql -uroot -psystem

  2. mysql> create database wordpress;

  1. Query OK, 1 row affected (0.00 sec)
  1.  

  2. mysql> show databases;

  3. +--------------------+

  4. | Database |

  5. +--------------------+

  6. | information_schema |

  7. | mysql |

  8. | performance_schema |

  9. | wordpress |

  10. +--------------------+

  11. 4 rows in set (0.07 sec)

创建一个管理的数据库WordPress的用户wordpress。

  1. mysql> grant all on wordpress.* to wordpress@'localhost' identified by 'system';

  2. Query OK, 0 rows affected (0.00 sec)

  1.  

  2. mysql> flush privileges;

  3. Query OK, 0 rows affected (0.01 sec)

  1. mysql> select user,host from mysql.user where user='wordpress';

  2. +-----------+-----------+

  3. | user | host |

  4. +-----------+-----------+

  5. | wordpress | localhost |

  6. +-----------+-----------+

  7. 1 row in set (0.00 sec)

部署WordPress

  1. [root@lnmp blog]# tar xf wordpress-4.7.2-zh_CN.tar.gz

  2. [root@lnmp blog]# mv wordpress/* .

  3. [root@lnmp blog]# rm -fr wordpress

  4. [root@lnmp blog]# cd ../

  5. [root@lnmp html]# ll -ld blog/

  6. drwxr-xr-x 5 root root 4096 Feb 27 10:10 blog/

  7. [root@lnmp html]# find ./blog/ -type f|xargs chmod 644

  8. [root@lnmp html]# find ./blog/ -type d|xargs chmod 755

  9.  

权限设置

默认目录权限:dir 755 root root

默认文件权限:file 644 root root

用户目录权限:dir nginx nginx 755

用户文件权限:file nginx nginx 644

  1. [root@lnmp html]# chown -R root.root blog/

  2. [root@lnmp html]# find ./blog/ -type f|xargs chmod 644

  3. [root@lnmp html]# find ./blog/ -type d|xargs chmod 755

  4. [root@lnmp html]# mkdir blog/wp-content/uploads

  5. [root@lnmp html]# chown -R nginx.nginx blog/wp-content/uploads/

图片 13

浏览器访问

图片 14

图片 15

图片 16

根据提示创建wp-config.php,然后点击"进行安装"。

图片 17

数据库中查看安装结果

  1. [root@lnmp blog]# mysql -uroot -psystem

  2. Welcome to the MySQL monitor. Commands end with ; or g.

  3.  

  4. mysql> use wordpress

  5. Database changed

  6. mysql> show tables;

  7. Empty set (0.01 sec)

  8.  

  9. mysql> show tables;

  10. +-----------------------+

  11. | Tables_in_wordpress |

  12. +-----------------------+

  13. | ol_commentmeta |

  14. | ol_comments |

  15. | ol_links |

  16. | ol_options |

  17. | ol_postmeta |

  18. | ol_posts |

  19. | ol_term_relationships |

  20. | ol_term_taxonomy |

  21. | ol_termmeta |

  22. | ol_terms |

  23. | ol_usermeta |

  24. | ol_users |

  25. +-----------------------+

  26. 12 rows in set (0.00 sec)

  27.  

  28. mysql> select * from ol_users;

  1. +----+------------+------------------------------------+---------------+---------------+----------+---------------------+---------------------+-------------+--------------+
  1. | ID | user_login | user_pass | user_nicename | user_email | user_url | user_registered | user_activation_key | user_status | display_name |

  2. +----+------------+------------------------------------+---------------+---------------+----------+---------------------+---------------------+-------------+--------------+

  1. | 1 | root | $P$BbYLtgyYZ9xItWMJXp4rYB/ggABd9t/ | root | admin@163.com | | 2017-02-27 03:37:27 | | 0 | root |

  2. +----+------------+------------------------------------+---------------+---------------+----------+---------------------+---------------------+-------------+--------------+

  1. 1 row in set (0.00 sec)

图片 18

 

      4) 配置php解析文件/配置php-fpm配置文件

        #上边是开发用的 下面是运维用的

cd /server/tools/php-5.5.32

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

                   php.ini-production 与 php.ini-development 文件区别关系对比

                   扩展:文件比较命令 diff zdiff vimdiff windows上的文件比较

        cd /application/php/etc/

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

                  

wordpress-4.9.4

    02:NFS服务器上配置创建共享目录

        vim /etc/exports

        /data 172.16.1.0/24(rw,sync,all_squash)

        showmount -e 172.16.1.31

        mount -t nfs 172.16.1.31:/data /mnt/

       

        showmount -e 172.16.1.31

        mount -t nfs 172.16.1.31:/data/ ./uploads/

        mv /tmp/wordpress_backup/* ./

 

 

 图片 19

 

禁止转载复制,lnmp禁止转载 nginx编译安装步骤 ①. 检查软件安装的系统环境 cat /etc/redhat-release uname -r ②...

 

    7) 复制启动脚本 授权

        cp /application/mysql/support-files/mysql.server  /etc/init.d/mysqld

        chmod +x /etc/init.d/mysqld

  cd /application/nginx/conf 

    1) 修改nginx配置文件,使nginx程序与php程序建立联系

        vim extra/blog.conf

        server {

                listen       80;

                server_name  blog.etiantian.org;

                location / {

                            root   html/blog;

                            index  index.php index.html index.htm;   <-- 需要注意编辑修改默认首页文件  index 

                }

                location ~* .*.(php|php5)?$ {         #主要添加下面这行

                            root html/blog;

                            fastcgi_pass  127.0.0.1:9000;

                            fastcgi_index index.php;

                            include fastcgi.conf;

                }

        }                

                   说明:利用nginx的location区块实现动态请求与静态请求的分别处理

                  

实例

[[email protected] extra]# pwd

/application/nginx/conf/extra

[[email protected] extra]# cat blog.conf

server {

        listen       80;

        server_name  blog.etiantian.org;

        location / {

            root   html/blog;

            index   index.php index.html index.htm;

        }

        location ~* .*.(php|php5)?$ {

            root html/blog;

            fastcgi_pass  127.0.0.1:9000;

            fastcgi_index index.php;

            include fastcgi.conf;

        }

    }

 

    9)  复制默认的配置文件

        cp /application/mysql/support-files/my-default.cnf /etc/my.cnf  #复制

      

 /etc/init.d/mysqld start                #启动

        至此,mysql数据库安装与启动完成;可以检测进程和服务端口,确认mysql服务是否启动正确

        

                    

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

    3) 编辑php与mysql连通性测试文件,并进行测试

+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
+------+-----------+
4 rows in set (0.00 sec)

    8) 修改启动脚本 和 mysql命令中的路径

        sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld

        #将默认的东西改为自己的  将后面两个配置文件的全部都`修改

wget -O /etc/yum.repos.d/epel.repo

    讲解安装PHP步骤

测试LNMP环境生效的情况

    1) 进入与退出mysql数据库方法:

             /application/mysql/bin/mysql

 

 

             =============================================

                   扩展知识:登录数据库命令简化方法

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

        source /etc/profile

        which mysql

             =============================================

        退出数据库时,尽量不要用ctrl+c进行退出mysql 用ctrl+d进行退出

 

 

    6)  初始化数据库

        #1. 确认软件安装在哪里

        #2. 确认数据存放在哪里

        #3. 确认MySQL使用的用户谁?

        /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data --user=mysql

图片 20

    讲解管理mysql数据库        

mysqladmin -u root password '12345.com'

02:LNMP PHP软件安装

mysql> select user,host from mysql.user;  查看数据库里创建的wordpress用户
+-----------+-----------+
| user | host |
+-----------+-----------+
| root | 127.0.0.1 |
| root | localhost |
| wordpress | localhost |         只允许本机通过wordpress用户访问数据库
+-----------+-----------+
3 rows in set (0.01 sec)

05. 进行数据迁移到NFS共享服务器

mysql> create database wordpress;    创建一个专用的数据库,用来存放blog数据 
Query OK, 1 row affected (0.01 sec)

         ③. 下载nginx软件---1.10.2 复制链接地址(统一位置进行下载)        

        mkdir -p /home/oldboy/tools

        cd /home/oldboy/tools

        wget -q

              说明:软件很小,用心查看一下

      

对PHP连接MySQL的情况进行测试

    4) 下载部署wordpress博客程序(   英文官网: )   

                   wget

        tar xf wordpress-4.5.1-zh_CN.tar.gz

        mv wordpress/* /application/nginx/html/blog/

        chown -R www.www /application/nginx/html/blog/

                   注意:确认hosts文件进行了解析

                   浏览器页面进行wordpress部署          

                   vim wp-config.php  可以修改wordpress上的数据库连接参数信息

                  

 

 

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld       拷贝msyql启动脚本到mysql的命令路径
[root@localhost mysql]# chmod +x /etc/init.d/mysqld     使脚本可执行

           a. 创建数据库

                      mysql   -u  root -p  oldboy123;       #进入数据库

                      show databases;                      <--- 查看当前数据库信息

                      create database wordpress;             

        

实例        

mysql> mysql -uroot -poldboy123;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql -uroot -poldboy123' at line 1

mysql>    create database wordpress;

Query OK, 1 row affected (0.53 sec)

/application/php/sbin/php-fpm

      2) 下载解压PHP软件

cd /server/tools/    #进入目录

tar xf php-5.5.32.tar.gz   #解压压缩包

cd php-5.5.32         #进入目录

#下面是配置文件

./configure      

--prefix=/application/php-5.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

 

        #Generating files

        #configure: creating ./config.status

        #creating main/internal_functions.c

        #creating main/internal_functions_cli.c

        #+--------------------------------------------------------------------+

        #| License:                                                           |

        #| This software is subject to the PHP License, available in this     |

        #| distribution in the file LICENSE.  By continuing this installation |

        #| process, you are bound by the terms of this license agreement.     |

        #| If you do not agree with the terms of this license, you must abort |

        #| the installation process at this point.                            |

        #+--------------------------------------------------------------------+

        #

        #Thank you for using PHP.

make  

        make install            <- 创建目录,生成程序文件信息

                   了解FastCGI

                  

[root@localhost php-5.3.27]# ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/
[root@localhost php-5.3.27]# touch ext/phar/phar.phar
[root@localhost php-5.3.27]# make

              c. 测试php与数据库连通性

                      vim test_mysql.php

<?php

//$link_id=mysql_connect('主机名','用户','密码');

//mysql -u用户 -p密码 -h 主机

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

if($link_id){

             echo "mysql successful by oldboy !n";

            }else{

             echo mysql_error();

            }

?>

curl blog.etiantian.org/test_mysql.php       <-- 测试php与数据库的连通性

                  

 

 

将wordpress里的文件移到www的根目录下

              b. 添加用户信息            

                     grant all on wordpress.* to 'wordpress'@'localhost' indentified by 'oldboy123';

                      grant all on wordpress.* to 'wordpress'@'172.16.1.%' indentified by 'oldboy123';

                      flush privileges;

                      drop user [email protected]'172.16.1.8';    <--- 删除用户信息

                      select user,host from mysql.user;    <--- 查看用户信息

                      mysql -uwordpress -p123456           <--- 测试创建的用户连接

           show databases;                      <--- 查看当前数据库信息

 

实例

 

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| test               |

| wordpress          |

+--------------------+

5 rows in set (0.33 sec)

 

mysql> grant all on wordpress.* to 'wordpress'@'10.0.0.%' identified by 'oldboy123';

Query OK, 0 rows affected (0.47 sec)

 

mysql> select user,host from mysql.user;

+-----------+-----------+

| user      | host      |

+-----------+-----------+

| wordpress | 10.0.0.%  |

| root      | 127.0.0.1 |

| root      | ::1       |

|           | localhost |

| root      | localhost |

|           | web01     |

| root      | web01     |

+-----------+-----------+

7 rows in set (0.00 sec)

 

 

    4) 为mysql服务程序创建软链接

        ln -s /application/mysql-5.6.34/ /application/mysql

         #创建软连接

更改后的www.conf配置文件

    3) 将mysql解压后的程序包搬家到程序目录下,并进行重命名

        mkdir -p /application/

          #创建程序目录

mv /server/tools/mysql-5.6.34-*-x86_64 /application/mysql-5.6.34

          #将程序搬迁

make    最后的正确提示

mysql-5.5.32-linux2.6-x86_64    二进制文件安装包

yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y

fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;

mysql> flush privileges;   刷新权限

 

 

  mkdir /application/nginx/conf/extra

[root@localhost tools]# cd libiconv-1.14

php-5.3.27

 

建立mysql数据文件目录

配置mysql命令的全局使用路径

[root@localhost ~]# mysql -u root -p12345.com
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 6
Server version: 5.5.32 MySQL Community Server (GPL)

    egrep -v "#|^$" nginx.conf.default >nginx.conf

Build complete.
Don't forget to run 'make test'.

mv /home/software/tools/mysql-5.5.32-linux2.6-x86_64 /application/mysql-5.5.32

/application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data --user=mysql

 

yum install -y mcrypt

安装PHP所需的lib库(PHP程序在开发及运行时会调用一些诸如zlib、gd等函数)

为mysql的root用户设置密码

 

mysql> show databases like 'wordpress';
+----------------------+
| Database (wordpress) |
+----------------------+
| wordpress |
+----------------------+
1 row in set (0.01 sec)

配置PHP服务(FastCGI方式)的配置文件php-fpm.conf

 

IP:192.168.0.103

/application/nginx/sbin/nginx -s reload  平滑重启nginx

 

下载libiconv-1.14.tar.gz    到/home/software/tools/   编译安装

创建 mysql用户及用户组

 

location ~ .*.(php|php5)?$ {
root html/www;

 

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

[root@localhost mysql]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!

 

检查mysql数据库是否启动

删除之前的测试文件

=================================================================================================

启动mysql

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

[root@localhost etc]# /application/php/sbin/php-fpm 
[root@localhost etc]# ps -ef|grep php-fpm
root 1178 1 0 20:53 ? 00:00:00 php-fpm: master process (/application/php5.3.27/etc/php-fpm.conf)
nginx 1179 1178 0 20:53 ? 00:00:00 php-fpm: pool www 
nginx 1180 1178 0 20:53 ? 00:00:00 php-fpm: pool www 
root 1182 2643 0 20:53 pts/0 00:00:00 grep php-fpm
[root@localhost etc]# **lsof -i:9000      (默认9000端口提供服务) COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME php-fpm 1178 root 7u IPv4 153583 0t0 TCP localhost:cslistener (LISTEN) php-fpm 1179 nginx 0u IPv4 153583 0t0 TCP localhost:cslistener (LISTEN) php-fpm 1180 nginx 0u IPv4 153583 0t0 TCP localhost:cslistener (LISTEN)**

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

yum install zlib-devel libxm12-devel libjpeg-ddevel libjpeg-turbo-devel libiconv-devel -y

将解压后的mysql软件包移动并改名/application/mysql-5.5.32,做软连接

[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on
[root@localhost mysql]# chkconfig --list|grep mysqld
mysqld   0:off   1:off   2:on   3:on   4:on   5:on   6:off

[root@localhost extra]# cat www.conf 
server {
listen 80;
server_name www.blogs.com;
location / {
root html/www;
index index.php index.html index.htm;       补充过一个首页文件 index.php
}

 

[root@localhost tools]# cd /home/software/tools/;cd php-5.3.27/;ls

[root@localhost www]# mysql -u root -p12345.com
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 8
Server version: 5.5.32 MySQL Community Server (GPL)

配置并启动mysql数据库

设置软连接以便访问

 图片 21

授权nginx及php服务访问www站点目录

ln -s /application/mysql-5.5.32 /application/mysql

安装mhash加密扩展库

mysql> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | localhost |
+------+-----------+
2 rows in set (0.00 sec)

mysql> drop user ""@"localhost";
Query OK, 0 rows affected (0.00 sec)

进入到软件目录

创建 extra目录,分离主配置和虚拟主机配置

 

/home/software/tools/php-5.3.27/build/shtool install -c ext/phar/phar.phar /application/php5.3.27/bin

yum install -y mhash

安装mcrypt加密扩展库

 sed -i 's#/usr/local/mysql#/application/mysql#g' mysqld_safe /etc/init.d/mysqld

进入到Nginx配置文件目录

mysql> show grants for wordpress@'localhost';    查看用户对应的权限
+------------------------------------------------------------------------------------------------------------------+
| Grants for wordpress@localhost |
+------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'wordpress'@'localhost' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |
| GRANT ALL PRIVILEGES ON `wordpress`.* TO 'wordpress'@'localhost' |
+------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

 

将需要的软件包下载到/home/software/tools/下

[root@MiWiFi-R3-srv conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include extra/www.conf;
}

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

 

 卸载本机自带MySQL

useradd -s /sbin/nologin -M mysql

 

LNMP之PHP(FastCGI方式)服务的安装准备

授权mysql用户管理mysql的安装目录

mysql数据库配置

使用grep命令生成基础的Nginx主配置文件nginx.conf 然后根据生成的初始配置进行更改,使其成为所需的形式

[root@localhost www]# rm -rf index.html test_mysql.php 

使用浏览器访问   开始安装博客程序

 

[root@localhost www]# mv wordpress/* ./
[root@localhost www]# ls
index.php wordpress wp-blog-header.php wp-content wp-links-opml.php wp-mail.php wp-trackback.php
license.txt wp-activate.php wp-comments-post.php wp-cron.php wp-load.php wp-settings.php xmlrpc.php
readme.html wp-admin wp-config-sample.php wp-includes wp-login.php wp-signup.php

make install    最后的正确提示

图片 22

[root@localhost tools]# tar fx libiconv-1.14.tar.gz 

[root@localhost nginx]# cd html/www/
[root@localhost www]# echo "<?php phpinfo(); ?>" >test_info.php

nginx-1.6.3

浏览器访问,nginx配合php解析正常

设置mysql开机自启动

[root@localhost ~]# cd /application/php/etc/;ls
pear.conf   php-fpm.conf.default
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf

Wordpress博客程序的搭建准备

 编译PHP

初始化mysql数据库文件

[root@localhost libiconv-1.14]# make && make install

经检查安装yum无法安装 libiconv-devel

 图片 23

将主配置文件中关于虚拟主机配置的行写入extra/www.conf文件中

ln -s -f /application/php5.3.27/bin/phar.phar /application/php5.3.27/bin/phar
Installing PDO headers: /application/php5.3.27/include/php/ext/pdo/

 

将下载的Wordpress博客程序解压到虚拟主机的站点目录

安装 libmcrypt库(这是一个使用动态加载的模块化的 libmcrypt, libmcrypt对于在程序运行时添加/移除算法是有用的。在编译PHP的过程中, libmcrypt库不是必须要安装的包)

图片 24

chown -R nginx.nginx /application/nginx/html/www/

 

mysql> drop user "root"@"::1";
Query OK, 0 rows affected (0.00 sec)

安装mysql

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

 

拷贝PHP配置文件到PHP默认目录,并更改文件按名为php.ini

安装PHP(FastCGI方式)服务

Centos6.8虚拟机

[root@localhost ~]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile

检查PHP服务php-fpm的进程及启动端口的情况

./configure
--prefix=/application/php5.3.27
--with-mysql=/application/mysql
--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-safe-mode
--enable-bcmath
--enable-shmop
--enable-sysvsem
--enable-inline-optimization
--with-curl
--with-curlwrappers
--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-zip
--enable-soap
--enable-short-tags
--enable-zend-multibyte
--enable-static
--with-xsl
--with-fpm-user=nginx
--with-fpm-group=nginx
--enable-ftp

 

图片 25

[root@localhost php-5.3.27]# cp php.ini-production /application/php/lib/php.ini

 

LNMP环境部署(www.blogs.com)blog程序服务

[root@localhost www]# pwd
/application/nginx/html/www
[root@localhost www]# cat test_mysql.php    (注意“ ;”,否则会报语法错误)
<?php
$link_id=mysql_connect('localhost','root','12345.com') or mysql_error();
if($link_id){
echo "mysql successful by localhost !";
}else{
echo mysql_error();
}
?>

========================================================================================================

 

yum install libmcrypt-devel -y

 

 [root@localhost mysql]# netstat -lntup|grep mysql

  diff nginx.conf nginx.conf.default

编辑:操作系统 本文来源:5.6.30  依赖软件包版本, 卸载本机自带MySQL

关键词: