LNMP架构的搭建

LNMP 架构的搭建

基础架构图

环境:

server5: nginx  mysql   php

//需要的安装包 (蓝色为解压后的文件)

[root@test5 ~]# /etc/init.d/iptables stop        //关掉防火墙


MYSQL 源码安装

[root@test6 ~]#yum install -y gcc gcc-c++ make ncurses-devel bison
openssl-devel zlib-devel cmake           //解决依赖性
[root@test6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm mysql-boost-5.7.11.tar.gz
[root@test6 ~]# tar zxf mysql-boost-5.7.11.tar.gz
[root@test6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm mysql-5.7.11 mysql-boost-5.7.11.tar.gz
[root@test6 ~]# yum install -y cmake-2.8.12.2-4.el6.x86_64.rpm
[root@test6 ~]# cd mysql-5.7.11/
[root@test6mysql-5.7.11]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock-DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=boost/boost_1_59_0/

注意:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \    #安装目录
-DMYSQL_DATADIR=/usr/local/mysql/data \    #数据库存放目录
-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock \ #Unix socket 文件路径
-DWITH_MYISAM_STORAGE_ENGINE=1 \    #安装 myisam 存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \    #安装 innodb 存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \    #安装 archive 存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \    #安装 blackhole 存储引擎
-DWITH_PARTITION_STORAGE_ENGINE=1 \    #安装数据库分区
-DENABLED_LOCAL_INFILE=1 \    #允许从本地导入数据
-DWITH_READLINE=1 \    #快捷键功能
-DWITH_SSL=yes \    #支持 SSL
-DDEFAULT_CHARSET=utf8 \    #使用 utf8 字符
-DDEFAULT_COLLATION=utf8_general_ci \    #校验字符
-DEXTRA_CHARSETS=all \    #安装所有扩展字符集
-DMYSQL_TCP_PORT=3306 \    #MySQL 监听端口


编译时可能会出现很多依赖性:
See also "/root/mysql-5.7.11/CMakeFiles/CMakeOutput.log".


[root@test6 ~]# yum install -y gcc gcc-c++
[root@test6 ~]# rm -rf CMakeCache.txt
[root@test6 ~]# yum install -y ncurses-devel
[root@test6 ~]# yum install -y bison       

//每修改一次错误,就执行清缓存操作 rm -fr CMakeCache.txt 并再次编译
//编译三部曲 cmake / ./configure...../make/make install
[root@test6 ~]# make && make install
[root@test6 mysql-5.7.11]# cd /usr/local/lnmp/
[root@test6 lnmp]# ls
mysql
[root@test6 lnmp]#cd mysql


[root@test5 mysql]# cd support-files/
[root@test5 support-files]# pwd
/usr/local/lnmp/mysql/support-files
[root@test5 support-files]# cp my-default.cnf /etc/my.cnfcp: overwrite `/etc/my.cnf'? Y
[root@test5 support-files]# vim /etc/my.cnf

[root@test5 support-files]# file mysql.server
mysql.server: POSIX shell script text executable
[root@test5 support-files]# cp mysql.server /etc/init.d/mysqld
cp: overwrite `/etc/init.d/mysqld'? yes
[root@test5 support-files]# cd ..
[root@test5 mysql]# groupadd -g 27 mysql      //创建组
[root@test5 mysql]# useradd -u 27 -g 27 -M -d /usr/local/lnmp/mysql/data -s    /sbin/nologin mysql     //创建用户
[root@test5 mysql]# cd
[root@test5 ~]# vim .bash_profile          //将路径注明添加到环境变量

[root@test5 ~]# source .bash_profile           //刷新环境变量
[root@test5 ~]# cd -
/usr/local/lnmp/mysql
[root@test5 mysql]# ls
bin
data include lib mysql-test share
COPYING docs keyring man README
support-files
[root@test5 mysql]# vim /etc/my.cnf

[root@test5 mysql]# mysqld --initialize --user=mysql             //进行初始化

2018-10-10T05:37:45.328095Z 0 [ERROR] --initialize specified but the data
directory has files in it. Aborting.
2018-10-10T05:37:45.328132Z 0 [ERROR] Aborting
//出现这种问题,应将目录切换到 mysql 下的 data 目录,删除 data 下的所有东西并重新初始化。若没出现这种情况则步骤忽略。

[root@test5 mysql]# cd data/
[root@test5 data]# ls
auto.cnf  ibdata1   ib_logfile1   marry   mysql.sock   performance_schema test5.err 
ib_buffer_pool   ib_logfile0   ibtmp1   mysql   mysql.sock.lock   sys  test5.pid

[root@test5 data]# rm -rf *

[root@test5 mysql]# cd ..
[root@test5 mysql]# mysqld --initialize --user=mysql         //再次初始化

2018-10-10T05:41:49.135259Z 0 [Warning] Gtid table is not ready to be used.
Table 'mysql.gtid_executed' cannot be opened.
2018-10-10T05:41:49.135787Z 1 [Note] A temporary password is generated for
root@localhost: e<hjlNprw7aj           //localhost: 后面的为初始密码用于后面的密码初始化

[root@server5 mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@server5 mysql]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[root@server5 mysql]# chgrp root . -R            //更改组及用户
[root@test5 mysql]# ll

[root@server5 mysql]# chown mysql data/ -R          //初始化及登陆
[root@server5 mysql]# /etc/init.d/mysqld start

Starting MySQL. SUCCESS!

如果出现以下情况:

[root@test5 mysql]# /etc/init.d/mysqld start

Starting MySQL....
ERROR! The server quit without updating PID file (/usr/local/lnmp/mysql/data/test5.pid).
执行:

[root@test5 mysql]# chown -R mysql:mysql /var/data
[root@test5 mysql]# chown -R mysql:mysql /usr/local/lnmp/mysql/data
[root@test5 mysql]# chmod -R 755 /usr/local/lnmp/mysql/data
[root@test5 mysql]# /etc/init.d/mysqld restart          //重起服务,失败

ERROR! MySQL server PID file could not be found!
Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/lnmp/mysql/data/test5.pid).
//解决方法:用命令“ps -ef|grep mysqld”查看是否有 mysqld 进程,如果有使用“kill -9 进程号”杀掉,然后启动 mysql
[root@test5 mysql]# ps -ef|grep mysqld      //查看进程,杀掉 mysql 有关的进程

[root@test5 mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@server5 mysql]# mysql_secure_installation    //开启服务,成功

Securing the MySQL server deployment.
Enter password for user root:              //这里输入初始密码
The existing password for the user account root has expired. Please set a new
password.
New password:
Re-enter new password:          //输入你想设置的数据库密码
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No:
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) :
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.Remove test database and access to it? (Press y|Y for Yes, any other key for
No) :
... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
... skipping.
All done!

[root@server1 mysql]# mysql -p            //登陆 mysql
[root@test5 mysql]# mysql -p

Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.

mysql> exit
Bye

 
PHP 源码安装

[root@test5 ~]# ls

cmake-2.8.12.2-4.el6.x86_64.rpm
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
php-5.6.35.tar.bz2
gd-devel-2.0.35-11.el6.x86_64.rpm
mysql-5.7.11
re2c-0.13.5-1.el6.x86_64.rpm
libmcrypt-2.5.8-9.el6.x86_64.rpm
mysql-boost-5.7.11.tar.gz

[root@test5 ~]# tar jxf php-5.6.35.tar.bz2
[root@test5 ~]# ls    //下载依赖包
[root@test5 ~]# yum install -y libxml2-devel openssl-devel curl-devel  gd-devel-2.0.35-11.el6.x86_64.rpm  gmp-devellibmcrypt-2.5.8-9.el6.x86_64.rpm  libmcrypt-devel-2.5.8-9.el6.x86_64.rpm net-snmp-devel
[root@test5 ~]# rpm -ivh re2c-0.13.5-1.el6.x86_64.rpm

 

[root@test5 ~]# cd php-5.6.35
[root@test5~]./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=mysqlnd --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash                                 //编译第一步

遇到的问题及解决办法
问题 1:
checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-vpx-dir=<DIR>
configure: error: jpeglib.h not found.

解决:
yum -y install libjpeg-devel
再次编译
问题 2:
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.解决:
yum install -y libpng-devel libpng
再次编译
问题 3:
checking for png_write_image in -lpng... yes
If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.

解决:
[root@test5 php-5.6.35]# yum install -y freetype-devel


再次编译


最后编译成功
//可能遇到的其他问题:
问题 4:
No package xml2-config available.
Error: Nothing to do
解决:
[root@test5 php-5.6.35]# rpm -qa | grep libxml2
libxml2-python-2.7.6-14.el6.x86_64
libxml2-2.7.6-14.el6.x86_64
[root@test5 php-5.6.35]# yum install libxml2 libxml2-devel -y

问题 5:
configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
解决:
[root@test5 php-5.6.35]# yum install curl curl-devel -y
问题 6:
configure: error: Could not find net-snmp-config binary. Please check your
net-snmp installation.
解决:
[root@test5 php-5.6.35]# yum -y install net-snmp-devel

[root@test5 php-5.6.35]# make && make install            //编译第二步和第三步

配置部分:

[root@test5 ~]# cd /usr/local/lnmp/php/
[root@test5 php]# ls
bin etc include lib php sbin var
[root@test5 php]# cd etc/
[root@test5 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[root@test5 etc]# cp php-fpm.conf.default php-fpm.conf
cp: overwrite `php-fpm.conf'? y
[root@test5 etc]# cd /root/php-5.6.35
[root@test5 etc]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@test5 etc]# cd /usr/local/lnmp/php/etc/
[root@test5 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[root@test5 etc]# vim php.ini                        //写时间

[root@test5 etc]# vim php-fpm.conf         

   
                    //使第 25 行有效

[root@test5 etc]# useradd -M -d /usr/local/lnmp/nginx -s /sbin/nologin nginx     //创建用户
[root@test5 php-5.6.35]# cd /root/php-5.6.35/sapi/fpm/
[root@test5 fpm]# file init.d.php-fpm                 //它是个脚本
init.d.php-fpm: POSIX shell script text executable
//[root@test5 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm                    //将脚本文件传到默认脚本路径
[root@test5 fpm]# chmod +x /etc/init.d/php-fpm                   //给其可执行权限
[root@test5 fpm]# /etc/init.d/php-fpm start                     //执行文件
Starting php-fpm done


nginx 源码安装

需要的包
nginx-1.14.0.tar.gz
nginx-sticky-module-1.1.tar.gz

[root@test5 ~]# tar zxf nginx-sticky-module-1.1.tar.gz
[root@test5 ~]# tar zxf nginx-1.14.0.tar.gz
[root@test5 ~]# cd nginx-1.14.0
[root@test5 nginx-1.14.0]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE
man README src 

[root@test5 nginx-1.14.0]# vim src/core/nginx.h                       //去掉 nginx 的版本号

[root@test5 nginx-1.14.0]# vim auto/cc/gcc                   //注释掉   

[root@test5 nginx-1.14.0]# yum install pcre-devel -y
[root@test5 nginx-1.14.0]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module
--user=nginx --group=nginx --with-threads --with-file-aio                                  //同样,根据报错解决依赖性//编译成功


//编译成功

[root@test5 nginx-1.14.0]# make && make install
[root@test5 ~]# cd nginx-1.14.0
[root@test5 nginx-1.14.0]# cd /usr/local/lnmp/nginx/conf/
[root@test5 conf]# vim nginx.conf                         //加入 index.php 会默认首先访问 index.php

[root@test5 conf]# cd
[root@test5 ~]# vim .bash_profile

[root@test5 ~]# source .bash_profile //或者 ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/          //做个软连接
[root@test5 ~]# cd /usr/local/lnmp/nginx/html/
[root@test5 html]# vim index.php

[root@test5 html]# nginx -t             //检查 nginx 配置文件是否有错误
[root@test5 html]# nginx                //开启 nginx 服务


在网页进行访问 172.25.1.5:

nginx 和 mysql 结合并安装论坛

[root@test5 ~]# unzip Discuz_X3.2_SC_UTF8.zip -d /usr/local/lnmp/nginx/html
[root@test5 ~]# cd /usr/local/lnmp/nginx/html/
[root@test5 html]# ls
50x.html bbs index.html index.php readme utility
[root@test5 html]# mv upload bbs

网页进行访问 172.25.1.5/bbs:

[root@test5 bbs]# chmod 777 config/ data/ uc_server/ uc_client/ -R           //修改权限

执行下一步

数据库连接错误,执行:

[root@test5 bbs]# cd /usr/local/lnmp/php/etc/
[root@test5 etc]# vim php.ini
pdo_mysql.default_socket=/usr/local/lnmp/mysql/data/mysql.sock
mysql.default_socket =/usr/local/lnmp/mysql/data/mysql.sock
mysqli.default_socket =/usr/local/lnmp/mysql/data/mysql.sock

//分别是

[root@server5 etc]# /etc/init.d/php-fpm reload
[root@server5 etc]# cd /usr/local/lnmp/mysql/
[root@server5 mysql]# chmod 755 data/   

                    

//下一步

登陆论坛:


登陆成功

上面提示删除 index.php
故执行删除操作:

[root@server5 mysql]# cd data
[root@server5 data]# cd /usr/local/lnmp/nginx/html/bbs/install/
[root@server5 install]# ls
data images include index.php
[root@server5 install]# rm -f index.php

最后,论坛发布成。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值