centos7 编译安装新版LNMP环境
centos7 编译安装新版LNMP环境
环境版本如下:
1、系统环境:Centos 7 x86_64
2、NGINX:nginx-1.11.3.tar.gz
3、数据库:mariadb-10.0.28-linux-glibc_214-x86_64.tar.gz
4、PHP:php-5.6.25.tar.gz
记得不要忘了先安装gcc gcc-c++ wget net-tools等功能哦。
一、首先安装mariadb
应为数据库编译需要很长时间,所以我这里下载的是已经编译好了的二进制包,下载版本为:mariadb-10.0.28-linux-glibc_214-x86_64.tar.gz
1、下载二进制包到/usr/local/src 目录下:
2、将压缩包解压到/home/work/env 目录下: #根据个人习惯更改安装目录,下面不再做解释。#/home/work/env/
[root@centos74 src]#tar zvxf mariadb-10.0.28-linux-glibc_214-x86_64.tar.gz -C /home/work/env
3、[root@centos74 src]# mv /home/work/env/mariadb-10.0.28-linux-x86_64/ /home/work/env/mariadb
4、创建mariadb 数据初始化目录/home/work/env/mariadb/data/mysql:
[root@centos74 src]# mkdir -p /home/work/env/mariadb/data/mysql
5、将mariadb 数据初始化目录所属主和组都修改为work:
[root@centos74 src]# chown -R work:work /home/work/env/mariadb/data/mysql
6、进入重命名后的目录,初始化mariadb:
root@centos74 src]# cd /home/work/env/mariadb
[root@centos74 mysql]# ./scripts/mysql_install_db --datadir=/home/work/env/mariadb/data/mysql --user=work
Installing MariaDB/MySQL system tables in '/home/work/env/mariadb/data/mysql
' ... :: [Note] InnoDB: Using mutexes to ref count buffer pool pages :: [Note] InnoDB: The InnoDB memory heap is disabled :: [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins :: [Note] InnoDB: Compressed tables use zlib 1.2. :: [Note] InnoDB: Using Linux native AIO :: [Note] InnoDB: Using CPU crc32 instructions :: [Note] InnoDB: Initializing buffer pool, size = 128.0M ........................................................................ The latest information about MariaDB is available at http://mariadb.org/. You can find additional information about the MySQL part at: http://dev.mysql.com Support MariaDB development by buying support/new features from SkySQL Ab. You can contact us about this at sales@skysql.com. Alternatively consider joining our community based development effort: http://mariadb.com/kb/en/contributing-to-the-mariadb-project/
报错:WARNING: The host 'test4' could not be looked up with resolveip.
解决办法:vim /etc/hosts 在最后一行添加192.168.1.242 test4
报错:./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决办法:yum -y install libaio-devel libaio
7、配置文件/home/work/env/mariadb/my.cnf
[client]
port =
socket = /home/work/env/mariadb/data/mysql.sock
default-character-set = utf8
[mysqld]
port =
tmp_table_size = 512M
max_heap_table_size = 512M
socket = /home/work/env/mariadb/data/mysql.sock
character-set-server = utf8
character-set-filesystem = utf8
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 32M
table_open_cache =
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
ft_min_word_len =
thread_cache_size =
query_cache_size = 16M
thread_concurrency =
max_connections =
slave_net_timeout =
max_connect_errors =
binlog_format = row
expire-logs-days =
#binlog-ignore-db = mysql
server-id =
log-bin = mysql-bin
log-slave-updates
relay-log = mysqld-relay-bin
relay-log-purge =
slow-query-log =
long_query_time =
innodb_file_per_table =
innodb_open_files =
innodb_buffer_pool_size = 6G
innodb_additional_mem_pool_size = 16M
innodb_log_file_size = 512M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit =
innodb_lock_wait_timeout = [mysqldump]
quick
max_allowed_packet = 16M [mysql]
no-auto-rehash
default-character-set=utf8
[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 2M
write_buffer = 2M [mysqlhotcopy]
interactive-timeout
8、编辑mariadb启动脚本文件/home/work/env/mariadb/start.sh
#!/bin/sh
dir=`dirname $(realpath $)`
cmd="nohup $dir/bin/mysqld_safe --defaults-file=$dir/my.cnf --basedir=$dir --ledir=$dir/bin --datadir=$dir/data --log-error=$dir/data/mysql.err --pid-file=$dir/data/mysql.pid >> mysql.log 2>&1 & echo $!"
echo $cmd
nohup $dir/bin/mysqld_safe --defaults-file=$dir/my.cnf --basedir=$dir --ledir=$dir/bin --datadir=$dir/data --log-error=$dir/data/mysql.err --pid-file=$dir/data/mysql.pid >> mysql.log >& & echo $! sleep
# 确保mysql已经起来后, 再退出
while true
do
pid_file="$dir/data/mysql.pid"
if test -f "$pid_file"
then
PID=`cat "$pid_file"`
if kill - $PID > /dev/null > /dev/null
then
if ps wwwp $PID | grep -v mysqld_safe | grep -- mysqld > /dev/null
then
#mysqld 已经被启动了
echo "mysqld has been started!"
break
fi
fi
fi
echo "mysqld is still starting, waiting for it"
sleep
done
编辑mariadb启动脚本文件/home/work/env/mariadb/stop.sh
#!/bin/sh
dir=`dirname $(realpath $)`
cmd="$dir/bin/mysqladmin -S $dir/data/mysql.sock -uroot shutdown"
echo $cmd
$dir/bin/mysqladmin -S $dir/data/mysql.sock -uroot shutdown
编辑mariadb启动脚本文件/home/work/env/mariadb/connnect.sh
bin/mysql -uroot -Sdata/mysql.sock -A
10、将mariadb自带命令放入$PATH
[root@localhost ~]# echo "export PATH=$PATH:/home/work/env/mariadb/bin/" >>/etc/profile
[root@localhost ~]# source !$
11、启动mariadb:
chmod +x start.sh
sh start.sh
[root@localhost src]
# tar zxf php-5.6.25.tar.gz -C /home/work/env
[root@localhost src]# cd php-5.6.
[root@localhost src]# yum -y install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel
[root@localhost php-5.6.]# ./configure --prefix=/home/work/env/php --with-config-file-path=/home/work/env/php/etc --enable-fpm --with-fpm-user=work --with-fpm-group=work --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-pear --with-curl --enable-bcmath --enable-mbstring --enable-sockets --with-gd --with-libxml-dir=/home/work/env --with-gettext
错误:configure: error: xml2-config not found. Please check your libxml2 installation.
解决办法:yum -y install libxml2-devel
错误:configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/
解决办法:yum -y install libcurl-devel
错误:configure: error: jpeglib.h not found.
解决办法:yum -y install libjpeg-turbo-devel
错误:configure: error: png.h not found.
解决办法:yum -y install libpng-devel
错误:configure: error: freetype-config not found.
解决办法:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
错误:configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决办法:yum -y install libmcrypt-devel
如果yum没有这个libmcrypt-devel包,那就自己编译安装libmcrypt-2.5.8.tar.gz(去下载)
#tar -zxvf mcrypt-2.6..tar.gz
#cd mcrypt-2.6.
#LD_LIBRARY_PATH=/usr/local/lib ./configure
#make
#make install
4、安装php
[root@localhost php-5.6.25]
# make && make install
以上每一个步骤,如果没有完全执行正确,那么下一步是无法进行的,使用 echo $? 看结果是否为 “0” , 如果不是,就是没有执行正确。
5、修改配置文件
cp php.ini-production /home/work/env/php/etc/php.ini
vim /home/work/env/php/etc/php-fpm.conf
6、把如下内容写入该文件:
[global]
pid = /home/work/env/php/var/run/php-fpm.pid
error_log = /home/work/env/php/var/log/php-fpm.log
[www]
listen = /home/work/env/php/php-fcgi.sock #或 listen = 127.0.0.1:9000
user = work
group = work
listen.owner = work
listen.group = work
pm = dynamic
pm.max_children =
pm.start_servers =
pm.min_spare_servers =
pm.max_spare_servers =
pm.max_requests =
rlimit_files =
7、保存配置文件后,检验配置是否正确的方法为:/home/work/env/php/sbin/php-fpm -t
如果出现诸如 “test is successful” 字样,说明配置没有问题。
8、启动php-fpm
#!/bin/bash
#opt.sh
dir=`dirname $(realpath $)`
export LD_LIBRARY_PATH=$dir/lib
usage()
{
echo "usage: sh opt.sh start|stop|restart|count"
} OPT=$
if [ $# -ne ]; then
usage
exit
fi
case $OPT in
start|Start) echo "Starting..."
/home/work/env/php/sbin/php-fpm --prefix=/home/work/env/php -c /home/work/env/php/etc
echo "Done"
;;
stop|Stop) echo "Stopping..."
kill -INT `cat /home/work/env/php/var/run/php-fpm.pid`
echo "Done"
;;
restart|Restart) echo "Restarting..."
kill -USR2 `cat /home/work/env/php/var/run/php-fpm.pid`
echo "Done"
;;
count|Count) echo "Count..."
ps aux | grep -c php-fpm
echo "Done"
;;
*)usage
;;
esac
9、检测是否启动:
ps aux |grep php-fpm
看看是不是有很多个进程(大概20多个)。
三、安装nginx
1、下载nginx软件包:nginx-1.11.3.tar.gz
2、解压nginx
tar zxvf nginx-1.11.3.tar.gz
3、配置编译参数
cd nginx-1.11.
./configure \
--prefix=/home/work/env/nginx \
--with-http_realip_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-pcre
报错:./configure: error: the HTTP rewrite module requires the PCRE library.
解决办法:yum -y install pcre-devel
报错:./configure: error: the HTTP gzip module requires the zlib library.
解决办法:yum install -y zlib-devel
4、编译nginx
make
安装nginx
make install
8、更改nginx配置
首先把原来的配置文件清空: 建议mv备份
>
/home/work/env/nginx/conf/nginx
.conf
“>” 这个符号为重定向的意思,单独用它,可以把一个文本文档快速清空。
vim
/home/work/env/nginx/conf/nginx
.conf
user work work;
worker_processes ;
error_log /home/work/env/nginx/logs/nginx_error.log crit;
pid /home/work/env/nginx/logs/nginx.pid;
worker_rlimit_nofile ; events
{
use epoll;
worker_connections ;
} http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size ;
server_names_hash_max_size ;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout ;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size ;
client_header_buffer_size 1k;
large_client_header_buffers 4k;
request_pool_size 4k;
output_buffers 32k;
postpone_output ;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /home/work/env/nginx/client_body_temp;
proxy_temp_path /home/work/env/nginx/proxy_temp;
fastcgi_temp_path /home/work/env/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 8k;
gzip_comp_level ;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm application/xml; server
{
listen ;
server_name localhost;
index index.html index.htm index.php;
root /home/work/env/nginx/html;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
} } }
user work;
worker_processes ; error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ;
fastcgi_connect_timeout ;
fastcgi_send_timeout ;
fastcgi_read_timeout ;
fastcgi_buffer_size 128k;
fastcgi_buffers 128k;
tcp_nodelay on;
client_max_body_size 128m; gzip on;
gzip_min_length ;
gzip_buffers 16k;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css application/xml application/json;
gzip_comp_level ; #gzip on; server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; user work;
worker_processes ; error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ;
fastcgi_connect_timeout ;
fastcgi_send_timeout ;
fastcgi_read_timeout ;
fastcgi_buffer_size 128k;
fastcgi_buffers 128k;
tcp_nodelay on;
client_max_body_size 128m; gzip on;
gzip_min_length ;
gzip_buffers 16k;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css application/xml application/json;
gzip_comp_level ; #gzip on; server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen ;
# listen somename:;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#}
include hosts/*.conf;
}
9、保存配置后,先检验一下配置文件是否有错误存在:
/home/work/env/nginx/sbin/nginx
-t
nginx: configuration file /home/work/env/nginx/conf/nginx.conf test is successful
/nginx/conf/nginx
.conf
11、ps
aux |
grep
nginx
看是否有进程。
12、测试是否解析php文件
创建测试文件:
vim
/usr/local/nginx/html/2
.php
firewall-cmd --permanent --zone=public --add-port=80/tcp #添加80端口
firewall-cmd --reload #重新加载
firewall-cmd --list-port #查看是否添加成功
[root@localhost nginx]
# curl localhost/2.php
listen.owner = work
listen.group = work
这两行,再重启一下服务就能使用php了
原因是/home/work/env/php/php-fcgi.sock这个文件没有读权限
至此,最新版的LNMP环境源码编译安装完成了
docker容器里安装需要把端口映射到本地上:
登陆到172.18.1.34 (服务器ip)
机器上执行:
ssh -C -f -N -g -L 8080:127.0.0.1:80 172.18.1.144
目的把144的80端口映射到 34的8080上
/home/work/env
centos7 编译安装新版LNMP环境的更多相关文章
- Ubuntu 编译安装搭配LNMP 环境
这里用Nginx1.2.0+mysql5.6.33+php5.6.2搭配安装环境 ---------------------------------------------Nginx BEGIN--- ...
- 如何查看编译安装的lnmp环境各自的配置参数
安装好后如何查看mysql/apache/nginx/php安装参数 查看mysql编译参数: cat /usr/local/mysql/bin/mysqlbug | grep CONFIGURE ...
- centos7源码编译安装lamp/lnmp
centos7源码编译安装lamp/lnmp 进程:是包工头(相当于是个门,只管开门关门,不管门内的事儿) 线程:是各种工种(cpu调度的是线程) 进程 是一件事情, 线程 是 同一个时间范围内 同时 ...
- CentOS7编译安装Nginx-1.8.1和编译参数
CentOS7编译安装Nginx-1.8.1和编译参数 Web服务器Nginx LNMP是一组众所周知的Web网站服务器架构环境,即由Linux+Nginx+MySQL+PHP(MySQL有时也 ...
- CentOS7.0 安装JAVA周围环境
CentOS7.0 安装JAVA周围环境 安装JDK 1.配置JDK环境变量 把下载好的JDK(jdk-7u75-linux-x64.gz)文件上传到 Reg: /home/p2pweb/java/ ...
- centos7编译安装Python3所需要的库(模块)依赖
在centos中编译安装python3环境,第三方的库 实战的编辑环境: 1.VMware虚拟机 2.centos7 依赖包经过百度搜集以及之前安装Python3报错搜集(centos7反反复复安 ...
- CentOS7编译安装httpd-2.4.41 php7.3
CentOS7编译安装httpd-2.4.41 php7.3 安装参考环境: CentOS Linux release 7.5.1804 (Core) 一.安装依赖包 httpd安装的依赖包 # yu ...
- Centos7 编译安装PHP7
Centos7 编译安装PHP7 编译安装的方式可以让组件等设置更加合理,但需要你对PHP的代码及各种配置非常的熟悉,以下为大致的安装流程,大家可以参考 1.下载编译工具 yum groupinsta ...
- CentOS7编译安装php7.1配置教程详解
这篇文章主要介绍CentOS7编译安装php7.1的过程和配置详解,亲测 ,需要的朋友可以参考. 1.首先安装依赖包: yum install libxml2 libxml2-devel openss ...
随机推荐
- Windows使用Telnet连接Linux服务器初探(待实践)
在Windows下可以适用Telnet连接Linux服务器,但是前提是在Linux下需要安装Tlenet-Server.还要开启防火的23端口.搞定之后就可以用telnet IP进行连接. 但是,我发 ...
- MySQL 5.6.20-4 and Oracle Linux DTrace
https://blogs.oracle.com/wim/entry/mysql_5_6_20_4?utm_source=tuicool&utm_medium=referral By WimC ...
- bootstrap -- 学习之流动布局
Grid是什么? Grid 翻译成中文是格栅系统,不过还是不好理解,理解为一行12个格子可能更容易些.Grid可以把一行内容最多分成12个格子,而且可以根据需要来合并这12个格子中的其中某些格子.下面 ...
- tcp三次握手和syn 洪水攻击
1. 连接后,所有的 ack 为1才有效(连接后,ack 也一般都是1) 2. 建立连接3次握手, 如何确认对方收到了你发的包, seq 是自己发出去的,自己知道seq的值.所以怎么确认对方收到了自己 ...
- SolidEdge如何修改线型和线宽
选中一条直线,然后点击如下所示两个按钮,可以分别修改线型和线宽.
- 天津政府应急系统之GIS一张图(arcgis api for flex)解说(二)鹰眼模块
解说GIS功能模块实现之前,先大概说一下flexviewer的核心配置文件config.xml,系统额GIS功能widget菜单布局.系统的样式.地图资源等等都是在这里配置的,这里对flexviewe ...
- Python常用的模块
模块,模块就是封装了特殊功能的代码. 模块分为三种: 自定义模块 第三方模块 内置模块 自定义模块 1.自定义模块 2.模块的导入 python有大量的模块可以使用,再使用之前我们只需要导入模块就可以 ...
- 创建JDBC模板简化代码、JDBC应用的事务管理以及连接池的作用
一.创建JDBC模板简化代码 一个简单的查询.要做这么一大堆事情,并且还要处理异常,我们不防来梳理一下: 1.获取connection 2.获取statement 3.获取resultset 4 ...
- java开始到熟悉60
本次主题:多维数组 1,多维数组的初始话有三种:默认初始化.静态初始化.动态初始化. 这里只讲解静态初始化: 这里以二位数组为例,实际应用中,一维用得最多,二维次之,三维以及三维以上几乎很少使用,而且 ...
- Here is the reason why Fengguang turns from ipmitool to freeipmi
http://ipmitool.sourceforge.net/ Last updated Thu Apr 26 09:08:52 PDT 2007 Revision 1.21 · Home· Dow ...