博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux上搭建nginx+php+mysql环境详细讲解
阅读量:4576 次
发布时间:2019-06-08

本文共 9058 字,大约阅读时间需要 30 分钟。

1、mysql安装

1 #安装编译环境 2 yum install -y gcc gcc-c++ gcc-devel g++ g++-devel; 3 yum install -y wget 4 yum install -y tar 5  6 #创建mysql用户组及用户 7 groupadd -f mysql 8 useradd -g mysql mysql 9 10 11 #编译mysql12 #安装依赖13 yum install -y ncurses ncurses-devel14 yum install -y cmake15 16 #解压mysql包17 tar -xf mysql-5.6.35.tar.gz18 cd  mysql-5.6.35.tar.gz19 20 #创建mysql的data数据目录21 mkdir -p /data/mysql/data22 chown -R mysql:mysql /data/mysql23 24 #编译,主要注意几个目录以及端口25 cmake -DCMAKE_INSTALL_PREFIX=/data/mysql  -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/tmp/mysql.sock  -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1  -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql/data -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DSYSCONFDIR=/data/mysql -DEXTRA_CHARSETS=all -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/data/mysql/boost26 27 #安装    28 make -j 4 && make install29 30 31 #配置数据库32 cd  /data/mysql33 34 #初始化数据库35 ./scripts/mysql_install_db --basedir="/data/mysql" --datadir="/data/mysql/data"36 37 chown -R mysql:mysql 、/data/mysql/data/38 39 #复制服务到init.d目录40 cp /data/mysql/support-files/mysql.server  /etc/init.d/mysql41     42 #将mysql服务加入chkconfig管理列表 ,然后就可以用service进行操作,如果要开机自启再执行 chkconfig mysql on 43 44 chkconfig /etc/init.d/mysql45 46 #软链接(快捷方式),方便直接使用mysql客户端和备份命令47 ln -s /data/mysql/bin/mysql  /bin/mysql48 ln -s /data/mysql/bin/mysqldump  /bin/mysqldump49 50 #最后检查mysql目录下 my.cnf  配置文件,无误后启动mysql服务51 service mysql start52 53 #关闭命令54 service mysql stop55 #重启命令56 service mysql restart 57 58 #客户端第一次登陆数据库,没有密码的59 mysql -uroot -p

mysql配置参考,有些参数视具体而定

# For advice on how to change settings please see# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the# *** default location during install, and will be replaced if you# *** upgrade to a newer version of MySQL.[client]port=3306socket =/tmp/mysql.sock[mysqld]# Remove leading # and set to the amount of RAM for the most important data# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.# innodb_buffer_pool_size = 128M# Remove leading # to turn on a very important data integrity option: logging# changes to the binary log between backups.# log_bin# These are commonly set, remove the # and set as required.basedir =/data/mysqldatadir =/data/mysql/dataport =3306socket =/tmp/mysql.sockkey_buffer_size =  128Mopen_files_limit = 10240sort_buffer_size = 8Mjoin_buffer_size = 4Mread_buffer_size = 16Mread_rnd_buffer_size=16Mmyisam_sort_buffer_size = 64Mthread_cache_size = 8query_cache_size = 32M query_cache_limit = 16M #允许临时存放在查询缓存区里的查询结果的最大长度(默认设置是1M)max_connections=4000max_allowed_packet = 1Gdefault_storage_engine = InnoDB #默认引擎innodbbulk_insert_buffer_size = 200M#thread_stack = 512K #线程使用的堆大小. 此容量的内存在每次连接时被预留thread_concurrency=16 #CPU的2倍,用于多核CPU上innodb_buffer_pool_size = 1Ginnodb_log_buffer_size = 16Minnodb_additional_mem_pool_size=32Minnodb_flush_log_at_trx_commit=2 # 1:(默认值) 每一次事务提交或事务外的指令都需要把日志写入硬盘 2:把日志写入系统缓存 0:延迟写入#innodb_flush_method=3 # 1) Default – 使用fsync。 2) O_SYNC 以sync模式打开文件,通常比较慢。 3) O_DIRECT,在Linux上使用Direct IO。innodb_thread_concurrency=16innodb_file_io_threads=8innodb_file_per_table = 1# innodb_strict_mode=1 #建议加上innodb_io_capacity = 500relay_log_recovery=1tmp_table_size=268435456max_heap_table_size=268435456slow_query_log=ONlong_query_time=60 #添加慢查询slow_query_log_file=slowquery.loglog_bin=mysql-binbinlog_format=mixedexpire_logs_days=5max_binlog_size=512M #日志文件太大读写效率降低#从配置slave-skip-errors=1062,1064relay_log=mysql-relay-binlog_slave_updates=1replicate-ignore-db=mysql,performance_schema,information_schema# Remove leading # to set options mainly useful for reporting servers.# The server defaults are faster for transactions and fast SELECTs.# Adjust sizes as needed, experiment to find the optimal values.# join_buffer_size = 128M# sort_buffer_size = 2M# read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [mysqldump]quickmax_allowed_packet = 1G[mysql]no-auto-rehash[myisamchk]key_buffer_size = 400Msort_buffer_size = 256Mread_buffer = 2Mwrite_buffer = 2M[mysqlhotcopy]interactive-timeout

 

