Centos7---LNMP

环境

centos7+nginx1.8.1+php-7.0.4+mariadb-10.1.13

下载相关包 

[[email protected] ~]# wget http://nginx.org/download/nginx-1.8.1.tar.gz
[[email protected] ~]# wget http://cn2.php.net/distributions/php-7.0.4.tar.gz

安装nginx

  准备

[[email protected] ~]# yum install wget gcc gcc-c++ autoconf automake bzip2  -y
[[email protected] ~]# yum install zlib zlib-devel pcre pcre-devel openssl openssl-devel -y
[[email protected] ~]# wget http://zlib.net/zlib-1.2.8.tar.gz
[[email protected] ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.bz2
[[email protected] ~]# wget http://www.canonware.com/download/jemalloc/jemalloc-4.1.0.tar.bz2

 编译安装

[[email protected] ~]# tar -xf pcre-8.38.tar.bz2 -C /usr/local/src/
[[email protected] ~]# tar -xf zlib-1.2.8.tar.gz -C  /usr/local/src/
[[email protected] ~]# tar -xf nginx-1.8.1.tar.gz -C /usr/local/src/
[[email protected] ~]# tar -xf jemalloc-4.1.0.tar.bz2 -C /usr/local/src/
[[email protected] ~]# tar -xf jemalloc-4.1.0.tar.bz2 -C /usr/local/src/
[[email protected] ~]# cd /usr/local/src/jemalloc-4.1.0/
[[email protected] jemalloc-4.1.0]# ./configure && make && make install
[[email protected] jemalloc-4.1.0]# echo ‘/usr/local/lib‘ > /etc/ld.so.conf.d/local.conf
[[email protected] jemalloc-4.1.0]# ldconfig
[[email protected] src]# cd nginx-1.8.1/
[[email protected] nginx-1.8.1]# useradd -u 8001 -s /sbin/nologin -M nginx
[[email protected] nginx-1.8.1]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_gzip_static_module --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.38  --pid-path=/usr/local/nginx/nginx.pid  --with-ld-opt="-ljemalloc" --with-http_flv_module --user=nginx --group=nginx
[[email protected] nginx-1.8.1]# make -j 4 && make install
[[email protected] ~]# /usr/local/nginx/sbin/nginx 

安装MariaDB

  准备工作

[[email protected] ~]# useradd -u 8003 -s /sbin/nologin mysql
[[email protected] ~]# mkdir -p /data/mysql
[[email protected] ~]# chown -R mysql.mysql /data/mysql
[[email protected] ~]# yum -y install gcc gcc-c++ ncurses ncurses-devel wget bzip2 openssl openssl-devel cmake bison
[[email protected] ~]# wget http://mariadb.nethub.com.hk//mariadb-10.1.13/source/mariadb-10.1.13.tar.gz
[[email protected] ~]# wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz    一定要1.59的,其他没有用
[[email protected] ~]# mv boost_1_59_0.tar.gz /usr/local/boost/

 安装cmake

[[email protected] ~]# wget https://cmake.org/files/v3.5/cmake-3.5.1.tar.gz
[[email protected] ~]# tar -xf cmake-3.5.1.tar.gz ; cd cmake-3.5.1
[[email protected] cmake-3.5.1]# ./bootstrap && make -j 4 && make install
[[email protected] cmake-3.5.1]# cmake --version
cmake version 3.5.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

 安装zlib

[[email protected] ~]# wget http://zlib.net/zlib-1.2.8.tar.gz
[[email protected] ~]# tar -xf zlib-1.2.8.tar.gz
[[email protected] ~]# cd zlib-1.2.8
[[email protected] zlib-1.2.8]# ./configure --prefix=/usr/local/zlib
[[email protected] zlib-1.2.8]# make && make install
没有指定路径则继续下面的
[[email protected] zlib-1.2.8]# echo "/usr/local/lib/" >>/etc/ld.so.conf
[[email protected] zlib-1.2.8]# ldconfig

  编译安装MariaDB

[[email protected] mariadb-10.1.13]# mkdir /run/mysql
[[email protected] ~]# chown -R mysql:mysql /run/mysql/
[[email protected] mariadb-10.1.13]# tar -xf mariadb-10.1.13.tar.gz
[[email protected] mariadb-10.1.13]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql > -DMYSQL_UNIX_ADDR=/run/mysql/mysql.sock > -DMYSQL_DATADIR=/data/mysql > -DSYSCONFDIR=/etc > -DMYSQL_TCP_PORT=3306 > -DWITH_INNOBASE_STORAGE_ENGINE=1 > -DWITH_PARTITION_STORAGE_ENGINE=1 > -DWITH_BLACKHOLE_STORAGE_ENGINE=1 > -DWITH_MYISAM_STORAGE_ENGINE=1 > -DENABLED_LOCAL_INFILE=1 > -DWITH_DEBUG=0 > -DDEFAULT_CHARSET=utf8 > -DDEFAULT_COLLATION=utf8_general_ci > -DWITH_EXTRA_CHARSETS=all > -DMYSQL_MAINTAINER_MODE=0 > -DWITH_EDITLINE=bundled > -DWITH_SSL:STRING=bundled > -DWITH_ZLIB:STRING=bundled > -DMYSQL_USER=mysql > -DWITH_SAFEMALLOC=OFF > -DZLIB_LIBRARY:FILEPATH=/usr/local/zlib/lib/ > -DZLIB_INCLUDE_DIR:PATH=/usr/local/zlib/include/ > -DCMAKE_EXE_LINKER_FLAGS="-ljemalloc" > -DENABLE_DOWNLOADS=1 > -DWITH_BOOST=/usr/local/boost
[[email protected] mariadb-10.1.13]# make -j 4
[[email protected] mariadb-10.1.13]# make install

  初始化mariadb

[[email protected] ~]# chown -R mysql:mysql /usr/local/mysql
[[email protected] ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
[[email protected] ~]# mv /etc/my.cnf /etc/my.cnf.bk
[[email protected] ~]# cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
[[email protected] ~]# sed -i ‘/^\[mysqld\]/adatadir = /data/mysql‘ /etc/my.cnf
[[email protected] ~]# sed -i ‘/^\[mysqld\]/abasedir = /usr/local/mysql‘ /etc/my.cnf
[[email protected] ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[[email protected] ~]# chmod +x !$
chmod +x /etc/init.d/mysqld
[[email protected] ~]# chkconfig mysqld on
[[email protected] ~]# echo "PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
[[email protected] ~]# source !$
source /etc/profile
[[email protected] ~]# systemctl start mysqld.service
[[email protected] ~]# lsof -i :3306
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  27982 mysql   21u  IPv6  39993      0t0  TCP *:mysql (LISTEN)

  设置root密码

[[email protected] ~]# mysql
MariaDB [(none)]> SET PASSWORD FOR ‘root‘@‘localhost‘ = PASSWORD(‘newpass‘);
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> drop database test;
MariaDB [(none)]> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
|      | localhost |
| root | localhost |
|      | oslinux   |
| root | oslinux   |
+------+-----------+
MariaDB [(none)]> delete from mysql.user where User=‘‘;
MariaDB [(none)]> delete from mysql.user where host in (‘127.0.0.1‘,‘::1‘,‘oslinux‘);
MariaDB [(none)]> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | localhost |
+------+-----------+

安装php

[[email protected] ~]# yum install epel* -y
[[email protected] ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel
[[email protected] ~]# tar -xf php-7.0.4.tar.gz -C /usr/local/src/
[[email protected] ~]# cd /usr/local/src/php-7.0.4/
[[email protected] php-7.0.4]# ./configure > --prefix=/usr/local/php7 > --exec-prefix=/usr/local/php7 > --bindir=/usr/local/php7/bin > --sbindir=/usr/local/php7/sbin > --includedir=/usr/local/php7/include > --libdir=/usr/local/php7/lib/php > --mandir=/usr/local/php7/php/man > --with-config-file-path=/usr/local/php7/etc > --with-mysql-sock=/run/mysql/mysql.sock > --with-mcrypt=/usr/include > --with-mhash > --with-openssl > --with-mysqli=shared,mysqlnd > --with-pdo-mysql=shared,mysqlnd > --with-gd > --with-iconv > --with-zlib > --enable-zip > --enable-inline-optimization > --disable-debug > --disable-rpath > --enable-shared > --enable-xml > --enable-bcmath > --enable-shmop > --enable-sysvsem > --enable-mbregex > --enable-mbstring > --enable-ftp > --enable-gd-native-ttf > --enable-pcntl > --enable-sockets > --with-xmlrpc > --enable-soap > --without-pear > --with-gettext > --enable-session > --with-curl > --with-jpeg-dir > --with-freetype-dir > --enable-opcache > --enable-fpm > --with-fpm-user=nginx > --with-fpm-group=nginx > --without-gdbm > --disable-fileinfo
[[email protected] php-7.0.4]# make -j 4 && make install

  查看生成的模块文件

[[email protected] ~]# ls /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/
mysqli.a  mysqli.so  opcache.a  opcache.so  pdo_mysql.a  pdo_mysql.so

  生成php配置文件

[[email protected] ~]# cp /usr/local/src/php-7.0.4/php.ini-production /usr/local/php7/etc/php.ini
[[email protected] ~]# cp /usr/local/src/php-7.0.4/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[[email protected] ~]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[[email protected] ~]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

  添加php的环境变量

[[email protected] ~]# vim /etc/profile
PATH=/usr/local/mysql/bin:/usr/local/php7/bin:/usr/local/php7/sbin:$PATH
[[email protected] ~]# source !$
source /etc/profile

  创建php数据库文件的存放路径以及相关安全配置

[[email protected] ~]# mkdir -p /var/log/php-fpm/ && mkdir -p /run/php-fpm && cd /run/ && chown -R nginx:nginx php-fpm
[[email protected] run]# mkdir -p /var/lib/php/session
[[email protected] run]# chown -R nginx:nginx /var/lib/php

  设置PHP开机启动以及测试配置文件是否正确

[[email protected] ~]# chmod +x /etc/init.d/php-fpm
[[email protected] ~]# chkconfig php-fpm on
[[email protected] ~]# php-fpm -t
[31-Mar-2016 18:39:40] NOTICE: configuration file /usr/local/php7/etc/php-fpm.conf test is successful

[[email protected] ~]# service php-fpm start
Starting php-fpm  done
[[email protected] ~]# lsof -i :9000
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
php-fpm 48724  root    7u  IPv4 127014      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 48725 nginx    0u  IPv4 127014      0t0  TCP localhost:cslistener (LISTEN)
php-fpm 48726 nginx    0u  IPv4 127014      0t0  TCP localhost:cslistener (LISTEN)

配置LNMP

  配置nginx

    nginx开机启动

[[email protected] ~]# ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
[[email protected] ~]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
[[email protected] ~]# chmod +x !$
[[email protected] init.d]# lsof -i :80
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   49220  root    6u  IPv4 131297      0t0  TCP *:http (LISTEN)
nginx   49221 nginx    6u  IPv4 131297      0t0  TCP *:http (LISTEN)

  nginx.conf修改配置

[[email protected] ~]# mkdir /website
[[email protected] ~]# chown -R nginx:nginx /website/
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf
user  nginx nginx;
worker_processes  auto;
error_log  logs/error.log  error;
pid        /run/nginx.pid;

events {
    use epoll;
    worker_connections  65535;
}

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"‘;
    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay    on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
gzip  on;
    gzip_min_length 1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
    gzip_vary on;
    gzip_proxied   expired no-cache no-store private auth;
    gzip_disable   "MSIE [1-6]\.";
    server {
        listen       80;
        server_name  oslinux.cn;

        charset UTF-8;
        location / {
            root   /website;
            index  index.html index.htm index.php;
        }

        location /NginxStatus {
            stub_status     on;   #启用StubStatus的工作状态统计功能*/
            access_log      logs/NginxStatus.log;   #/*StubStatus模块的访问日志文件*/
            auth_basic      "NginxStatus";    #/*StubStatus的一种认证机制*/
        }
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 location ~ \.php$ {
            root           /website;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /website$fastcgi_script_name;
            include        fastcgi_params;
        }
 }
}

  配置php

    配置php.ini

[[email protected] ~]# vim /usr/local/php7/etc/php.ini
expose_php = Off
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/"
zend_extension=opcache.so
extension=mysqli.so
extension=pdo_mysql.so
date.timezone = Asia/Shanghai
[opcache]
opcache.enable=1
short_open_tag = On

  配置MariaDB

[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql
port            = 3306
socket          = /run/mysql/mysql.sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU‘s*2 for thread_concurrency
thread_concurrency = 8
lower_case_table_names = 1
skip-name-resolve
max_connections = 1000
max_connect_errors = 200
wait_timeout = 600
interactive_timeout = 60
innodb_buffer_pool_size = 512M
innodb_file_per_table = 1
#innodb_data_file_path = ibdata1:1G:autoextend
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_log_buffer_size = 3M

 

时间: 2024-10-14 14:52:06

Centos7---LNMP的相关文章

Linux平台(Centos7)-lnmp一键式部署mysql,nginx,php,php-fpm服务

Linux平台(Centos7)-lnmp一键式部署mysql,nginx,php,php-fpm服务 1. 部署方式1:手动部署. 6 1.1. 配置防火墙. 6 1.2. 关闭firewall 6 1.3. 安装iptables防火墙. 6 1.4. 安装Apache 7 1.5. 安装MariaDB 9 1.5.1. 安装MariaDB 9 1.5.2. 启动服务. 10 1.5.3. 设置开机启动. 10 1.5.4. 为root账户设置密码. 11 1.5.5. 重启MariaDB 1

centOS7 LNMP+phpmyadmin环境搭建 第三篇phpmyadmin安装

这篇文章主要介绍了CentOS7 LNMP+phpmyadmin环境搭建,第三篇phpmyadmin安装,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 之前我们已经安装了lnmp的环境,现在让我们来安装phpmyadmin. 跟前一样,yum默认的库里是没有phpmyadmin的,我们需要从epel库里进行安装,之前已经安装过epel的朋友就可以直接下载rpm包了. 1 2 yum install epel-release rpm -ivh http://rpms.famillecollet

VM虚拟机 Centos7 lnmp环境 配置域名问题 windows浏览器访问的问题

CentOS7  ip地址为 192.168.0.155 搭有 LNMP集成环境 执行 lnmp vhost add 配置服务器 指定目录的域名 mark.com 这时windows 机器的 浏览器想要访问 mark.com 需要在 C:\Windows\System32\drivers\etc 下的hosts 文件需要加一行 192.168.0.155 mark.com

CentOS7 LNMP+phpmyadmin环境搭建(二、LNMP环境搭建)

上一篇博客我们在虚拟机上安装了centos7,接下来,就开始安装lnmp环境吧. 还是跟之前一样,进入命令行后,先使用su命令切换到root权限. 首先配置防火墙 CentOS 7.0默认使用的是firewall作为防火墙 1.关闭firewall: systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall开机启动 2.关闭SELINUX: vi /etc/selinu

CentOS7+LNMP 安装Zabbix3.0 安装笔记

转载 自 http://blog.csdn.net/asionliang/article/details/51733833 从网上看过N篇教程,小白编译各种出错,无奈选择LNMP一键安装包,解决所有问题.感谢lnmp.org的lamp一体包,现已成功安装,做个笔记,以便后查. 参考: http://www.cnblogs.com/swordxia/p/5591712.html 1.配置防火墙 [root~]# firewall-cmd --permanent --zone=public --ad

CENTOS7+LNMP+zabbix3.2.6安装配置

1.安装MySQL 1.1.安装MySQL rpm -ivh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm yum -y install mysql-server 1.2.修改MySQL的配置文件 vim /etc/my.cnf [mysqld] default-storage-engine = innodb innodb_file_per_table collation-server = utf8_gener

zabbix3.0基于centos7 lnmp环境

一:zabbix概述 zabbix 由2部分构成,zabbix server 与可选组件zabbix agent. zabbix server 可以通过SNMP,zabbix agent ,ping,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux, Solaris, HP-UX, AIX, Free BSD, Open BSD, OS X等平台之上. zabbix agent 需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CP

CentOS7 LNMP+phpmyadmin环境搭建(三、安装phpmyadmin)

之前我们已经安装了lnmp的环境,现在让我们来安装phpmyadmin. 跟前一样,yum默认的库里是没有phpmyadmin的,我们需要从epel库里进行安装,之前已经安装过epel的朋友就可以直接下载rpm包了. yum install epel-release rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm 下载完成后安装phpmyadmin yum install --enablerepo=remi

centos7 LNMP 配置备注

1.mysql 已改名为 mariadb 2.service 升级为 systemctl 3.mysql 设置初始密码  mysql_secure_installation 4.nginx配置 server{ listen 80; server_name weiqing.isousou.net; root /data/weiqing; index index.html index.htm index.php; location ~ \.php/?.* { fastcgi_pass   127.0

404 not found ------ nginx ----- lnmp/lnmpa centOS7

http://www.codes51.com/itwd/4394286.html (nginx)Centos7 Lnmp 安装好后 能访问phpinfo没问题,但是访问项目却404,尝试了很多方法都未能解决 关于网友提出的" (nginx)Centos7 Lnmp 安装好后 能访问phpinfo没问题,但是访问项目却404,尝试了很多方法都未能解决"问题疑问,本网通过在网上对" (nginx)Centos7 Lnmp 安装好后 能访问phpinfo没问题,但是访问项目却404