标签:
centos7+nginx1.8.1+php-7.0.4+mariadb-10.1.13
[root@oslinux ~]# wget http://nginx.org/download/nginx-1.8.1.tar.gz [root@oslinux ~]# wget http://cn2.php.net/distributions/php-7.0.4.tar.gz
[root@oslinux ~]# yum install wget gcc gcc-c++ autoconf automake bzip2 -y [root@oslinux ~]# yum install zlib zlib-devel pcre pcre-devel openssl openssl-devel -y [root@oslinux ~]# wget http://zlib.net/zlib-1.2.8.tar.gz [root@oslinux ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.bz2 [root@oslinux ~]# wget http://www.canonware.com/download/jemalloc/jemalloc-4.1.0.tar.bz2
[root@oslinux ~]# tar -xf pcre-8.38.tar.bz2 -C /usr/local/src/ [root@oslinux ~]# tar -xf zlib-1.2.8.tar.gz -C /usr/local/src/ [root@oslinux ~]# tar -xf nginx-1.8.1.tar.gz -C /usr/local/src/ [root@oslinux ~]# tar -xf jemalloc-4.1.0.tar.bz2 -C /usr/local/src/ [root@oslinux ~]# tar -xf jemalloc-4.1.0.tar.bz2 -C /usr/local/src/ [root@oslinux ~]# cd /usr/local/src/jemalloc-4.1.0/ [root@oslinux jemalloc-4.1.0]# ./configure && make && make install [root@oslinux jemalloc-4.1.0]# echo ‘/usr/local/lib‘ > /etc/ld.so.conf.d/local.conf [root@oslinux jemalloc-4.1.0]# ldconfig [root@oslinux src]# cd nginx-1.8.1/ [root@oslinux nginx-1.8.1]# useradd -u 8001 -s /sbin/nologin -M nginx [root@oslinux 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 [root@oslinux nginx-1.8.1]# make -j 4 && make install [root@oslinux ~]# /usr/local/nginx/sbin/nginx
[root@oslinux ~]# useradd -u 8003 -s /sbin/nologin mysql [root@oslinux ~]# mkdir -p /data/mysql [root@oslinux ~]# chown -R mysql.mysql /data/mysql [root@oslinux ~]# yum -y install gcc gcc-c++ ncurses ncurses-devel wget bzip2 openssl openssl-devel cmake bison [root@oslinux ~]# wget http://mariadb.nethub.com.hk//mariadb-10.1.13/source/mariadb-10.1.13.tar.gz [root@oslinux ~]# wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz 一定要1.59的,其他没有用 [root@oslinux ~]# mv boost_1_59_0.tar.gz /usr/local/boost/
安装cmake
[root@oslinux ~]# wget https://cmake.org/files/v3.5/cmake-3.5.1.tar.gz [root@oslinux ~]# tar -xf cmake-3.5.1.tar.gz ; cd cmake-3.5.1 [root@oslinux cmake-3.5.1]# ./bootstrap && make -j 4 && make install [root@oslinux cmake-3.5.1]# cmake --version cmake version 3.5.1 CMake suite maintained and supported by Kitware (kitware.com/cmake).
[root@oslinux ~]# wget http://zlib.net/zlib-1.2.8.tar.gz [root@oslinux ~]# tar -xf zlib-1.2.8.tar.gz [root@oslinux ~]# cd zlib-1.2.8 [root@oslinux zlib-1.2.8]# ./configure --prefix=/usr/local/zlib [root@oslinux zlib-1.2.8]# make && make install 没有指定路径则继续下面的 [root@oslinux zlib-1.2.8]# echo "/usr/local/lib/" >>/etc/ld.so.conf [root@oslinux zlib-1.2.8]# ldconfig
编译安装MariaDB
[root@oslinux mariadb-10.1.13]# mkdir /run/mysql [root@oslinux ~]# chown -R mysql:mysql /run/mysql/ [root@oslinux mariadb-10.1.13]# tar -xf mariadb-10.1.13.tar.gz [root@oslinux 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 [root@oslinux mariadb-10.1.13]# make -j 4 [root@oslinux mariadb-10.1.13]# make install
初始化mariadb
[root@oslinux ~]# chown -R mysql:mysql /usr/local/mysql [root@oslinux ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql [root@oslinux ~]# mv /etc/my.cnf /etc/my.cnf.bk [root@oslinux ~]# cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf [root@oslinux ~]# sed -i ‘/^\[mysqld\]/adatadir = /data/mysql‘ /etc/my.cnf [root@oslinux ~]# sed -i ‘/^\[mysqld\]/abasedir = /usr/local/mysql‘ /etc/my.cnf [root@oslinux ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@oslinux ~]# chmod +x !$ chmod +x /etc/init.d/mysqld [root@oslinux ~]# chkconfig mysqld on [root@oslinux ~]# echo "PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile [root@oslinux ~]# source !$ source /etc/profile [root@oslinux ~]# systemctl start mysqld.service [root@oslinux ~]# lsof -i :3306 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME mysqld 27982 mysql 21u IPv6 39993 0t0 TCP *:mysql (LISTEN)
设置root密码
[root@oslinux ~]# 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 | +------+-----------+
[root@oslinux ~]# yum install epel* -y [root@oslinux ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel [root@oslinux ~]# tar -xf php-7.0.4.tar.gz -C /usr/local/src/ [root@oslinux ~]# cd /usr/local/src/php-7.0.4/ [root@oslinux 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 [root@oslinux php-7.0.4]# make -j 4 && make install
查看生成的模块文件
[root@oslinux ~]# 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配置文件
[root@oslinux ~]# cp /usr/local/src/php-7.0.4/php.ini-production /usr/local/php7/etc/php.ini [root@oslinux ~]# cp /usr/local/src/php-7.0.4/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@oslinux ~]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf [root@oslinux ~]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
添加php的环境变量
[root@oslinux ~]# vim /etc/profile PATH=/usr/local/mysql/bin:/usr/local/php7/bin:/usr/local/php7/sbin:$PATH [root@oslinux ~]# source !$ source /etc/profile
创建php数据库文件的存放路径以及相关安全配置
[root@oslinux ~]# mkdir -p /var/log/php-fpm/ && mkdir -p /run/php-fpm && cd /run/ && chown -R nginx:nginx php-fpm [root@oslinux run]# mkdir -p /var/lib/php/session [root@oslinux run]# chown -R nginx:nginx /var/lib/php
设置PHP开机启动以及测试配置文件是否正确
[root@oslinux ~]# chmod +x /etc/init.d/php-fpm [root@oslinux ~]# chkconfig php-fpm on [root@oslinux ~]# php-fpm -t [31-Mar-2016 18:39:40] NOTICE: configuration file /usr/local/php7/etc/php-fpm.conf test is successful [root@oslinux ~]# service php-fpm start Starting php-fpm done [root@oslinux ~]# 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开机启动
[root@oslinux ~]# ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx [root@oslinux ~]# 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 [root@oslinux ~]# chmod +x !$ [root@oslinux 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修改配置
[root@oslinux ~]# mkdir /website [root@oslinux ~]# chown -R nginx:nginx /website/ [root@oslinux ~]# 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
[root@oslinux ~]# 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
标签:
原文地址:http://www.cnblogs.com/ylion/p/5335557.html