CentOs7.5--LNMP源码环境搭建文档

CentOs7.5–LNMP源码环境搭建文档

搭建环境–腾讯云CentOs7.5 x64系统

一、LNMP环境的介绍

1. LNMP架构介绍

1.LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。Nginx中的PHP是以fastcgi的方式结合Nginx的,可以理解为Nginx代理了PHP的fastcgi。

2.Nginx提供web服务,php作为一个独立的服务存在,这个服务叫做php-fpm

Nginx直接处理静态请求,动态请求会转发给php-fpm

对于静态文件处理上性能高于Apache,并发高,响应快,低消耗

2. 软件包下载地址

MySQL 8.0 源码包下载地址:https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.13.tar.gz

nginx 1.14.1 源码包下载地址:http://nginx.org/download/nginx-1.14.1.tar.gz

php 7.2.12 源码包下载地址:http://cn2.php.net/get/php-7.2.12.tar.gz/from/this/mirror

软件包下载目录 /root/soft

二、Nginx源码安装

1.解压进入目录

# tar zxf nginx-1.14.1.tar.gz 
# cd nginx-1.14.1/

2.创建nginx运行的用户和用户组

# useradd www -r -s /sbin/nologin

3.配置编译参数

nginx依赖pcre库进行url重写,如果需要部署支持https协议,需要ssl的支持,安装openssl
# yum install gcc  pcre-devel openssl-devel
# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --user=www --group=www
# make && make install

4.启动nginx

# /usr/local/nginx/sbin/nginx

5.关闭nginx命令

# /usr/local/nginx/sbin/nginx -s stop

三、PHP源码安装

1.解压进入目录

# tar zxf php-7.2.12.tar.gz
# cd php-7.2.12/

2.编译参数配置

编译过程出错 安装以下软件
# yum -y install curl-deve libxml2 libxml2-devel libjpeg-devel libpng libpng-devel freetype-devel

# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts

# make && make install

3.复制配置文件

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# cp /root/soft/php-7.2.12/php.ini-development /usr/local/php/etc/php.ini
# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

4.添加启动服务

# cp /root/soft/php-7.2.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm 
# chkconfig --add php-fpm

5.添加环境变量

# echo 'PATH=/usr/local/php/bin:$PATH' >> /etc/profile
# source /etc/profile

6.启动php

# service php-fpm start
Starting php-fpm  done

四、MySQL源码安装

1.创建mysql用户,mysql启动用这个用户

# useradd mysql -r -s /sbin/nologin

2.编译安装mysql

MySQL从5.5开始,源代码安装将原来的configure改为cmake,因此在安装MySQL5.5.x以上版本时,需要先安装cmake,通过yum安装

①安装cmake

# yum -y install gcc-c++ cmake

②解压并进行配置

# tar xf mysql-boost-8.0.13.tar.gz 
# cd mysql-8.0.13/

# vim cmake.sh
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_BOOST=/root/soft/mysql-8.0.13/boost \
-DWITH_SSL=bundled

# sh cmake.sh

在cmake时候报错,注意解决依赖,并删除编译缓存文件,重新cmake

# yum -y install ncurses-devel
# rm -f CMakeCache.txt 
重新cmake以上参数

③编译安装

# make && make install

由于我个人服务器内存为2G 而安装mysql8.0至少需要2G内存,在编译过程中会报以下错,是内存不足导致

c++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make[2]: *** [sql/CMakeFiles/sql_gis.dir/item_geofunc_setops.cc.o] Error 4
make[1]: *** [sql/CMakeFiles/sql_gis.dir/all] Error 2
make: *** [all] Error 2

出现这种情况执行以下操作,临时使用交换分区来解决,然后重新编译安装

# dd if=/dev/zero of=/data/swapfile bs=1M count=2048
# mkswap /data/swapfile
# swapon /data/swapfile

④查看安装目录

# ls /usr/local/mysql
bin   docs     lib      LICENSE.router  man         README         README-test  share
data  include  LICENSE  LICENSE-test    mysql-test  README.router  run          support-files

3.配置

①授权

# chown -R mysql. /usr/local/mysql

②初始化

# cd /usr/local/mysql
# ./bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data
# ./bin/mysql_ssl_rsa_setup

③添加环境变量(mysql命令可直接使用)

# echo 'PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
# cat /etc/profile

④配置my.cnf文件

# cat /etc/my.cnf 
[mysqld]
server-id=1
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
log-error=/usr/local/mysql/data/mysqld.log

⑤启动mysql 并且修改账号密码

# mysqld_safe --user=mysql &
初始密码在文件  /usr/local/mysql/data/mysqld.log 中
# cat /usr/local/mysql/data/mysqld.log
[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: qLGlXo8<Gs;A

# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.13

Copyright (c) 2000, 2018, 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> alter user 'root'@'localhost' identified by "123456";
mysql> flush privileges;


mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

4.添加到服务启动

# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chkconfig --add mysqld

猜你喜欢

转载自blog.csdn.net/SU_Devops/article/details/84799596