CentOS 6.9编译方式搭建LTMP环境,并部署phpMyAdmin数据库管理工具

一、演示环境:

IP

安装的程序包

版本

下载地址

192.168.199.7

Tengine

tengine-2.2.2.tar.gz

http://tengine.taobao.org/download_cn.html

PHP

php-7.0.29.tar.gz

http://www.php.net/downloads.php

phpMyAdmin

phpMyAdmin-4.8.0.1-all-languages.zip

https://www.phpmyadmin.net/downloads/

192.168.199.8

mariadb

mariadb-10.2.14-linux-x86_64.tar.gz

https://downloads.mariadb.org/

备注:Tengine是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验。它的最终目标是打造一个高效、稳定、安全、易用的Web平台。


二、准备工作:

1、下载上述程序包

2、服务器时间校对

3、配置epel

4、安装开发环境程序包组:# yum -y groupinstall "Development Tools" "Server Platform Development"


三、安装配置Tengine

1、安装依赖程序包:

# yum -y install libxml2-devel libxslt-devel gd-devel GeoIP-devel google-perftools-devel libatomic_ops-devel cmake

2、解压pcreperl兼容的正则表达式库,下载地址:https://ftp.pcre.org/pub/pcre/):

# tar -xf pcre-8.42.tar.gz -C /usr/src  # ls /usr/src/pcre-8.42

