本节会安装Nginx,Mysql.
Nginx是一款轻量级Web服务器
、也是一款反向代理服务器
.php
做用:
(1)、能够直接支持Rails和PHP的程序
(2)、可做为HTTP反向代理服务器
(3)、做为负载均衡服务器
(4)、做为邮件代理服务器
(5)、帮助实现前端动静分离html
特色:
高稳定、高性能、资源占用少、支持热部署前端
安装环境:centOS 6.8 64位
安装版本:1.0.2mysql
安装步骤:nginx
yum install gcc
,可输入 gcc -v
查询系统是否自带安装)yum install pcre-devel
)yum install zlib zlib-devel
)yum install openssl openssl-devel
,如需支持ssl,才需安装openssl)综合命令:sql
yum install gcc pcre-devel zlib zlib-devel openssl openssl-devel
5.下载源码包,选择稳定版本,解压缩安装(http://www.nginx.org/)数据库
wget http://nginx.org/download/nginx-1.10.2.tar.gz
6.解压缩apache
tar -zxvf nginx-1.10.2.tar.gz
7.进入Nginx目录以后执行 ./configure
1)、也能够指定安装目录,增长参数 --prefix=/usr/nginx
2)、若是不指定路径,能够经过 whereis nginx
来查询vim
8.继续执行 make
9.继续执行 make install
tomcat
默认安装在 /usr/local/nginx
安装成功以后,能够测试访问,默认是80端口:
安装路径下的 /nginx/sbin/nginx -t
安装路径下的 /nginx/sbin/nginx
/usr/local/nginx/sbin/nginx
安装路径下的 /nginx/sbin/nginx -s stop
或:nginx -s quit
安装路径下的 /nginx/sbin/nginx -s reload
ps -ef | grep nginx
kill -HUP [Nginx主进程号(即查看进程命令查到的PID)]
sudo vim /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
重启防火墙:
sudo service iptables restart
修改配置文件:
[root@corwien conf]# pwd /usr/local/nginx/conf # 添加文件夹 mkdir vhost
编辑nginx配置文件:
vim nginx.conf
nginx.conf 配置文件
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } 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 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #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; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # 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 # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} include vhost/*.conf; # HTTPS server # #server { # listen 443 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; # } #} }
编辑hosts
配置文件:
vim /etc/hosts
编辑域名配置:
[root@corwien vhost]# pwd /usr/local/nginx/conf/vhost [root@corwien vhost]# vim www.emall.com.conf
server { listen 80; autoindex on; server_name www.emall.com; access_log /usr/local/nginx/logs/access.log combined; index index.html index.htm index.jsp index.php; # root /product/ftpfile/; #error_page 404 /404.html; if ( $query_string ~* ".*[\;'\<\>].*" ){ return 404; } location / { proxy_pass http://127.0.0.1:8080; add_header Access-Control-Allow-Origin *; } }
验证:
(1)先开启Tomcat服务
# 开启Tomcat服务 /developer/apache-tomcat-7.0.82/bin/startup.sh
(2)使用域名 www.emall.com 访问:
咱们能够看到,能够正常访问。
建立配置:
[root@corwien vhost]# pwd /usr/local/nginx/conf/vhost [root@corwien vhost]# vim image.emall.com.conf
编辑图片目录域名配置文件
server { listen 80; autoindex off; server_name image.emall.com; access_log /usr/local/nginx/logs/access.log combined; index index.html index.htm index.jsp index.php; # root /product/ftpfile/; #error_page 404 /404.html; if ( $query_string ~* ".*[\;'\<\>].*" ){ return 404; } location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* { deny all; } location / { root /ftpfile/; add_header Access-Control-Allow-Origin *; } }
若是咱们使用 image.emall.com/m.jpg 文件,会出现404的问题,由于咱们的域名配置文件有误,应该添加后缀名 /usr/local/nginx/conf/vhost/image.emall.com
改成/usr/local/nginx/conf/vhost/image.emall.com.conf
,由于咱们在 nginx.conf
配置文件中这样加载的 include vhost/*.conf;
[root@corwien vhost]# vim s.emall.com.conf
编辑 s.emall.com.conf:
server { listen 80; autoindex off; # 是否自动建立索引,若是开启则会列出下面目录文件的索引 server_name s.emall.com; access_log /usr/local/nginx/logs/access.log combined; index index.html index.htm index.jsp index.php; # root /product/ftpfile/; #error_page 404 /404.html; if ( $query_string ~* ".*[\;'\<\>].*" ){ return 404; } location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* { deny all; } location / { root /product/front/; add_header Access-Control-Allow-Origin *; } }
配置以后,须要重启Nginx服务器:
[root@corwien nginx]# sbin/nginx -s reload
系统环境:CentOS 6.8 64位
MySQL版本:mysql-server-5.1.73(阿里软件源默认带的版本)
yum -y install mysql-server
能够经过 rpm -qa | grep mysql-server
此语句来检查是否已经安装mysql-server
mysql 默认配置文件在 /etc/my.cnf
(2)、字符集配置:
vim /etc/my.cnf
添加配置,在[mysqld]节点下添加:
default-character-set=utf8 character-set-server=utf8
:wq
保存退出
/etc/my.cnf
文件:
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # 设置字符集[20180107] default-character-set=utf8 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
关于中文乱码问题:
在5.1版本,为了解决中文乱码问题,my.ini
内[mysql]和[mysqld]中都写:
default-character-set=utf8
在5.5版本,[mysql]内能够这么写,[mysqld]内不能再这么写了,而是写:
character-set-server=utf8
(1)、执行 chkconfig mysqld on
(2)、执行 chkconfig --list mysqld
查看(若是2-5位启用on状态即OK)
(3)、启动MySQL
service mysqld start
(4)、登陆mysql
无密码登陆
[root@corwien corwien]# mysql -u root
(1)、vim /etc/sysconfig/iptables
(2)、-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
将以上配置添加到防火墙配置中
(3)、sudo service iptables restart
执行命令重启防火墙
-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
(1)、查看目前MySQL的用户
select user,host,password from mysql.user
咱们能够看到有两个匿名用户,出于安全考虑,咱们把匿名用户删掉:
mysql> delete from mysql.user where user = '';
删除匿名用户,执行如下SQL(安全考虑)
查看是否有匿名用户:select user, host from mysql.user;
删除匿名用户:delete from mysql.user where user='';
刷新、使以上操做生效:flush privileges
mysql> insert into mysql.user(Host,User,Password) values("localhost", "emall", password("518666"));
查看全部用户权限:
mysql> select * from mysql.user \G;
\G
表示对输出的内容进行格式化
\G
格式化以后输出的数据:
咱们能够看到,刚才添加的新用户 emall
的权限都为N,因此这里要对这个用户权限作开放:
根据本身实际状况决定是否开放什么权限
语法模板:
grant all privileges on 库名.表名 to '用户名'@'IP地址' identified by '密码' with grant option; flush privileges;
库名:要远程访问的数据库名称,全部的数据库使用“*” 表名:要远程访问的数据库下的表的名称,全部的表使用“*” 用户名:要赋给远程访问权限的用户名称 IP地址:能够远程访问的电脑的IP地址,全部的地址使用“%” 密码:要赋给远程访问权限的用户对应使用的密码
举例:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'lxh' WITH GRANT OPTION; # 全部的地址均可以使用root用户,密码为lxh远程访问全部的数据库 flush privileges; GRANT ALL PRIVILEGES ON testdb.* TO 'lxh'@'172.16.52.225' IDENTIFIED BY 'lxh' WITH GRANT OPTION; # IP为172.16.52.225的电脑可使用lxh用户,密码为lxh远程访问数据库testdb的全部表
赋予emall这个用户全部权限:
mysql> grant all privileges on emall.* to emall@'%' identified by '518666' with grant option;
或者只赋予查增改
权限,不让此用户对数据库进行删除
操做:
mysql> grant select,update,create on emall.* to emall@'%' identified by 'emall' with grant option;
咱们再查看受权是否成功:
mysql> select * from mysql.user \G;
已经授过权了,为何这里仍是N呢?
缘由是:select * from mysql.user \G;
给出的是全局的权限,而不是针对某个DB或者SCHEMA得权限。你赋权语句是grant all privileges on emall.* to 'emall'@'%' identified by '518666' with grant option;
也就是针对emall这个数据库赋权。那么你天然会得出权限都是‘N’了。
那么,这是否是错误的呢?答案固然不是了。
具体的流程是这样的:假如你有一个SQL的query,好比是select * from emall.table1。mysql会首先去user表中对比你(emall@localhost)是否有select 权限?发现是N.而后,它并不会直接拒绝这个query,而是会继续对照Database级别上检验权限,会db.user='emall' and db.db='emall' and db.host='localhsot',若是检验经过,则经过,不然继续向下检验,host.db='emall' and host.host='localhost',若检验经过,则经过,不然继续向下检验table级别,而后是column级别。
这就是mysql的权限检查模块的工做过程。
并非你出现了错误,而是mysql的内部机制就是这样的。
建议你仔细看下这篇文章http://tech.it168.com/a2010/0...。这里面对mysql的权限机制作了详细的讲解。
相关文章:
mysql grant 受权不起做用
因此,这里咱们给全部库受权,则这里的权限便可为Y:
mysql> grant all privileges on *.* to emall@'%' identified by '518666' with grant option;
set password for root@localhost=password('yourpassword'); set password for root@127.0.0.1=password('yourpassword');
设置root密码:
mysql> set password for root@127.0.0.1=password('root'); Query OK, 0 rows affected (0.00 sec)
从新登陆:
mysql -uroot -p
查看全部数据库:
mysql> show databases;
建立数据库:
mysql> create database `emall` default character set utf8 collate utf8_general_ci;
密码太多记不住??你是否忘记了MySQL的root密码? 经过如下4步就可从新设置新密码:
service mysqld stop
2.打开终端,输入:
找到mysql安装目录:
[root@corwien download]# whereis mysql mysql: /usr/bin/mysql /usr/lib64/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz
[root@corwien download]# /usr/bin/mysqld_safe --skip-grant-tables
3.打开另外一个新终端,输入:
[root@corwien corwien]# /usr/bin/mysql -u root mysql> UPDATE mysql.user SET authentication_string=PASSWORD('root') WHERE User='root'; ERROR 1054 (42S22): Unknown column 'authentication_string' in 'field list' mysql> UPDATE mysql.user SET password=PASSWORD('root') WHERE User='root'; Query OK, 2 rows affected (0.00 sec) Rows matched: 3 Changed: 2 Warnings: 0 mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> exit; Bye
4.而后重启mysql,从新登陆:
[root@corwien corwien]# service mysqld start [root@corwien corwien]# mysql -uroot -p Enter password: