LNMP架构的编译安装

安装mysql
[root@server1 ~]# tar zxf mysql-boost-5.7.17.tar.gz
[root@server1 ~]# yum install cmake-2.8.12.2-4.el6.x86_64.rpm -y //这里我们用cmake
[root@server1 ~]# ls
anaconda-ks.cfg install.log mysql-5.7.17
cmake-2.8.12.2-4.el6.x86_64.rpm install.log.syslog mysql-boost-5.7.17.tar.gz
[root@server1 ~]# cd mysql-5.7.17/
[root@server1 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data
-DMYSQL_UNIX_ADDR=/usr/local/mysql/lnmp/data/mysql.sock
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MYISAM_STORAGE_ENGINE=1
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DEXTRA_CHARSETS=all
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 监听端口

依赖性安装
在这里插入图片描述
//安装gcc,gcc-c++
[root@server1 mysql-5.7.17]# yum install gcc gcc-c++ -y
[root@server1 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/mysql/lnmp/data/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MYISAM_STORAGE_ENGINE=1
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DEXTRA_CHARSETS=all

//CMake Error at cmake/boost.cmake:81 (MESSAGE):
You can download it with// ##-DDOWNLOAD_BOOST=1 -DWITH_BOOST=##//

This CMake script will look for boost in . If it is not there,
it will download and unpack it (in that directory) for you.

If you are inside a firewall, you may need to use an http proxy:

export http_proxy=http://example.com:80

Call Stack (most recent call first):
cmake/boost.cmake:238 (COULD_NOT_FIND_BOOST)
CMakeLists.txt:455 (INCLUDE)

– Configuring incomplete, errors occurred!
See also “/root/mysql-5.7.17/CMakeFiles/CMakeOutput.log”.
See also “/root/mysql-5.7.17/CMakeFiles/CMakeError.log”.

[root@server1 mysql-5.7.17]# cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql
-DMYSQL_UNIX_ADDR=/usr/local/mysql/lnmp/data/mysql.sock
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_MYISAM_STORAGE_ENGINE=1
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DEXTRA_CHARSETS=all
//-DWITH_BOOST=boost/boost_1_59_0 //修改指定目录

CMake Error at cmake/readline.cmake:64 (MESSAGE):
Curses library not found. Please install appropriate package,

  remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.

Call Stack (most recent call first):
cmake/readline.cmake:107 (FIND_CURSES)
cmake/readline.cmake:197 (MYSQL_USE_BUNDLED_EDITLINE)
CMakeLists.txt:483 (MYSQL_CHECK_EDITLINE)

– Configuring incomplete, errors occurred!
[root@server1 mysql-5.7.17]# rm -fr CMakeCache.txt //清楚缓存
[root@server1 mysql-5.7.17]# yum install ncurses-devel -y //安装依赖性
[root@server1 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/mysql/lnmp/data/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci-DEXTRA_CHARSETS=all -DWITH_BOOST=boost/boost_1_59_0/

下面的依赖性就一一举例了,大家可以根据错误提示进行安装

[root@server1 mysql-5.7.17]# yum install bison -y
[root@server1 mysql-5.7.17]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/mysql/lnmp/data/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci-DEXTRA_CHARSETS=all -DWITH_BOOST=boost/boost_1_59_0/
[root@server1 mysql-5.7.17]# make && make install
在这里插入图片描述
初始化配置
root@server mysql-5.7.17]# cd /usr/local/lnmp/mysql
[root@server mysql]# ls
bin COPYING docs include lib man mysql-test README share support-files
[root@server mysql]# rpm -qa | grep mysql
mysql-libs-5.1.71-1.el6.x86_64
[root@server mysql]# cat /etc/my.cnf //系统默认配置文件
在这里插入图片描述
root@server support-files]# ls
magic my-default.cnf mysqld_multi.server mysql-log-rotate mysql.server
[root@server support-files]# cp my-default.cnf /etc/my.cnf
//拷贝安装软件的配置文件到系统默认配置文件地方
cp: overwrite `/etc/my.cnf’? y
[root@server support-files]# vim /etc/my.cnf
在这里插入图片描述
[root@server support-files]# file mysql.server //服务开启脚本文件
mysql.server: POSIX shell script text executable
[root@server support-files]# cp mysql.server /etc/init.d/mysqld
[root@server support-files]# cd …
[root@server mysql]# pwd
/usr/local/lnmp/mysql
[root@server mysql]# ll //查看数据库权限,为root,修改为mysql用户
total 56
drwxr-xr-x 2 root root 4096 Aug 5 02:34 bin
-rw-r–r-- 1 root root 17987 Nov 28 2016 COPYING
drwxr-xr-x 2 root root 4096 Aug 5 02:33 docs
drwxr-xr-x 3 root root 4096 Aug 5 02:33 include
drwxr-xr-x 4 root root 4096 Aug 5 02:34 lib
drwxr-xr-x 4 root root 4096 Aug 5 02:33 man
drwxr-xr-x 10 root root 4096 Aug 5 02:34 mysql-test
-rw-r–r-- 1 root root 2478 Nov 28 2016 README
drwxr-xr-x 28 root root 4096 Aug 5 02:34 share
drwxr-xr-x 2 root root 4096 Aug 5 02:34 support-files
[root@server mysql]# id mysql
id: mysql: No such user
[root@server mysql]# groupadd -g 27 mysql //添加mysql用户
[root@server mysql]# useradd -u 27 -g 27 -M -d /usr/local/lnmp/mysql/data -s /sbin/nologin mysql
[root@server mysql]# chown mysql data -R
[root@server1 mysql]# ll
total 60
drwxr-xr-x 2 root root 4096 Aug 5 10:05 bin
-rw-r–r-- 1 root root 17987 Nov 28 2016 COPYING
drwxr-x— 5 mysql root 4096 Aug 5 10:52 data //将数据部分修改为mysql
drwxr-xr-x 2 root root 4096 Aug 5 10:05 docs
drwxr-xr-x 3 root root 4096 Aug 5 10:05 include
drwxr-xr-x 4 root root 4096 Aug 5 10:05 lib
drwxr-xr-x 4 root root 4096 Aug 5 10:05 man
drwxr-xr-x 10 root root 4096 Aug 5 10:05 mysql-test
-rw-r–r-- 1 root root 2478 Nov 28 2016 README
drwxr-xr-x 28 root root 4096 Aug 5 10:05 share
drwxr-xr-x 2 root root 4096 Aug 5 10:36 support-files
root@server1 mysql]# cd data/
[root@server1 data]# ls
auto.cnf ib_buffer_pool ibdata1 ib_logfile0 ib_logfile1 mysql performance_schema server1.err sys
[root@server1 data]# ll
total 110644
-rw-r----- 1 mysql root 56 Aug 5 10:40 auto.cnf
-rw-r----- 1 mysql mysql 290 Aug 5 10:52 ib_buffer_pool
-rw-r----- 1 mysql root 12582912 Aug 5 10:52 ibdata1
-rw-r----- 1 mysql root 50331648 Aug 5 10:52 ib_logfile0
-rw-r----- 1 mysql root 50331648 Aug 5 10:40 ib_logfile1
drwxr-x— 2 mysql root 4096 Aug 5 10:40 mysql
drwxr-x— 2 mysql root 4096 Aug 5 10:40 performance_schema
-rw-r----- 1 mysql root 24451 Aug 5 10:52 server1.err
drwxr-x— 2 mysql root 12288 Aug 5 10:40 sys

[root@server1 mysql]# chkconfig --add mysqld //添加服务
[root@server1 mysql]# chkconfig mysqld on //开机自启

配置环境变量
[root@server1 ~]# vim ~/.bash_profile
在这里插入图片描述
[root@server1 ~]# source ~/.bash_profile //刷新策略
[root@server1 support-files]# /etc/init.d/mysqld start
Starting MySQL… SUCCESS!
数据库初始化
[root@server mysql]# mysqld --initialize --user=mysql 初始化
2018-08-04T19:16:21.762888Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-08-04T19:16:21.762965Z 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-08-04T19:16:21.762970Z 0 [Warning] ‘NO_AUTO_CREATE_USER’ sql mode was not set.
2018-08-04T19:16:24.123398Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-08-04T19:16:24.590953Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-08-04T19:16:24.747103Z 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: e112b312-981a-11e8-ba28-525400fc7a18.
2018-08-04T19:16:24.817791Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2018-08-04T19:16:24.819486Z 1 [Note] A temporary password is generated for root@localhost: TRLkC3jld>fJ //(初始密码)

//(安全证书设置)
[root@server mysql]# mysql_secure_installation
进去更改密码----n-------n------y------y------y
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: n
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) : y
Success.

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) : y

  • Dropping test database…
    Success.

  • Removing privileges on test database…
    Success.

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) : y
Success.

All done!

安装php
[root@server ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm mysql-boost-5.7.17.tar.gz
mysql-5.7.17 php-5.6.35.tar.bz2
[root@server ~]# tar jxf php-5.6.35.tar.bz2
[root@server ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm mysql-boost-5.7.17.tar.gz php-5.6.35.tar.bz2
mysql-5.7.17 php-5.6.35
[root@server ~]# cd php-5.6.35
[root@server php-5.6.35]#./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

//这里需要安装很多的依赖性,可以每次根据错误的提示进行安装,没有的包在之前分享的链接中可以参考。
[root@server php-5.6.35]# yum install libxml2-devel openssl-devel curl-devel
gd-devel-2.0.35-11.el6.x86_64.rpm gmp-devel libmcrypt-devel-2.5.8-9.el6.x86_64.rpm net-snmp-devel libmcrypt-2.5.8-9.el6.x86_64.rpm //安装依赖性
[root@server ~]# rpm -ivh re2c-0.13.5-1.el6.x86_64.rpm
//安装好后继续在测试一下,直到没有报错
[root@server1 ~]# make && make install
配置php
[root@server1 php-5.6.20]# find -name init.d.php-fpm
./sapi/fpm/init.d.php-fpm
[root@server1 php-5.6.20]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm //拷贝脚本到/etc/init.d/
[root@server1 php-5.6.20]# chmod +x /etc/init.d/php-fpm //添加可执行权限
[root@server1 php-5.6.20]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# ls
pear.conf php-fpm.conf.default php.ini
[root@server1 etc]# vim php.ini //设置时区
在这里插入图片描述
[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server1 etc]#vim php-fpm.conf

安装nginx
配置yum源
在这里插入图片描述
解压,修改配置文件,安装依赖性
[root@server1 ~]# ls
nginx-1.16.0.tar.gz
[root@server1 ~]# tar zxf nginx-1.14.0.tar.gz //解压
[root@server1 ~]# ls
nginx-1.16.0 nginx-1.14.0.tar.gz
[root@server1 ~]# cd nginx-1.14.0
[root@server1 nginx-1.14.0]# ls
auto CHANGES.ru configure html man src
CHANGES conf contrib LICENSE README
[root@server1 nginx-1.14.0]# cd src/
[root@server1 src]# ls
core event http mail misc os stream
[root@server1 src]# cd core/
[root@server1 core]# vim nginx.h

在这里插入图片描述
[root@server1 nginx-1.16.0]# yum install gcc -y //安装依赖性
[root@server1 nginx-1.16.0]# yum install pcre-devel -y
[root@server1 nginx-1.16.0]# yum install openssl-devel -y
源码编译三部曲
[root@server1 nginx-1.16.0]# pwd
/root/nginx-1.14.0
[root@server1 nginx-1.16.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@server1 nginx-1.16.0]# make && make install
[root@server1 nginx-1.16.0]# ln -s /usr/local/nginx/sbin/nginx /sbin/
//创建软连接,所有的二进制文件命令在/sbin下执行
//加入全局变量,与之前软连接的作用相同,这里我还添加了mysql
在这里插入图片描述
[root@server ~]# source .bash_profile //刷新配置
nginx //开启服务
nginx -s reload //刷新策略
nginx -s stop //停止服务
注意,nginx默认使用得失80端口,与apache的相同,两个不能同时打开,否则会冲突
测试
打开nginx,浏览器如此则显示成功
在这里插入图片描述
Nginx负载均衡设置
配置文件设置
[root@server1 ~]# vim /usr/local/nginx/conf/nginx.conf
//后端的服务器为server3与server4,默认算法为轮叫
//在测试的server3与server4的/var/www/html/下写下发布网页,下面用于测试。
//限制访问的域名为www.westos.org
//在物理机上设置域名解析
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
[root@server1 ~]# useradd -M -d /usr/local/lnmp/nginx/ -s /sbin/nologin ngnix
//添加nginx用户
[root@server1 ~]# nginx -s reload //刷新配置
[root@server1 ~]# vim /etc/security/limits.conf //设置系统默认文件数
在这里插入图片描述
访问域名
在这里插入图片描述
nginx添加php
在这里插入图片描述
设置默认发布目录
在这里插入图片描述
[root@server1 conf]# nginx -s reload
测试php
[root@server ~]# cd /usr/local/lnmp/nginx/html/ //nginx默认发布目录
[root@server html]# ls
50x.html index.html
[root@server html]# vim index.php在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值