2、php安装,需要自己下载libmcrypt-2.5.8.tar.gz 依赖

1 #安装依赖 2 yum install -y libxml2-devel 3 yum install -y bzip2-devel 4 yum install -y libcurl-devel 5 yum install -y libjpeg-devel libpng-devel freetype-devel 6      7 #手动安装libmcrypt依赖 8 tar -xf libmcrypt-2.5.8.tar.gz 9 cd libmcrypt-2.5.810 11 #配置 自定义安装目录12 ./configure --prefix=/usr/local/libmcrypt13 #开始安装14 make -j 4 && make install15 cd ../16 17 #安装php18 tar -xf php-5.6.29.tar.gz19 cd php-5.6.2920 21 #配置信息22 ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm  --with-mcrypt=/usr/local/libmcrypt --with-zlib --enable-mbstring --with-openssl --with-mysql --with-mysqli --with-mysql-sock --with-gd --enable-gd-native-ttf --with-jpeg-dir=/usr/lib64 --with-freetype-dir=/usr/lib64 --with-png-dir=/usr/lib64 --enable-pdo --with-pdo-mysql --with-gettext --with-curl --enable-sockets --enable-bcmath --enable-xml --with-bz2 --enable-zip --enable-pcntl --enable-sysvmsg --enable-mysqlnd=mysqlnd --enable-calendar --enable-mbstring --enable-maintainer-zts23 #开始安装    24 make -j 4 && make install25 cd ../

3、安装nginx,需要手动下载pcre-8.39.tar.gz 和zlib-1.2.10.tar.gz

1 #我这里是提前把pcre、zlib以及nginx的包下载到了/data/install目录 2 #实际安装中的目录根据具体的而定 3  4 #解压依赖包 5 tar -xf pcre-8.39.tar.gz 6 tar -xf zlib-1.2.10.tar.gz 7  8 tar -xf nginx-1.9.15.tar.gz 9 cd nginx-1.9.1510 yum install -y openssl openssl-devel11 12 #配置13 ./configure --sbin-path=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/data/install/pcre-8.39 --with-zlib=/data/install/zlib-1.2.1014 15 #开始安装16 make -j 4 && make install

4、配置nginx

(1)创建根目录和日志目录:

  mkdir  /data/wwwroot  

  mkdir -p /data/logs/nginx

(2)修改配置文件

  

user  www;worker_processes  8;worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;error_log   /data/logs/nginx/error.log;pid        nginx.pid;events {    worker_connections 65535;    multi_accept on;    use epoll;}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  /data/logs/nginx/access.log  main;    sendfile        on;    #tcp_nopush     on;    keepalive_timeout  120;	add_header Access-Control-Allow-Origin "*";	server_names_hash_bucket_size 128;    gzip  on;		server{		listen 80;		server_name localhost;		root /data/wwwroot;		location / {			index index.html index.htm index.php;		}		location ~ \.php {			root /data/wwwroot;			fastcgi_pass  127.0.0.1:9000;			fastcgi_index index.php;			fastcgi_param SCRIPT_FILENAME /usr/local/php$fastcgi_script_name;			include    fastcgi_params;			set $path_info "";			set $real_script_name $fastcgi_script_name;			if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {				 set $real_script_name $1;				 set $path_info $2;			}			fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;			fastcgi_param SCRIPT_NAME $real_script_name;			fastcgi_param PATH_INFO $path_info;	   }	}    include 'conf/*.conf';}

