关键词:
源码编译安装LNMP架构环境
OS版本:2.6.32-431.el6.x86_64
Nginx版本:nginx-1.6.1
mariadb版本:mariadb-10.0.13
php版本:php-5.4.26
1、安装编译安装所需系统环境
~]# yum groupinstall "Development Tools" "Server Platform Development" -y
2、编译安装nginx-1.6.1
# yum -y install pcre-devel openssl-devel zlib-devel
# tar -xf nginx-1.6.1.tar.gz
# cd nginx-1.6.1
# ./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --user=nginx --group=nginx --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-debug
# make && make install
账号添加,否则开启会报错(nginx: [emerg] getpwnam("nginx") failed)
~]# useradd -r -M nginx
~]# id nginx
uid=498(nginx) gid=498(nginx) 组=498(nginx)
修改配置文件中servername从localhost修改为ip地址启动nginx测试
~]# /usr/local/nginx/sbin/nginx
~]# ss -tnlp | grep nginx
LISTEN 0 128 *:80 *:* users:(("n ginx",3939,6),("nginx",3940,6))
编写一个nginx启动脚本
~]# vim /etc/rc.d/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
sysconfig="/etc/sysconfig/$prog"
lockfile="/var/lock/nginx.lock"
pidfile="/var/run/nginx/${prog}.pid"
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f $sysconfig ] && . $sysconfig
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $pidfile $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest_q || return 6
stop
start
}
reload() {
configtest_q || return 6
echo -n $"Reloading $prog: "
killproc -p $pidfile $prog -HUP
echo
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
configtest_q() {
$nginx -t -q -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
# Upgrade the binary with no downtime.
upgrade() {
local oldbin_pidfile="${pidfile}.oldbin"
configtest_q || return 6
echo -n $"Upgrading $prog: "
killproc -p $pidfile $prog -USR2
retval=$?
sleep 1
if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]]; then
killproc -p $oldbin_pidfile $prog -QUIT
success $"$prog online upgrade"
echo
return 0
else
failure $"$prog online upgrade"
echo
return 1
fi
}
# Tell nginx to reopen logs
reopen_logs() {
configtest_q || return 6
echo -n $"Reopening $prog logs: "
killproc -p $pidfile $prog -USR1
retval=$?
echo
return $retval
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest|reopen_logs)
$1
;;
force-reload|upgrade)
rh_status_q || exit 7
upgrade
;;
reload)
rh_status_q || exit 7
$1
;;
status|status_q)
rh_$1
;;
condrestart|try-restart)
rh_status_q || exit 7
restart
;;
*)
echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}" exit 2
esac
~]# service nginx start
正在启动 nginx: [确定]
~]# service nginx status
nginx (pid 1171 1169) 正在运行...
设置开机启动
~]# chkconfig --add nginx
~]# chkconfig --list nginx
nginx 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
~]# chkconfig nginx on
~]# chkconfig --list nginx
nginx 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
3、mariadb编译安装
首先安装mariadb编译安装所需的cmake、ncurses-devel
~]# yum -y install cmake ncurses-devel
(1)创建数据存放目录
~]# mkdir -pv /data/mydata
mkdir: 已创建目录 "/data"
mkdir: 已创建目录 "/data/mydata"
(2)创建mysql用户,并授予数据文件mysql账户权限
~]# groupadd mysql
~]# useradd -s /sbin/nologin -g mysql -M mysql
~]# id mysql
uid=500(mysql) gid=500(mysql) 组=500(mysql)
~]# chown -R mysql.mysql /data/mydata
(3)安装mariadb
解压mariadb
~]# tar -xf mariadb-10.0.13.tar.gz
编译安装mariadb
mariadb-10.0.13]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mydata -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
mariadb-10.0.13]# make -j 4 && make install
(4)配置mariadb
初始化数据库
~]# cd /usr/local/mysql/
mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mydata
mysql]# ls /data/mydata/
aria_log.00000001 ibdata1 ib_logfile1 performance_schema
aria_log_control ib_logfile0 mysql test
设置配置文件,修改datadir指定目录项和socket所指定文件
[mysqld]
datadir=/data/mydata
socket=/tmp/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
设置启动脚本
mysql]# cp support-files/mysql.server /etc/init.d/mysqld
mysql]# chkconfig --add mysqld
mysql]# chkconfig --list mysqld
启动并查看服务
mysql]# service mysqld start
Starting MySQL. SUCCESS!
~]# ss -tnlp | grep 3306
LISTEN 0 128 :::3306 :::* users:(("mysqld",65174,
16))
设置环境变量
~]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
~]# source /etc/profile.d/mysql.sh
导出头文件
~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
"/usr/local/include/mysql" -> "/usr/local/mysql/include/"
导出库文件
mysql]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
mysql]# ldconfig -v
mysql]# ldconfig -p |grep mysql
libmysqlclient_r.so.16 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient_r.so.16
libmysqlclient.so.18 (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so.18
libmysqlclient.so.16 (libc6,x86-64) => /usr/lib64/mysql/libmysqlclient.so.16
libmysqlclient.so (libc6,x86-64) => /usr/local/mysql/lib/libmysqlclient.so
使用mysql_secure_installation脚本来进行安全配置
[[email protected] mysql]# mysql_secure_installation
/usr/local/mysql/bin/mysql_secure_installation: line 379: find_mysql_client: command not fou
nd
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we‘ll need the current
password for the root user. If you‘ve just installed MariaDB, and
you haven‘t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n]
... 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? [Y/n] n
... skipping.
By default, MariaDB 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? [Y/n] n
... skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n]
... Success!
Cleaning up...
All done! If you‘ve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
4、编译安装php
编译安装前安装所需要包
~]# yum -y install libxml2-devel
安装bzip2-devel
php-5.4.26]# yum -y install bzip2-devel
~]# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
~]# tar -xf libmcrypt-2.5.7.tar.gz
~]# cd libmcrypt-2.5.7
libmcrypt-2.5.7]# ./configure
libmcrypt-2.5.7]# make && make install
解压并进行编译安装,nginx是通过php-fpm连接php的,编译时需添加--enable-fpm
./configure --prefix=/usr/local/php5 --with-mysql=mysqlnd --with-openssl --with-mysqli=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
再次编译没有问题,进行安装
php-5.4.26]# make -j 4 && make install
拷贝配置文件至/etc目录
php-5.4.26]# cp php.ini-production /etc/php.ini
拷贝php-fpm配置文件,并同时取消pid选项的注释
cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
php-5.4.26]# vim /usr/local/php5/etc/php-fpm.conf
pid = /usr/local/php5/var/run/php-fpm.pid
添加服务脚本
fpm]# pwd
/root/php-5.4.26/sapi/fpm
fpm]# cp init.d.php-fpm /etc/rc.d/init.d/php-fpm
~]# chmod +x /etc/rc.d/init.d/php-fpm
~]# chkconfig --add php-fpm
启动php-fpm
~]# service php-fpm start
~]# ps aux | grep fpm
root 14881 0.0 0.3 68920 3928 ? Ss 09:51 0:00 php-fpm: master process (/usr/local/php5/etc/php-fpm.conf) nobody 14882 0.0 0.3 68920 3460 ? S 09:51 0:00 php-fpm: pool www
nobody 14883 0.0 0.3 68920 3460 ? S 09:51 0:00 php-fpm: pool www
root 14885 0.0 0.0 103260 872 pts/1 S+ 09:51 0:00 grep f
5、修改nginx.conf文件,支持php
location / {
root html;
index index.html index.htm index.php; 添加支持index.php
}
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf; 这边要注意的是直接include fastcgi.conf即可,老版本的使用方法是fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;再include。参考http://gxl-ct001.iteye.com/blog/2270522
}
修改完成后重启nginx
service nginx restart
停止 nginx: [确定]
正在启动 nginx: [确定]
6、编写测试页进行测试
vim /usr/local/nginx/html/index.php
<h1>LNMP TEST</h1>
<?php
$conn = mysql_connect(‘localhost‘,‘root‘,‘oracleadmin‘); 测试连接mariadb是否ok
if ($conn)
echo "OK";
else
echo "Failure";
phpinfo(); 测试nginx使用php是否ok
?>
本文出自 “Open World” 博客,请务必保留此出处http://voidyao000.blog.51cto.com/12458042/1896064
源码编译lnmp环境
一、环境准备:1.部署LNMP架构需要安装依赖包yum-yinstallmakegccgcc-c++flexbisonfilelibtoollibtool-libsautoconfkernel-devellibjpeglibjpeg-devellibpnglibpng-develgdfreetypefreetype-devellibxml2libxml2-develzlibzlib-d 查看详情
20使用lnmp架构部署动态网站环境(代码片段)
20使用LNMP架构部署动态网站环境20.1源码包程序源码包的可移植性非常好,几乎可以在任何Linux系统中安装使用,而RPM软件包是针对特定系统和架构编写的指令集,必须严格地符合执行环境才能顺利安装(即只会去“生硬地”安装... 查看详情
源码编译安装lnmp环境
一、源码编译安装步骤首先说明源码安装的好处 速度快,可自定义路径主要有三步:1.配置进入源码安装包 ./configure--prefix=/uer/local/nginx 可指定参数--prefix为安装路径2.编译相当于rpm包 make3.安装makeinstall如果安... 查看详情
第20章使用lnmp架构部署动态网站环境
...有免费、高效、扩展性强且资源消耗低等优良特性。使用源码包来安装服务程序具有两个优势。1、源码包的可移植性非常好。2、使用源码包安装可以更好地适应安装主机的系统环境,运行效率和优化程度都会强于使用RPM软件包... 查看详情
源码编译lnmp架构(代码片段)
众所周知,LAMP平台是目前应用最为广泛的网站服务器架构,其中的“A”对应着Web服务软件ApacheHTTPServer。随着Nginx在企业中的使用越来越多,LNMP(或LEMP)架构也受到越来越多Linux系统工程师的青睐,其中的“E”就来自于Nginx的发音[... 查看详情
lnmp架构搭建论坛
配置PHP服务(1)cd/usr/local/src(2)解压编译生成安装yasm源码包(3)安装libmcrypt源码包(4)安装libvpx源码包(5)安装tiff源码包(6)安装libpng源码包(7)安装freetype源码包(8)安装jpegsrc源码包(9)安装libgb源码包(10)安装t1lib... 查看详情
centos6源码编译安装lnmp环境(代码片段)
操作系统版本64位CentOS-6.6 10.0.0.20安装环境所需依赖包yum-yinstallgccautomakeautoconflibtoolmakegcc-c++glibclibxslt-devellibjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-devellibxml2libxml2-develzlib 查看详情
2-21-源码编译搭建lnmp环境
源码编译部署LNMP架构 LNMP=Linux+Nginx+MySQL+PHP Nginx("enginex")是一个高性能的HTTP和反向代理服务器。Nginx是由IgorSysoev为俄罗斯访问量第二的Rambler.ru站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许... 查看详情
linuxcentos7源码编译安装lnmp企业级架构(代码片段)
准备工作#统一下载存放目录cd/usr/local/src#mysql源码包下载网址https://downloads.mysql.com/archives/community/#下载包括Boost标头的mysql-5.7.33.tar.gzwgethttps://downloads.mysql.com/archives/get/p/23/file/mysql-boost-5.7.33.tar.g 查看详情
lnmp架构
...墙,selinux关闭) 安装nginx服务(配置相应的模块)yum或者源码编译安装 安装php-fpm环境 安装mysql数据库服务 ②安装好基础环境之后,建立php-fpm和nginx的关联,修改nginx的配置文件nginx.conf ③建立php-fpm和mysql数据... 查看详情
源码编译安装lnmp
LNMP LNMP就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。 Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。  ... 查看详情
lnmp架构部署动态网络环境
...从Linux系统的软件安装方式讲起,带领读者分辨RPM软件包与源码安装的区别、并能够理解它们的优缺点。Nginx是一款相当优秀的用于部署动态网站的服务程序,Ng 查看详情
lnmp架构部署动态网络环境
...从Linux系统的软件安装方式讲起,带领读者分辨RPM软件包与源码安装的区别、并能够理解它们的优缺点。Nginx是一款相当优秀的用于部署动态网站的服务程序,Ng 查看详情
saltstack之编译安装lnmp环境
...装文档 目录结构为 其中files文件夹下面放置的是源码包install.sls 查看详情
lnmp服务搭建
LNMP服务搭建解压yusm源码包编译yusm源码生成数据安装yasm开源汇编器解压libmcrypt包编译libmcrypt生成数据安装程序解压libvpx包编译生成安装解压tiff包编译生成安装解压libpng编译生成安装解压frertype编译生成安装解压jpeg编译生成安装... 查看详情
lnmp架构介绍
...加到服务并重新启动PHP安装步骤2进入PHP目录先清除之前编译的文件makeclean编译文件nable不加无法启动make&&makeinstall查看文件-t测试配置文件的语法拷贝配置文件如果是开发环境使用development如果是生产环境使用production编辑文... 查看详情
第十一周作业
1、源码编译安装LNMP架构环境;2、编写一个脚本完成以下功能:(1)、一键搭建LNMP源码编译环境;(2)、可通过在脚本后面跟上一些参数来自定义安装目录等其他选项。#!/bin/bashread -p ‘Please enter the installation p... 查看详情
搭建lnmp环境(代码片段)
...p;7作为安装环境。一.gcc安装安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,则需要安装:yuminstallgcc-c++二.PCREpcre-devel安装PCRE(PerlCompatibleRegularExpr 查看详情