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

前端之家收集整理的这篇文章主要介绍了CentOS 6.9编译方式搭建LTMP环境,并部署phpMyAdmin数据库管理工具前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一、演示环境:

@H_301_37@ @H_301_37@ @H_301_37@ @H_301_37@ @H_301_37@ @H_403_130@

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

# 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过程中将会提示如下错误




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

配置摘要

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

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

说明:

Ø -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目录中:

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

dso {

load ngx_http_fastcgi_module.so;

}

备注: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

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

ngx_http_fastcgi_module模块已被动态加载。

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

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

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

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

(1)创建LVM

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

# partx -a /dev/sdb

# cat /proc/partitions

(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

(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

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

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

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

# echo $PATH

# MysqL --version

(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

# ss -tunlp | grep :3306

# ps aux | grep MysqLd

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

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

# ls /data/MysqLdata

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

# MysqL -uroot -p

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

MariaDB [(none)]> flush privileges;


五、安装配置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

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

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

# echo "/usr/local/pcre/lib/" > /etc/ld.so.conf.d/pcre.conf # ldconfig

# ln -sv /usr/local/pcre/include /usr/include/pcre-8.42

# 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 //所需时间较长

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

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

# echo "/usr/local/openssl/lib/" > /etc/ld.so.conf.d/openssl.conf # ldconfig

# 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

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

# ln -sv /usr/local/zlib/include /usr/include/zlib-1.2.11

(3)导出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 //所需时间较长

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)导出二进制程序目录至# vim /etc/profile.d/PHP7.sh --> export PATH=/usr/local/PHP7/sbin:/usr/local/PHP7/bin:$PATH

# . /etc/profile.d/PHP7.sh

(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)导出# 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();

?>

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

浏览器中输入http://192.168.199.7

停止192.168.199.8上的MariaDB# service MysqLd stop

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数据库用户名和密码:

猜你在找的CentOS相关文章