(3)用www用户启动nginx

     创建www用户:groupadd www

     创建www用户组:useradd -g www www

     启动nginx/usr/local/nginx/nginx

   关闭nginx: /usr/local/nginx/nginx -s stop

  如果是在虚拟机安装可能还需要关闭防火墙 (外部访问 虚拟机要先关闭防火墙chkconfig iptables off 或者 service iptables stop 或者 iptables -F)

5、phpnginx关联

  开启php-fpm配置文件:

  cd  /usr/local/php/etc

  cp  php-fpm.conf.default  ./php-fpm.conf

  开启php-fpm:

  /usr/local/php/sbin/php-fpm

 

6、常见问题:

(1)启动mysql服务 ,提示my.cnf被忽略?

   解决方法:修改my.cnf的权限  chmod 644 /data/mysql1/my.cnf

(2)终端mysql进不去?

  解决办法:mysql1 -h127.0.0.1 -uroot -p  主机加上127.0.0.1

(3)外部连不上虚拟机mysql

  解决办法:iptables -F

  参考网址:

(4)如何开机mysql服务自动开启?

  解决办法:上传启动控制脚本到/etc/init.d (一般安装后里面会自动生成,不需上传),mysql添加到系统服务,然后设置自动开启。

  chkconfig --add /etc/init.d/mysql  

  chkconfig  mysql  on

  详细内容可参考网址:

(5)如何设置nginx开机自启动?

   (1) 上传启动控制脚本nginx /etc/init.d

  (2) 设置权限:chmod 755 /etc/init.d/nginx

  (3) 添加到系统服务:chkconfig --add /etc/init.d/nginx

  (4) 设置开机启动:chkconfig  ginx  on

  (5) 查看是否设置成功:chkconfig --list | grep nginx   (2-5选项为on)

  参考网址:

(6)如何设置php-fpm开机自启动?

  (1)上传启动控制脚本php-fpm/etc/init.d

  (2)设置权限:chmod 755 /etc/init.d/php-fpm

  (3)添加到系统服务:chkconfig --add /etc/init.d/php-fpm

  (4)设置开机启动:chkconfig  ginx  on

  (5)查看是否设置成功:chkconfig --list | grep php-fpm   (2-5选项为on)

  参考网址:

(7)替换了配置文件mysql也无法启动?

     解决办法:如果替换了配置文件,启动还是报这个错误:mysqld_safe error: log-error set to '/var/log/mariadb/mariadb.log', however file don't exists. Create writable for user 'mysql'.ERROR! The server quit without updating PID file (/data/mysql/data/bogon.pid).

  这时可以去/etc目录下删掉默认的my.cnf ,然后再次启动即可

最后附上完整的一键安装脚本,以及所需安装包,配置文件、启动控制脚本

  链接:https://pan.baidu.com/s/1XkxgW9fRINqg_Zi3W27OUg 密码:ddan 

转载于:https://www.cnblogs.com/myIvan/p/9533474.html

你可能感兴趣的文章
RDLC报表钻取空白页问题
查看>>
多路电梯调度的思想
查看>>
jQuery-对Select的操作
查看>>
过滤器、监听器、拦截器的区别
查看>>
为什么要进行需求分析?通常对软件系统有哪些需求?
查看>>
一些模板
查看>>
jquery和dom元素相互转换
查看>>
放大的X--HDOJ-201307292012
查看>>
题目831-签到-nyoj-20140818
查看>>
百词斩-斩家秘籍
查看>>
Mysql主从配置,实现读写分离
查看>>
完整版本的停车场管理系统源代码带服务端+手机android客户端
查看>>
排序精讲
查看>>
【bzoj3172】 Tjoi2013—单词
查看>>
【uoj2】 NOI2014—起床困难综合症
查看>>
js return的用法
查看>>
子节点填充父元素除去一固定高度后的剩余高度
查看>>
[原]IOS 后台发送邮件
查看>>
(转)JAVA Calendar详解
查看>>
转: 编码,charset,乱码,unicode,utf-8与net简单释义
查看>>