环境
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