3、解压openssl(安全套接字层密码库,下载地址:https://www.openssl.org/source/):

# tar -xf openssl-1.0.2o.tar.gz -C /usr/src  # ls /usr/src/openssl-1.0.2o

4、解压zlib(提供数据压缩用的函式库,下载地址:http://www.zlib.net/):

# tar -xf zlib-1.2.11.tar.gz -C /usr/src  # ls /usr/src/zlib-1.2.11

5、使用TCMalloc优化Tengine性能:

        TCMalloc是谷歌开发的开源工具google-perftools中的一员,与标准的glibc库的Malloc相比,TCMalloc库在内存分配效率和速度上要高很多,这在很大程度上提高了服务器在高并发情况下的性能,从而降低了系统的负载。要安装TCMalloc库,需要安装libunwind32位操作系统不需要安装)和google-perftools两个程序包,libunwind库为基于64CPU和操作系统的程序提供了基本函数调用链和函数调用寄存器功能。

(1)编译安装libunwind库(下载地址:http://download.savannah.nongnu.org/releases/libunwind/):

# tar -xf libunwind-1.2.tar.gz -C /usr/src

# cd /usr/src/libunwind-1.2

# ./configure

# make && make install

(2)编译安装google-perftools(下载地址:https://github.com/gperftools/gperftools/releases):

# tar -xf gperftools-2.6.3.tar.gz -C /usr/src

# cd /usr/src/gperftools-2.6.3

# ./configure --enable-libunwind --enable-frame-pointers --enable-emergency-malloc

# make && make install

//google-perftools添加线程目录,并修改目录权限

# mkdir -p /tmp/tcmalloc

# chmod -R 0777 /tmp/tcmalloc

6、安装淘宝分布式文件系统TFS所需的yajl库(开源的JSON库,下载地址http://lloyd.github.io/yajl/):

# tar -xf lloyd-yajl-2.1.0-0-ga0ecdde.tar.gz -C /usr/src

# cd /usr/src/lloyd-yajl-66cb08c

# ./configure

# make && make install

# ln -sv /usr/local/lib/libyajl.so.2 /usr/lib64/libyajl.so.2

7、添加Tengine用户和组:

# groupadd -r tengine  # useradd -g tengine -r -s /sbin/nologin tengine  # id tengine

8、编译安装Tengine

# tar -xf tengine-2.2.2.tar.gz -C /usr/src

# cd /usr/src/tengine-2.2.2

# ./configure --prefix=/usr/local/tengine --user=tengine --group=tengine --with-rtsig_module --with-select_module --with-poll_module --with-threads --with-file-aio --with-force-exit --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_slice_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_concat_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_sysguard_module --with-http_charset_filter_module=shared --with-http_userid_filter_module=shared --with-http_footer_filter_module=shared --with-http_trim_filter_module=shared --with-http_access_module=shared --with-http_autoindex_module=shared --with-http_map_module=shared --with-http_split_clients_module=shared --with-http_referer_module=shared --with-http_rewrite_module=shared --with-http_fastcgi_module=shared --with-http_uwsgi_module=shared --with-http_scgi_module=shared --with-http_memcached_module=shared --with-http_limit_conn_module=shared --with-http_limit_req_module=shared --with-http_empty_gif_module=shared --with-http_browser_module=shared --with-http_user_agent_module=shared --with-http_upstream_hash_module=shared --with-http_upstream_ip_hash_module=shared --with-http_upstream_least_conn_module=shared --with-http_upstream_session_sticky_module=shared --with-http_reqstat_module=shared --with-http_dyups_module --with-mail --with-mail_ssl_module --with-backtrace_module --with-http_tfs_module --with-pcre-jit --with-libatomic --http-log-path=/usr/local/tengine/logs/access.log --with-google_perftools_module --with-pcre=/usr/src/pcre-8.42 --with-openssl=/usr/src/openssl-1.0.2o --with-zlib=/usr/src/zlib-1.2.11 --with-pcre-opt=-fPIC --with-openssl-opt=-fPIC --with-zlib-opt=-fPIC | tee /tmp/tengine_install.log

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

特别注意:

Ø  编译Tengine时有3个选项:--with-pcre=DIR--with-openssl=DIR--with-zlib=DIR,此处的DIR皆为解压后的源码包存放路径,而非安装路径

Ø  | tee /tmp/tengine_install.log表示将整个configure过程保存至/tmp/tengine_install.log文件中

Ø  另外如果编译过程中不加--with-pcre-opt=-fPIC--with-openssl-opt=-fPIC--with-zlib-opt=-fPIC3个选项,在make过程中将会提示如下错误:

1.jpg


2.jpg


3.jpg


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

配置摘要:

4.jpg

# make && make install            //所需时间较长

9、显示Tengine帮助信息:# /usr/local/tengine/sbin/nginx -h

5.jpg

说明:

Ø  -h:显示帮助信息

Ø  -v:显示Tengine版本

Ø  -m:显示所有静态编译的模块

Ø  -l:显示所有可配置的指令

Ø  -V:显示版本、编译安装时的选项、所有静态编译的模块

Ø  -t:检查Tengine配置文件语法

Ø  -s [stop | quit | reopen | reload]:关闭 | 退出 | 重新打开 | 重载Tengine

10、配置Tengine

(1)导出二进制程序目录至PATH环境变量中:

# vim /etc/profile.d/tengine.sh  -->  export PATH=/usr/local/tengine/sbin:$PATH

# . /etc/profile.d/tengine.sh

# echo $PATH

(2)导出头文件:# ln -sv /usr/local/tengine/include /usr/include/tengine-2.2.2

(3)修改目录权限:# chown -R tengine.tengine /usr/local/tengine

(4)动态加载ngx_http_fastcgi_module模块(DSO):

# nginx -m的执行结果中没有显示之前使用--with-http_fastcgi_module=shared编译的ngx_http_fastcgi_module模块,shared表示此模块为动态编译的模块,可以动态加载或卸载,无需重新编译Tengine动态编译的模块都位于/usr/local/tengine/modules目录中:

6.jpg

修改配置文件/usr/local/tengine/conf/nginx.conf,在events{}配置段前新增如下代码:

dso {

load ngx_http_fastcgi_module.so;

}

7.jpg

备注:load命令用于在指定路径module_path,将指定模块module_name动态加载到Tengine中。

(5)加载google-perftools

修改配置文件/usr/local/tengine/conf/nginx.conf,在#pid  logs/nginx.pid;下新增如下代码:

google_perftools_profiles  /tmp/tcmalloc;

11、启动Tengine,并验证上述配置:

(1)启动Tengine# nginx -t  # nginx  # ss -tunlp | grep :80  # ps aux | grep nginx

(2)浏览器中访问默认测试页:http://192.168.199.7

8.jpg

(3)显示加载的模块信息:# nginx -m

9.jpg

ngx_http_fastcgi_module模块已被动态加载。

(4)测试tcmalloc# lsof -n | grep tcmalloc

10.jpg

备注:由于配置文件中默认worker_processes的值为1,所以只开启了1worker线程,每个线程会有一行记录,每个线程文件后的数值就是启动的TenginePID值。


四、安装配置二进制格式的mariadb

1、虚机添加新硬盘,创建LVM逻辑卷,并创建用于存放mariadb数据的目录:

(1)创建LVM

11.jpg

# fdisk /dev/sdb --> n --> p --> 1 --> 回车 --> +20G --> t --> 8e --> p --> w

# partx -a /dev/sdb

# cat /proc/partitions

12.jpg

(2)创建pv# pvcreate /dev/sdb1  # pvs

(3)创建vg# vgcreate mysqlvg /dev/sdb1  # vgs

(4)创建lv# lvcreate -l +100%FREE mysqlvg -n mysqldata  # lvs

(5)格式化LVM# mke2fs -t ext4 /dev/mysqlvg/mysqldata

(6)创建挂载点:# mkdir -pv /data

(7)开机自动挂载:# vim /etc/fstab  -->  /dev/mysqlvg/mysqldata  /data  ext4  defaults  0  0

(8)挂载分区并查看分区信息:# mount -a  # mount | grep data  # df -Th | grep data

13.jpg

(9)创建用于存放mariadb数据的目录:# mkdir -pv /data/mysqldata

(10)创建mysql用户和组:# groupadd -r mysql  # useradd -g mysql -r -s /sbin/nologin mysql  # id mysql

(11)设置数据目录权限:# cd /data  # chown -R mysql.mysql mysqldata  # chmod -R o-rx mysqldata

2、解压mariadb

# tar -xf mariadb-10.2.14-linux-x86_64.tar.gz -C /usr/local

# cd /usr/local

# mv mariadb-10.2.14-linux-x86_64/ mysql

# cd mysql

# chown -R mysql.mysql .

3、配置mariadb

(1)导出二进制程序目录至PATH环境变量中:

# vim /etc/profile.d/mariadb.sh  -->  export PATH=/usr/local/mysql/bin:$PATH

# . /etc/profile.d/mariadb.sh

# echo $PATH

# mysql --version

14.jpg

(2)导出库文件:# vim /etc/ld.so.conf.d/mariadb.conf  -->  /usr/local/mysql/lib  # ldconfig

(3)导出头文件:# ln -sv /usr/local/mysql/include/mysql /usr/include/mysql

(4)导出man帮助文档:# vim /etc/man.config  -->  MANPATH /usr/local/mysql/man

(5)创建并修改my.cnf配置文件:

# find / -name my.cnf                               //如果系统中事先已存在my.cnf,将其重命名备份

# cp /usr/local/mysql/support-files/my-innodb-heavy-4G.cnf /etc/my.cnf

备注:MariaDB的配置文件my.cnf是集中式的配置文件,可以为多个程序提供配置,包括clientmysqlmysqld等等。查找配置文件的顺序依次为:/etc/my.cnf  -->  /etc/mysql/my.cnf  -->  $BASEDIR/my.cnf  -->  --defaults-extra-file=/PATH/TO/CONF_FILE  -->  ~/.my.cnf。如果发现多个my.cnf配置文件,那最后一个被读到的配置文件将会最终生效,即如果存在~/.my.cnf配置文件,那么MariaDB服务器的配置以此文件为准。

# vim /etc/my.cnf,在[mysqld]配置段中增加如下代码:

basedir = /usr/local/mysql

datadir = /data/mysqldata

user = mysql

skip_name_resolve = on

注释thread_concurrency = 8

(6)初始化mariadb

# ls /data/mysqldata                   //确认存放数据的目录必须为空

# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldata --defaults-file=/etc/my.cnf --skip-name-resolve

(7)使用service命令控制mariadb,并设置开机自启:

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

# vim /etc/init.d/mysqld,修改如下2行内容:

Ø  将第46basedir参数的值设置为/usr/local/mysql

Ø  将第47datadir参数的值设置为/data/mysqldata

# chkconfig --add mysqld

# chkconfig mysqld on

# chkconfig --list mysqld

# service mysqld start

15.jpg

# ss -tunlp | grep :3306

# ps aux | grep mysqld

(8)mariadb安全性设置:# mysql_secure_installation

备注:用于设置root用户密码、删除匿名用户、是否允许root用户远程登录、删除测试数据库和重载授权表。

# ls /data/mysqldata

16.jpg

(9)授权root用户远程访问MariaDB

# mysql -uroot -p

MariaDB [(none)]> grant all on *.* to 'root'@'%' identified by '123456';

MariaDB [(none)]> flush privileges;

17.jpg


五、安装配置PHP

1、安装配置依赖程序包:

# yum -y install libxml2-devel bzip2-devel curl-devel libpng-devel libjpeg-devel freetype-devel readline-devel ncurses-devel libmcrypt-devel gd-devel libxslt-devel openldap-devel recode-devel net-snmp-devel libicu-devel libtidy-devel libacl-devel gmp-devel libevent-devel

# ln -sv /usr/lib64/libldap* /usr/lib/

2、编译安装pcre

# cd /usr/src/pcre-8.42

# ./configure --prefix=/usr/local/pcre

# make && make install

(1)导出二进制程序目录至PATH环境变量中:

# vim /etc/profile.d/pcre.sh  -->  export PATH=/usr/local/pcre/bin:$PATH

# . /etc/profile.d/pcre.sh

# echo $PATH

(2)导出库文件:# echo "/usr/local/pcre/lib/" > /etc/ld.so.conf.d/pcre.conf  # ldconfig

(3)导出头文件:# ln -sv /usr/local/pcre/include /usr/include/pcre-8.42

(4)导出man帮助文档:# vim /etc/man.config,新增一行:MANPATH /usr/local/pcre/share/man

3、编译安装openssl

# cd /usr/src/openssl-1.0.2o

# ./config --prefix=/usr/local/openssl

# make && make install            //所需时间较长

(1)导出二进制程序目录至PATH环境变量中:

# vim /etc/profile.d/openssl.sh  -->  export PATH=/usr/local/openssl/bin:$PATH

# . /etc/profile.d/openssl.sh

# echo $PATH

(2)导出库文件:# echo "/usr/local/openssl/lib/" > /etc/ld.so.conf.d/openssl.conf  # ldconfig

(3)导出头文件:# ln -sv /usr/local/openssl/include /usr/include/openssl-1.0.2o

4、编译安装zlib

# cd /usr/src/zlib-1.2.11

# ./configure --prefix=/usr/local/zlib

# make && make install

(1)导出库文件:# echo "/usr/local/zlib/lib/" > /etc/ld.so.conf.d/zlib.conf  # ldconfig

(2)导出头文件:# ln -sv /usr/local/zlib/include /usr/include/zlib-1.2.11

(3)导出man帮助文档:# vim /etc/man.config,新增一行:MANPATH /usr/local/zlib/share/man

备注:pcreopensslzlib在编译安装Tengine时,只是解压了源码包,还没有进行安装。

5、编译安装php

# find / -name php.ini                   //如果系统中事先已存在php.ini,将其重命名备份

# tar -xf php-7.0.29.tar.gz -C /usr/src

# cd /usr/src/php-7.0.29

# ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc/ --with-config-file-scan-dir=/usr/local/php7/etc/ --enable-fpm --with-fpm-user=tengine --with-fpm-group=tengine --with-fpm-acl --enable-sigchild --disable-ipv6 --with-openssl=/usr/local/openssl --with-openssl-dir=/usr/local/openssl --with-zlib=/usr/local/zlib --with-zlib-dir=/usr/local/zlib --enable-bcmath --with-system-ciphers --with-pcre-dir=/usr/local/pcre --with-pcre-regex=/usr/local/pcre --with-pcre-jit --enable-calendar --enable-exif --enable-ftp --enable-gd-native-ttf --enable-gd-jis-conv --with-imap-ssl=/usr/local/openssl --enable-intl --enable-mbstring --enable-wddx --enable-zip --enable-zend-signals --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --enable-soap --enable-shmop --enable-pcntl --enable-maintainer-zts --enable-zend-signals --with-bz2 --with-curl --with-gd --with-gettext --with-xmlrpc --with-xsl --with-mhash --with-ldap --with-ldap-sasl --with-readline --with-recode --with-snmp --with-libxml-dir --with-jpeg-dir --with-png-dir --with-freetype-dir --with-libmbfl --with-onig --with-mcrypt --with-gmp --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd | tee /tmp/php7_install.log

# make && make install            //所需时间较长

18.jpg

6、 配置PHP

(1)复制php.ini配置文件:# cp /usr/src/php-7.0.29/php.ini-production /usr/local/php7/etc/php.ini

(2)复制php-fpm.conf配置文件:# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf

(3)配置www.confphp-fpm进程服务扩展配置文件):

# cd /usr/local/php7/etc/php-fpm.d

# cp www.conf.default www.conf

# vim www.conf,修改如下2项参数的值:

Ø  listen = 192.168.199.7:9000

Ø  listen.allowed_clients = 192.168.199.7

(4)导出二进制程序目录至PATH环境变量中:

# vim /etc/profile.d/php7.sh  -->  export PATH=/usr/local/php7/sbin:/usr/local/php7/bin:$PATH

# . /etc/profile.d/php7.sh

# echo $PATH

(5)导出库文件:# vim /etc/ld.so.conf.d/php7.conf  -->  /usr/local/php7/lib  # ldconfig

(6)导出头文件:# ln -sv /usr/local/php7/include/php /usr/include/php7

(7)导出man帮助文档:# vim /etc/man.config  -->  MANPATH /usr/local/php7/php/man

(8)设置开机自启:

# cp /usr/src/php-7.0.29/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

# chmod +x /etc/init.d/php-fpm

# chkconfig --add php-fpm

# chkconfig php-fpm on

# chkconfig --list php-fpm

# service php-fpm start

# ps -ef | grep php-fpm

# ss -tunlp | grep :9000


六、测试LTMP

1、配置Tengine支持PHP

# vim /usr/local/tengine/conf/nginx.conf

server {

listen        80;

server_name  localhost;

root         /usr/local/tengine/html;

 

location / {

index index.php index.html index.htm;

}

 

location ~ \.php$ {

fastcgi_pass   192.168.199.7:9000;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

include       fastcgi_params;

}

}

# nginx -t

# nginx -s reload

# service php-fpm restart

2、创建测试页:

# vim /usr/local/tengine/html/index.php

<?php

$conn = mysqli_connect("192.168.199.8","root","123456");

if ($conn)

echo "Success";

else

echo "Failure";

mysqli_close();

phpinfo();

?>

19.jpg

备注:如果在PHP7中使用之前PHP5mysql_connect()函数连接MySQL,会提示undefined function mysql_connect()。从PHP5.5开始,mariadb就不推荐使用mysql_connect()函数,属于废弃函数,PHP7中已彻底不支持,其增加了mysqli的函数功能。从某种意义上讲,它是mariadb系统函数的增强版,更稳定、更高效、更安全,属于面向对象,用对象的方式操作驱动mariadb数据库。

浏览器中输入http://192.168.199.7

20.jpg

停止192.168.199.8上的MariaDB# service mysqld stop

21.jpg

PHPMariaDB通信正常


七、安装配置phpMyAdmin数据库管理工具:

       phpMyAdmin是一个以PHP为基础,以Web-Base方式架构在网站主机上的MariaDB的数据库管理工具,让管理员可用WebGUI接口管理MariaDB数据库。

1、解压phpMyAdmin

# unzip -q phpMyAdmin-4.8.0.1-all-languages.zip -d /usr/local/tengine/html

# cd /usr/local/tengine/html

# mv phpMyAdmin-4.8.0.1-all-languages/ pma

2、配置phpMyAdmin

# cd pma

# cp config.sample.inc.php config.inc.php

//生成随机字符串

# openssl rand -base64 8  -->  uRYO7/xG88k=

//指定用于cookie认证的信息,可以是任意字符串

# vim config.inc.php

Ø  $cfg['blowfish_secret'] = 'uRYO7/xG88k=';

Ø  $cfg['Servers'][$i]['host'] = '192.168.199.8';

# nginx -s reload

浏览器中输入http://192.168.199.7/pma,用户名和密码均为MariaDB数据库的用户名和密码:

22.jpg

23.jpg 


猜你喜欢

转载自blog.51cto.com/qiuyue/2106176