LNMP架构之源码安装

一、mysql源码安装

mysql5.7版本更新后,都需要boost库,mysql官网有自带boost库的源码包
这里写图片描述

1、下载,解压源码包

[root@server5 ~]# ls
mysql-boost-5.7.11.tar.gz
[root@server5 ~]# tar zxf mysql-boost-5.7.11.tar.gz 
[root@server5 ~]# ls
mysql-5.7.11  mysql-boost-5.7.11.tar.gz

2、源码安装选择

[root@server5 mysql-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 -DWITH_PARTITION_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all

-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql  ##指定目录
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data    ##指定数据库路径
-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock  ##Unix socket 存放路径
-DWITH_MYISAM_STORAGE_ENGINE=1      ##安装 myisam 存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1    ##安装 innodb 存储引擎
-DWITH_PARTITION_STORAGE_ENGINE=1   ##安装数据库分区
-DDEFAULT_CHARSET=utf8          ##使用 utf8 字符
-DDEFAULT_COLLATION=utf8_general_ci ##校验字符
-DEXTRA_CHARSETS=all            ##安装所有扩展字符集
-DWITH_BOOST=boost/boost_1_59_0/    ##指定 boost 路径

3、报错与解决方法

1、报错没有cmake,需要安装
提示没有cmake命令
2、6.5镜像自带的cmake版本过低,提示报错,需要2.8.2以上
这里写图片描述
网上查找cmake2.8.2版本,升级

[root@server5 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-5.7.11  mysql-boost-5.7.11.tar.gz
[root@server5 ~]# yum update cmake-2.8.12.2-4.el6.x86_64.rpm -y

3、gcc和gcc-c++缺少
这里写图片描述
安装gcc和gcc-c++
这里写图片描述
4、没有指定boost库
这里写图片描述

[root@server5 mysql-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 -DWITH_PARTITION_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=boost/boost_1_59_0/

5、跟以前编译生成的文件冲突并缺少ncurses-devel包
这里写图片描述
每次编译后都会生成文件,当下次编译时,会在原来编译文件的基础上继续,所以每次都需要删除文件

[root@server5 mysql-5.7.11]# rm -fr CMakeCache.txt 
[root@server5 mysql-5.7.11]# yum install -y ncurses-devel

6、缺少bison包
这里写图片描述

[root@server5 mysql-5.7.11]# rm -fr CMakeCache.txt
 [root@server5 mysql-5.7.11]# yum install -y bison

继续编译

这里写图片描述
编译成功

4、make && make install

这里写图片描述
这里写图片描述

5、mysql初始化设置

[root@server5 mysql-5.7.11]# cd /usr/local/lnmp/mysql/
[root@server5 mysql]# ls
bin  COPYING  docs  include  lib  man  mysql-test  README  share  support-files
[root@server5 mysql]# cd support-files/
[root@server5 support-files]# ls
magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@server5 support-files]# mv /etc/my.cnf /etc/my.cnf.back
[root@server5 support-files]# cp my-default.cnf /etc/my.cnf   ##复制mysql的配置文件
[root@server5 support-files]# cp mysql.server /etc/init.d/mysqld   ##复制mysql的执行脚本
[root@server5 support-files]# ll /etc/init.d/mysqld   (如果没有执行权限需要+x)
-rwxr-xr-x 1 root root 11005 Jul  1 18:01 /etc/init.d/mysqld
[root@server5 support-files]# groupadd -g 27 mysql
[root@server5 support-files]# useradd -u 27 -g 27 -d /usr/local/lnmp/mysql/data -M -s /sbin/nologin mysql
Creating mailbox file: File exists
[root@server5 support-files]# grep mysql /etc/passwdmysql:x:27:27::/usr/local/lnmp/mysql/data:/sbin/nologin
[root@server5 support-files]# pwd
/usr/local/lnmp/mysql/support-files
[root@server5 support-files]# cd ..
[root@server5 mysql]# chown mysql.mysql . -R
[root@server5 mysql]# pwd
/usr/local/lnmp/mysql
[root@server5 mysql]# cd bin/
[root@server5 bin]# vim /root/.bash_profile 
################################################################
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin

export PATH`
##########################################################
[root@server5 bin]# source /root/.bash_profile   ##运行环境变量
[root@server5 mysql]# vim /etc/my.cnf        ##编辑配置文件
#############################################
 18 basedir = /usr/local/lnmp/mysql
 19 datadir = /usr/local/lnmp/mysql/data
 20 port = 3306
 21 # server_id = .....
 22 socket = /usr/local/lnmp/mysql/data/mysql.sock
########################################################

[root@server5 mysql]# mysql_install_db  ## 老版本的初始化命令,5.6以后新命令
2018-06-29 11:01:28 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-06-29 11:01:28 [ERROR]   The data directory needs to be specified.
[root@server5 mysql]# mysqld --initialize --user=mysql
[root@server5 mysql]# chown mysql.mysql . -R 

碰到此报错,删除生成的data目录,重新来
这里写图片描述

[root@server5 mysql]# rm -fr data/
[root@server5 mysql]# mysqld --initialize --user=mysql
2018-07-01T10:48:56.964538Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-07-01T10:48:56.964624Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2018-07-01T10:48:56.964629Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2018-07-01T10:48:59.917842Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-07-01T10:49:00.667612Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-07-01T10:49:00.981175Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 5d212cdb-7d1c-11e8-8030-525400b70b5b.
2018-07-01T10:49:01.124832Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-07-01T10:49:01.126243Z 1 [Note] A temporary password is generated for root@localhost: jhm#wI&cb4HK(临时密码)
[root@server5 mysql]# chown root . -R
[root@server5 mysql]# chown mysql.mysql data/ -R
[root@server5 mysql]# ll
total 64
drwxr-xr-x  2 root  mysql  4096 Jul  1 17:58 bin
-rwxr-xr-x  1 root  mysql 17987 Feb  2  2016 COPYING
drwxr-x---  5 mysql mysql  4096 Jul  1 18:49 data
drwxr-xr-x  2 root  mysql  4096 Jul  1 17:57 docs
drwxr-xr-x  3 root  mysql  4096 Jul  1 17:57 include
drwxr-xr-x  2 root  mysql  4096 Jul  1 18:18 keyring
drwxr-xr-x  4 root  mysql  4096 Jul  1 17:58 lib
drwxr-xr-x  4 root  mysql  4096 Jul  1 17:57 man
drwxr-xr-x 10 root  mysql  4096 Jul  1 17:59 mysql-test
-rwxr-xr-x  1 root  mysql  2478 Feb  2  2016 README
drwxr-xr-x 28 root  mysql  4096 Jul  1 17:59 share
drwxr-xr-x  2 root  mysql  4096 Jul  1 17:59 support-files

6、mysql登陆

[root@server5 mysql]# /etc/init.d/mysqld start 
[root@server5 mysql]# mysql -p 
Enter password:    ##输入刚才的临时密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.11

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.

7、mysql修改密码

这里写图片描述
这里写图片描述

8、登陆测试

这里写图片描述

二、php源码安装

1、下载,解压,预编译

[root@server5 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm  mysql-boost-5.7.11.tar.gz
mysql-5.7.11                     php-5.6.35.tar.bz2
[root@server5 ~]# tar jxf php-5.6.35.tar.bz2 
[root@server5 ~]# cd php-5.6.35
[root@server5 php-5.6.35]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --enable-mysqlnd --with-mysql=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

2、下载相关依赖包

libxml2-devel openssl-devel curl-devel libjpeg-turbo-devel libpng-devel
freetype-devel gmp-devel libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
libmcrypt-2.5.8-9.el6.x86_64.rpm net-snmp-devel

3、编译

[root@server5 php-5.6.35]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --enable-mysqlnd --with-mysql=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

这里写图片描述

4、make && make install

[root@server5 php-5.6.35]# make && make install 

5、配置

[root@server5 php-5.6.35]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@server5 php-5.6.35]# cd /usr/local/lnmp/php/
[root@server5 php]# cd etc/
[root@server5 etc]# ls
pear.conf  php-fpm.conf.default  php.ini
[root@server5 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server5 etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php.ini
[root@server5 etc]# vim php-fpm.conf
###########################################################
 21 [global]
 22 ; Pid file
 23 ; Note: the default prefix is /usr/local/lnmp/php/var
 24 ; Default Value: none
 25 pid = run/php-fpm.pid
#################################################################
 [root@server5 etc]# vim php.ini
##############################################################
 933 [Date]
 934 ; Defines the default timezone used by the date functions
 935 ; http://php.net/date.timezone
 936 date.timezone =Asia/Shanghai

6、更改启动脚本

[root@server5 etc]# cd
[root@server5 ~]# cd php-5.6.35
[root@server5 php-5.6.35]# cd sapi/fpm/
[root@server5 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@server5 fpm]# chmod +x /etc/init.d/php-fpm 

7、新增nginx用户,启动服务

[root@server5 fpm]# useradd -u 800 -M -d /usr/local/lnmp/nginx nginx
[root@server5 fpm]# /etc/init.d/php-fpm start 
Starting php-fpm  done

三、nginx源码安装

1、下载,解压

[root@server5 ~]# tar zxf nginx-1.10.3.tar.gz 
[root@server5 ~]# tar zxf nginx-sticky-module-ng.tar.gz 
[root@server5 ~]# cd nginx-1.10.3

2、编译前配置

[root@server5 nginx-1.10.3]# vim src/core/nginx.h
########################################
 12 #define nginx_version      1010003
 13 #define NGINX_VERSION      "1.10.3"
 14 #define NGINX_VER          "nginx/"    ##隐藏nginx版本
[root@server5 nginx-1.10.3]# vim auto/cc/gcc 
############################################
178 # debug                           
179 #CFLAGS="$CFLAGS -g"                    ##关闭debug 
###########################################

3、编译

[root@server5 nginx-1.10.3]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module --with-threads --with-file-aio --add-module=/root/nginx-sticky-module-ng(导入nginx-sticky模块)

4、解决依赖性

这里写图片描述

5、make && make install

这里写图片描述

6、配置

[root@server5 nginx]# vim /usr/local/lnmp/nginx/conf/nginx.conf

 43         location / {
 44             root   html;
 45             index  index.php index.html index.htm;
 46         }
 65         location ~ \.php$ {
 66             root           html;
 67             fastcgi_pass   127.0.0.1:9000;
 68             fastcgi_index  index.php;
 69            # fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 70             include        fastcgi.conf;
 71         }


 ##################################################
[root@server5 nginx]# ln -s /usr/local/lnmp/nginx/sbin/nginx /sbin/
[root@server5 nginx]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server5 nginx]# vim /usr/local/lnmp/nginx/html/index.php
<?php
phpinfo()
?>
[root@server5 nginx]# nginx 
[root@server5 nginx]# /etc/init.d/php-fpm start 
Starting php-fpm  done
[root@server5 nginx]# nginx -s reload

8、测试

这里写图片描述

四、lnmp搭建论坛,测试架构

[root@server5 html]# unzip Discuz_X3.2_SC_UTF8.zip 
[root@server5 html]# pwd
/usr/local/lnmp/nginx/html
[root@server5 html]# ls
50x.html  Discuz_X3.2_SC_UTF8.zip  index.html  index.php  readme  upload  utility
[root@server5 html]# cd upload/
[root@server5 upload]# ls
admin.php  config           data         home.php    misc.php    search.php  uc_client
api        connect.php      favicon.ico  index.php   plugin.php  source      uc_server
api.php    cp.php           forum.php    install     portal.php  static      userapp.php
archiver   crossdomain.xml  group.php    member.php  robots.txt  template
[root@server5 upload]# cd ..
[root@server5 html]# mv upload/ bbs
[root@server5 html]# cd bbs/

配置完重新加载nginx
网页:
这里写图片描述
排错:
这里写图片描述
1、bbs下文件目录权限不足,修改权限
[root@server5 bbs]# chmod 777 uc_server/ config/ data/ uc_client/ -R
2、目录不存在

[root@server5 bbs]# vim /usr/local/lnmp/php/etc/php.ini
1013 pdo_mysql.default_socket=/usr/local/lnmp/mysql/data/mysql.sock
1162 mysql.default_socket =/usr/local/lnmp/mysql/data/mysql.sock
1221 mysqli.default_socket =/usr/local/lnmp/mysql/data/mysql.sock

这里写图片描述
这里写图片描述
3、数据库权限不足
这里写图片描述
[root@server5 bbs]# chmod 755 /usr/local/lnmp/mysql/data/
这里写图片描述
4、输入数据库密码,设定 admin 密码,搭建成功

5、避免重复安装,删除 /usr/local/lnmp/nginx/html/bbs/install/index.php
这里写图片描述

五、php添加memcache缓存模块

1、安装memcache

[root@server5 ~]# tar zxf memcache-2.2.5.tgz 
[root@server5 ~]# vim ~/.bash
.bash_history  .bash_logout   .bash_profile  .bashrc        
[root@server5 ~]# vim ~/.bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/usr/local/lnmp/php/bin

export PATH
[root@server5 ~]# source ~/.bash_profile 
[root@server5 ~]# cd memcache-2.2.5
[root@server5 memcache-2.2.5]# phpize 
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
[root@server5 memcache-2.2.5]# ./configure --prefix=/usr/local/lnmp/php/memcache 
[root@server5 memcache-2.2.5]# make && make install 

2、memcache配置

[root@server5 memcache-2.2.5]# vim /usr/local/lnmp/php/etc/php.ini 

这里写图片描述

[root@server5 memcache-2.2.5]# /etc/init.d/php-fpm reload
Reload service php-fpm  done
[root@server5 memcache-2.2.5]# php -m | grep memcache   ##php -m 查看加载的模块
memcache

3、将memcache测试文件拷贝到nginx的发布目录

[root@server5 memcache-2.2.5]# cp example.php /usr/local/lnmp/nginx/html/
[root@server5 memcache-2.2.5]# cp memcache.php /usr/local/lnmp/nginx/html/
[root@server5 memcache-2.2.5]# vim /usr/local/lnmp/nginx/html/example.php 

这里写图片描述

[root@server5 memcache-2.2.5]# vim /usr/local/lnmp/nginx/html/example.php 

这里写图片描述

[root@server5 memcache-2.2.5]# /etc/init.d/php-fpm reload
Reload service php-fpm  done
[root@server5 memcache-2.2.5]# nginx -s reload

4、测试

这里写图片描述
这里写图片描述
这里写图片描述
example.php的页面是直接访问了服务器,而memcache的页面是缓存,缓存页面速度要比example页面速度快一倍以上

5、memcache端口查看

[root@server5 memcache-2.2.5]# yum install -y memcached
[root@server5 memcache-2.2.5]# /etc/init.d/memcached start 
Starting memcached:                                        [  OK  ]
[root@server5 memcache-2.2.5]# netstat -antuple | grep memcache
tcp        0      0 0.0.0.0:11211               0.0.0.0:*                   LISTEN      498        251142     4355/memcached      
tcp        0      0 :::11211                    :::*                        LISTEN      498        251143     4355/memcached      
udp        0      0 0.0.0.0:11211               0.0.0.0:*                               498        251146     4355/memcached      
udp        0      0 :::11211                    :::*                                    498        251147     4355/memcached      

六、nginx虚拟主机和httpd加密

1、虚拟主机配置

1、nginx配置文件修改

[root@server5 ~]# vim /usr/local/lnmp/nginx/conf/nginx.conf

这里写图片描述

[root@server5 ~]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server5 ~]# nginx -s reload
[root@server5 ~]# mkdir /www1
[root@server5 ~]# mkdir /www2
[root@server5 ~]# vim /www1/index.html
[root@server5 ~]# vim /www2/index.html
[root@server5 ~]# cat  /www1/index.html
www.westos.org
[root@server5 ~]# cat  /www2/index.html
bbs.westos.org

2、测试
真机做域名解析后测试

[root@foundation77 ~]# curl www.westos.org
www.westos.org
[root@foundation77 ~]# curl bbs.westos.org
bbs.westos.org

2、配置https加密

这里写图片描述

[root@server5 ~]# nginx -s reload
nginx: [emerg] BIO_new_file("/usr/local/lnmp/nginx/conf/cert.pem") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/usr/local/lnmp/nginx/conf/cert.pem','r') error:2006D080:BIO routines:BIO_new_file:no such file)   ##报错原因 缺少cert.pem
[root@server5 ~]# cd /etc/pk
pkcs11/ pki/     
[root@server5 ~]# cd /etc/pki/tls/certs/
[root@server5 certs]# ls
ca-bundle.crt  ca-bundle.trust.crt  make-dummy-cert  Makefile  renew-dummy-cert
[root@server5 certs]# make cert.pem
umask 77 ; \
    PEM1=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
    PEM2=`/bin/mktemp /tmp/openssl.XXXXXX` ; \
    /usr/bin/openssl req -utf8 -newkey rsa:2048 -keyout $PEM1 -nodes -x509 -days 365 -out $PEM2 -set_serial 0 ; \
    cat $PEM1 >  cert.pem ; \
    echo ""    >> cert.pem ; \
    cat $PEM2 >> cert.pem ; \
    rm -f $PEM1 $PEM2
Generating a 2048 bit RSA private key
........................................................................+++
.........................................................+++
writing new private key to '/tmp/openssl.G4q7WP'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN 
State or Province Name (full name) []:Shaanxi
Locality Name (eg, city) [Default City]:XI'an
Organization Name (eg, company) [Default Company Ltd]:westos
Organizational Unit Name (eg, section) []:linux
Common Name (eg, your name or your server's hostname) []:redhat
Email Address []:root@localhost
[root@server5 certs]# mv cert.pem /usr/local/lnmp/nginx/conf/
[root@server5 certs]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server5 certs]# nginx -s reload 
[root@server5 certs]# netstat -antuple | grep 443
tcp        0      0 0.0.0.0:443                 0.0.0.0:*                   LISTEN      0          252637     312/nginx           

物理机测试:
访问https:www.westos.org
这里写图片描述
这里写图片描述

猜你喜欢

转载自blog.csdn.net/weixin_41789003/article/details/80875550
今日推荐