centos7 firewall 命令
查看已经开放的端口
firewall-cmd --list-ports
查看开放的服务
firewall-cmd --list-services
开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --zone=public --add-port=3306/tcp --permanent

firewall-cmd --zone=public --add-port=8080/tcp --permanent
命令含义:
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
重启防火墙
firewall-cmd --reload #重启firewall

systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动

CentOS 7 以下版本 iptables 命令
如要开放80,22,8080 端口,输入以下命令即可

/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT

然后保存:
/etc/rc.d/init.d/iptables save

查看打开的端口:
/etc/init.d/iptables status
关闭防火墙
1) 永久性生效,重启后不会复原
开启: chkconfig iptables on
关闭: chkconfig iptables off
2) 即时生效,重启后复原
开启: service iptables start
关闭: service iptables stop


其中./configure时是可以进行一些配置的,具体可以参考(如果你看英文手册没有什么压力的话可以直接 configure --help获取帮助):

    --prefix=PATH : 指定nginx的安装目录。默认 /usr/local/nginx
    --conf-path=PATH : 设置nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动,通过命令行中的-c选项。默认为prefix/conf/nginx.conf
    --user=name: 设置nginx工作进程的用户。安装完成后,可以随时在nginx.conf配置文件更改user指令。默认的用户名是nobody。--group=name类似
    --with-pcre : 设置PCRE库的源码路径,如果已通过yum方式安装,使用--with-pcre自动找到库文件。使用--with-pcre=PATH时,需要从PCRE网站下载pcre库的源码(版本4.4 – 8.30)并解压,剩下的就交给Nginx的./configure和make来完成。perl正则表达式使用在location指令和 ngx_http_rewrite_module模块中。
    --with-zlib=PATH : 指定 zlib(版本1.1.3 – 1.2.5)的源码解压目录。在默认就启用的网络传输压缩模块ngx_http_gzip_module时需要使用zlib 。
    --with-http_ssl_module : 使用https协议模块。默认情况下,该模块没有被构建。前提是openssl与openssl-devel已安装
    --with-http_stub_status_module : 用来监控 Nginx 的当前状态
    --with-http_realip_module : 通过这个模块允许我们改变客户端请求头中客户端IP地址值(例如X-Real-IP 或 X-Forwarded-For),意义在于能够使得后台服务器记录原始客户端的IP地址
    --add-module=PATH : 添加第三方外部模块,如nginx-sticky-module-ng或缓存模块。每次添加新的模块都要重新编译(Tengine可以在新加入module时无需重新编译)



参考:http://blog.csdn.net/sunxiaopengsun/article/details/53965643
Centos7 安装中文输入法
sudo su -
yum install ibus-libpinyin

https://mariadb.org/blog/
 就会得到配置文件的内容:
# MariaDB 10.1 CentOS repository list - created 2016-07-18 06:22 UTC
#http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl =http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
2、在 etc/yum.repos.d下,创建MariaDB.repo文件,将上边得到的内容复制到这个文件中,保存退出。
3、运行命令yum install MariaDB-server MariaDB-client,开始安装。


参考: http://www.jb51.net/os/RedHat/313889.html
CentOS7设置日期和时间方法以及基本概念介绍
一、基本概念
1.1 GMT、UTC、CST、DST 时间
(1) UTC
整个地球分为二十四时区,每个时区都有自己的本地时间。在国际无线电通信场合,为了统一起见,使用一个统一的时间,称为通用协调时(UTC, Universal Time Coordinated)。
(2) GMT
格林威治标准时间 (Greenwich Mean Time)指位于英国伦敦郊区的皇家格林尼治天文台的标准时间,因为本初子午线被定义在通过那里的经线。(UTC与GMT时间基本相同,本文中不做区分)
(3) CST
中国标准时间 (China Standard Time)
GMT + 8 = UTC + 8 = CST
(4) DST
夏令时(Daylight Saving Time) 指在夏天太阳升起的比较早时,将时钟拨快一小时,以提早日光的使用。(中国不使用)
1.2 硬件时钟和系统时钟
(1) 硬件时钟
RTC(Real-Time Clock)或CMOS时钟,一般在主板上靠电池供电,服务器断电后也会继续运行。仅保存日期时间数值,无法保存时区和夏令时设置。
(2) 系统时钟
一般在服务器启动时复制RTC时间,之后独立运行,保存了时间、时区和夏令时设置。


二、timedatectl 命令
2.1 读取时间
timedatectl //等同于 timedatectl status
2.2 设置时间
timedatectl set-time "YYYY-MM-DD HH:MM:SS"
2.3 列出所有时区
timedatectl list-timezones
2.4 设置时区
timedatectl set-timezone Asia/Shanghai
2.5 是否NTP服务器同步
timedatectl set-ntp yes //yes或者no
2.6 将硬件时钟调整为与本地时钟一致
timedatectl set-local-rtc 1
hwclock --systohc --localtime //与上面命令效果一致
2.6 硬件时间设置成 UTC:
timedatectl set-local-rtc 1
hwclock --systohc --utc //与上面命令效果一致


centos7 设置了EPEL库
安装epel仓库
yum -y install epel-release
移除epel仓库
yum -y remove epel-release
查看仓库信息:
yum repolist





Centos7安装配置Apache+PHP+Mysql+phpmyadmin
参考: http://www.jianshu.com/p/bc14ff0ab1c7

一、安装Apache
yum -y install  httpd
rpm -qi httpd
cp httpd.conf httpd.conf.origin    //将原有配置文件备份

安装成功后,Apache操作命令:

systemctl start httpd      //启动apache
systemctl stop httpd       //停止apache
systemctl restart httpd    //重启apache
systemctl enable httpd     //设置apache开机启动

 //设置为自动启动
# systemctl enable httpd.service
ln -s'/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
//在centos7中chkconfig httpd on 被替换成 systemctl enable httpd
 配置WEB站点 (假设使用/wwwroot目录下的文档)    
//创建两个网站的目录结构及测试用页面文件
# mkdir/wwwroot/www
# echo"www.bigcloud.local" > /wwwroot/www/index.html
 
# mkdir/wwwroot/crm
# echo"crm.bigcloud.local" > /wwwroot/crm/index.html
 //配置虚拟机主机
# cd/etc/httpd/
# mkdirvhost-conf.d
# echo"Include vhost-conf.d/*.conf" >> conf/httpd.conf
 
# vi/etc/httpd/vhost-conf.d/vhost-name.conf
//添加如下内容
<VirtualHost *:80>
   ServerNamewww.bigcloud.local
  DocumentRoot /wwwroot/www/
</VirtualHost>
<Directory /wwwroot/www/>
    Requireall granted
</Directory>
 
<VirtualHost *:80>
   ServerNamecrm.bigcloud.local
  DocumentRoot /wwwroot/crm/
</VirtualHost>
<Directory /wwwroot/crm/>
   Require ip192.168.188.0/24   //可以设置访问限制
</Directory>
 

异常处理
我再阿里云上配置并出现启动Apache后无法访问的问题,但是一般服务器访问Apache可能需要如下操作:
(1)在防火墙中开放80端口
现在需要将 http 服务加入防火墙以允许外部访问,
firewall-cmd --add-service=http --permanent --zone=public
–permanent 参数表示这是一条永久防火墙规则,如果不加则重启系统后就没有这条规则了。
而对于自定义的端口(如81),也需要添加防火墙规则,
firewall-cmd --zone=public --add-port=81/tcp --permanent
重启 Firewalld 使该规则生效,
systemctl restart firewalld

参考: http://www.cnblogs.com/xiaoluo501395377/archive/2013/05/26/3100444.html

(2)关闭SELINUX
vi /etc/selinux/config
注释掉如下两句,添加最后一项
\#SELINUX=enforcing #注释掉
\#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq! 保存退出
输入如下命令

setenforce 0 #使配置立即生效

getenforce  查看

sestatus
setenforce 0
如果要永久关闭 可修改/etc/selinux/config/ 将SELINU 设置为 disabled
也可以用命令完成
sed -i 'SELINUX/s/enforcing/disabled' /etc/selinux/config
getenforce

yum安装 程序过程中 出现占用yum情况:

rm -f /var/run/yum.pid



centos7安装httpd服务及访问控制
yum repolist 看是否有安装包
安装httpd服务,使用yum -y install httpd,并设置开机启动服务 systemctl enable httpd
启动httpd 服务,并加入防火墙规则使其允许通过
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
systemctl restart httpd
添加一个简单的网站,用curl命令在客户端进行测试
echo "ceshi" >/var/www/html/index.html
curl -r http://localhost
更改网站主目录
设置目录权限chcon -R  -t  httpd_sys_content_t '文件夹名'
配置httpd.conf文件,并重新启动服务,在客户端进行测试

二、 安装MariaDB (MySQL的一个开源分支)
yum install mariadb mariadb-server
MariaDB安装成功后,需要配置MySQL的root密码,此外,备注一下启动关闭MariaDB的常用命令
systemctl start mariadb     //启动MariaDB
systemctl stop mariadb      //停止MariaDB
systemctl restart mariadb   //重启MariaDB
systemctl enable mariadb    //设置开机启动

2、配置MariaDB的字符集
http://www.linuxidc.com/Linux/2016-03/128880.htm
文件/etc/my.cnf.d/
vi /etc/my.cnf.d/server.cnf
在[mysqld]标签下添加
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
文件/etc/my.cnf.d/client.cnf
vi /etc/my.cnf.d/client.cnf
在[client]中添加
default-character-set=utf8
文件/etc/my.cnf.d/mysql-clients.cnf
vi /etc/my.cnf.d/mysql-clients.cnf
在[mysql]中添加
default-character-set=utf8
 全部配置完成,重启mariadb
systemctl restart mariadb
之后进入MariaDB查看字符集

mysql -uroot -p 回车

mysql> show variables like "%character%";show variables like "%collation%";
显示为
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client    | utf8                      |
| character_set_connection | utf8                      |
| character_set_database  | utf8                      |
| character_set_filesystem | binary                    |
| character_set_results    | utf8                      |
| character_set_server    | utf8                      |
| character_set_system    | utf8                      |
| character_sets_dir      | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
+----------------------+-----------------+
| Variable_name        | Value          |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database  | utf8_unicode_ci |
| collation_server    | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
字符集配置完成。

3、添加用户,设置权限
创建用户命令
mysql>create user username@localhost identified by 'password';
直接创建用户并授权的命令
mysql>grant all on *.* to username@localhost identified by 'password';
授予外网登陆权限
mysql>grant all privileges on *.* to username@'%' identified by 'password';
授予权限并且可以授权
mysql>grant all privileges on *.* to username@'hostname' identified by 'password' with grant option;

简单的用户和权限配置基本就这样了。
其中只授予部分权限把 其中 all privileges或者all改为select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file其中一部分。
设置root账户密码
mysql_secure_installation
    Enter current password for root (enter for none):
    Set root password? [Y/n]
点击回车然后提示是否设置root账号密码,输入y
    New password:
    Re-enter new password:
    Password updated successfully!
提示输入新密码和重复输入新密码,重复输入两次后,出现更新密码成功提示。
然后一路输入y就可以。
    Remove anonymous users? [Y/n] y
    ... Success!
    Disallow root login remotely? [Y/n] y
    ... Success!
    Remove test database and access to it? [Y/n] y
    - Dropping test database...
    ... Success!
    - Removing privileges on test database...
    ... Success!
    Reload privilege tables now? [Y/n] y
    ... Success!
    Thanks for using MariaDB!

设置root密码后,重启MariaDB生效
systemctl restart mariadb.service
测试访问数据库:
mysql -uroot -p
然后输入密码,登录成功后显示如下:
    Enter password:
    Welcome to the MariaDB monitor. Commands end with ; or \g.
    Your MariaDB connection id is 2
    Server version: 5.5.44-MariaDB MariaDB Server
    Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    MariaDB [(none)]>
输入如下命令,查看数据库服务器的数据库
show databases;
退命令:
exit;

三、安装PHP以及PHP拓展

yum install php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
安装完成后,重启Apache服务器
systemctl restart httpd.service
测试PHP安装结果
vi /var/www/html/index.php
输入如下内容
<?php
  phpinfo();
?>
输入:wq! 保存退出
在浏览器中输入服务器地址,查看是否可以看到:
页面效果

四、安装phpmyadmin
使用yum安装phpmyadmin
yum install phpmyadmin php-mcrypt
phpMyAdmin 的默认安装目录是 /usr/share/phpMyAdmin,同时会在 Apache 的配置文件目录中自动创建虚拟主机配置文件 /etc/httpd/conf.d/phpMyAdmin.conf(区分大小写)。默认情况下,CentOS 7上的phpMyAdmin只允许从回环地址(127.0.0.1)访问。为了能远程连接,你需要改动它的配置。
vi /etc/httpd/conf.d/phpMyAdmin.conf
修改配置文件,如下:
<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8
   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
      # Require ip 127.0.0.1  #注释掉
      # Require ip ::1   #注释掉
      Require all granted   #新添加
     </RequireAny>
 </IfModule>
 <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from 127.0.0.1
     Allow from ::1
   </IfModule>
</Directory>

<Directory /usr/share/phpMyAdmin/setup/>
   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
      #Require ip 127.0.0.1  #注释掉
      #Require ip ::1   #注释掉
      Require all granted   #新添加
     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from 127.0.0.1
     Allow from ::1
   </IfModule>
</Directory>

然后重启Apache服务器
systemctl restart httpd
然后可以通过浏览器访问http://服务器ip地址/phpmyadmin访问




参考:http://www.linuxidc.com/Linux/2016-09/134907.htm
CentOS 7 下 压缩包安装 Nginx 
安装所需环境
Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Windows 版本,本篇则使用 CentOS 7 作为安装环境。
一. gcc 安装
安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:
yum install gcc-c++

二. PCRE pcre-devel 安装
PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令:
yum install -y pcre pcre-devel

三. zlib 安装
zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。
yum install -y zlib zlib-devel

四. OpenSSL 安装
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。
yum install -y openssl openssl-devel

官网下载
1.直接下载.tar.gz安装包,地址:https://nginx.org/en/download.html
nginx.png

2.使用wget命令下载(推荐)。
wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
我下载的是1.10.1版本,这个是目前的稳定版。
解压
依然是直接命令:
tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1

配置
其实在 nginx-1.10.1 版本中你就不需要去配置相关东西,默认就可以了。当然,如果你要自己配置目录也是可以的。
1.使用默认配置
./configure 需要更改

2.自定义配置(不推荐)
./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi

    注:将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录

编译安装
make
make install

查找安装路径:
whereis nginx

nginx-whereis.png
启动、停止nginx

cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s quit
./nginx -s reload
./nginx -s quit:此方式停止步骤是待nginx进程处理任务完毕进行停止。
./nginx -s stop:此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。

查询nginx进程:
ps aux|grep nginx

重启 nginx
1.先停止再启动(推荐):
对 nginx 进行重启相当于先停止再启动,即先执行停止命令再执行启动命令。如下:
./nginx -s quit
./nginx

2.重新加载配置文件:
当 ngin x的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止 ngin x再启动 nginx
即可将配置信息在 nginx 中生效,如下:
./nginx -s reload
启动成功后,在浏览器可以看到这样的页面:

开机自启动
即在rc.local增加启动代码就可以了。
vi /etc/rc.local
增加一行 /usr/local/nginx/sbin/nginx
设置执行权限:
chmod 755 rc.local
到这里,nginx就安装完毕了,启动、停止、重启操作也都完成了,当然,你也可以添加为系统服务,我这里就不在演示了。



http://www.cnblogs.com/calvinK/p/5604036.html
 .Net Core Linux centos7行—安装nginx,运行静态网站
使用编译安装方式安装nginx
    Nginx下载地址:http://nginx.org/en/download.html。下载Stable version(稳定版就好)。当前稳定版:http://nginx.org/download/nginx-1.10.1.tar.gz
    可以下载完成之后,ftp上传到centos。或者使用wget命令下载。wget -p savepath downloadurl。
    下载完成,解压。使用命令 tar -xzvf nginx-1.10.1.tar.gz 解压到指定目录使用 tar -xzvf nginx-1.10.1.tar.gz -C savepath
    解压 之后cd到解压的目录内。
    安装nginx
        运行命令./ configure –prefix=安装路径。当提示缺少各种包的时候安装上即可。可能提示缺少gcc,pcre,zlib等。使用命令 yum -y install gcc-c++ pcre-devel zlib-devel完成相应的组件安装。
        运行命令make && make install 完成安装
        参考:http://www.cnblogs.com/skyblue/archive/2013/05/13/3075900.html
            http://www.cnblogs.com/kunhu/p/3633002.html
            http://www.cnblogs.com/xd502djj/archive/2011/11/23/2260239.html
    nginx基本设置
    4.1.首先设置防火墙。放行80端口。centos7改用firewall啦,不再是之前的iptables了。
    命令firewall-cmd --zone=public --add-port=80/tcp –permanent。–permanent代表永久生效
    参考:http://www.zhaokeli.com/Article/6321.html
    4.2.设置nginx网站目录。定位到nginx安装目录/conf。编辑nginx.conf文件
    server{
        listen    80;
        server_name    localhost;
        location{
         root     /my static app path //主要修改指向自己的project目录即可
         index    index.html index.htm
    }
    }

    具体配置参考:
    http://my.oschina.net/duxuefeng/blog/34880
    http://www.nginx.cn/76.html
    http://www.cnblogs.com/xiaogangqq123/archive/2011/03/02/1969006.html
如果不出意外,通过ip就能方法我们搭建的静态站点啦

 

 

http://www.kimsom.com/article/138
centos7正确安装设置phpMyAdmin的方法

我们可以在命令行工具下面管理MySQL/MariaDB数据库。如果想要个图形界面的话,可以安装使用phpMyAdmin,这样通过浏览器就可以直接管理服务器里面的数据库:添加用户、设置密码、创建数据库、导入导出数据等等。

安装
在很多Linux类型的系统上都可以使用包管理工具去安装phpMyAdmin,比如在CentOS系统里,先为系统安装epel仓库,然后就可以通过yum -y install phpmyadmin安装phpMyAdmin了。
当然如果你不想使用默认的版本,可以去https://www.phpmyadmin.net/downloads/这里下载安装。
通过yum安装的默认目录为/usr/share/phpMyAdmin,也可能是其他目录,根据系统版本不同,可能会有变化,大家留意一下就可以了。下面我们要设置访问,这里以nginx为例,在/etc/nginx/conf.d/你站点的conf文件中的server加入以下代码:
location /phpmyadmin {
alias /usr/share/phpMyAdmin;
index index.php;
}
location ~ /phpmyadmin/.+\.php$ {
if ($fastcgi_script_name ~ /phpmyadmin/(.+\.php.*)$) {
set $valid_fastcgi_script_name $1;
}
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin/$valid_fastcgi_script_name;
}
现在,打开浏览器,输入nginx服务器绑定的主机名/phpmyadmin就可以访问了,用MySQL/MariaDB系统里的用户登录一下看看。

配置
登录到phpMyAdmin以后,在页面底部会显示“配置文件现在需要一个短语密码。”或"The configuration file now needs a secret passphrase (blowfish_secret).",你需要在phpMyAdmin的配置文件里的blowfish_secret这个配置里面去设置一个密码,phpMyAdmin会用到这个密码,加密Cookie。phpMyAdmin 的相关配置要放在一个叫 config.inc.php的文件里,如果这个文件不存在,你可以复制一份 config.sample.inc.php,命名为 config.inc.php。进入到phpMyAdmin所在的目录以后:
cp config.sample.inc.php config.inc.php
然后去生成一串随机的密码,可以使用openssl去做:
openssl rand -base64 32
返回:
kVu/yTa5dzkIJiYHrDppvnU+y8LCLf6XkpoldsCMfFQ=
复制返回来的随机密码,然后打开config.inc.php,搜索$cfg['blowfish_secret'],把复制的密码粘贴到这个配置的后面。
$cfg['blowfish_secret'] = 'AhONip2q+KmANQJfbzx7NC+j+hsGRKuhuQi8ClJG4mk=';
保存配置文件,回到浏览器,重新登录。

安全
在生产环境下使用 phpMyAdmin,所有人也都可以看到phpMyAdmin的登录页面,虽然他们不知道你的数据库的用户名跟密码,不过还是挺吓人的。我们可以配置一下nginx ,在显示phpMyAdmin登录页面之前,验证一下用户的身份,同样需要输入用户名还有密码,成功以后,才能进入到phpMyAdmin的登录页面,然后使用数据库管理系统上的用户登录。

我们要做的是创建一个密码文件,文件里的内容就是用户名与对应的密码,然后再去设置一下nginx的服务器配置,访问phpMyAdmin的时候,用密码文件里的用户名跟密码验证用户的身份。这个密码需要用crypt()加密一下,可以使用openssl去做这件事:
openssl passwd
提示你输入要加密的密码,输入好以后,回车,又会提示Verifying - Password,再输入一次密码。再次回车,会返回加密以后的密码,像这样:
cHDQh8dVIZRwY
复制一下这串加密之后的密码,下面再去创建一个密码文件,进入到nginx的配置文件所在的目录:
cd /etc/nginx/conf.d
创建一个文件叫pma_pass(意思是phpMyAdmin password),可以使用vim:
vim pma_pass
文件里的内容使用username:password的形式,像这样:
kimsom:cHDQh8dVIZRwY
打开服务器的配置文件,修改location /phpmyadmin模块,用auth_basic指令设置一个登录窗口的提示,再用auth_basic_user_file指令设置一下密码文件的位置:
location /phpmyadmin {
auth_basic "Login Please";
auth_basic_user_file /etc/nginx/conf.d/pma_pass;
alias /usr/share/phpMyAdmin;
index index.php;
}

 

 

nginx:bind() to 0.0.0.0(98 address alreadly in use  )

sudo fuser -k 80/tcp

重启服务

 参考: http://www.511yj.com/centos7-lnmp-php.html

centos7安装Lnmp(Linux+Nginx+MySql+Php)及Apache

Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,Nginx是一个高性能的HTTP和反向代理服务器,Nginx 超越 Apache 的高性能和稳定性,使得国内使用 Nginx 作为 Web 服务器的网站也越来越多,

我们学习PHP,以及搭建我们自己的LNMP环境,不妨先在本机上尝试学习,下面我们一步一步来完成在CentOS7 下安装LNMP(Linux+Nginx+MySQL+PHP)及Apache。

查看已经开放的端口
firewall-cmd --list-ports
查看开放的服务
firewall-cmd --list-services

开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent

firewall-cmd --zone=public --add-port=3306/tcp --permanent

firewall-cmd --zone=public --add-port=8080/tcp --permanent
命令含义:
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
重启防火墙
firewall-cmd --reload #重启firewall
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动

关闭SELINUX
vi /etc/selinux/config
注释掉如下两句,添加最后一项
\#SELINUX=enforcing #注释掉
\#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq! 保存退出
输入如下命令
setenforce 0 #使配置立即生效

getenforce  查看

sestatus

setenforce 0

yum安装 程序过程中 出现占用yum情况:

rm -f /var/run/yum.pid

 

一、安装httpd

  sudo su -

 yum install -y httpd 

二、启动httpd服务

安装完成之后使用以下命令启动httpd服务:

#启动apache

systemctl start httpd.service

#设置apache开机启动

systemctl enable httpd.service

可以在浏览器中输入服务器所在的主机的IP即可看到apache的欢迎界面。

要在另外一台主机上实现这种访问,需要关闭系统的防火墙。

在CentOS7中只能使用以下命令,如果使用上面的命令并不会报任何错误,但是起不到关闭防火墙的效果:

systemctl stop firewalld.service 

  //禁止防火墙开机启动

systemctl disable firewalld.service 

防火墙开放端口和服务

firewall-cmd --add-service=http --permanent --zone=public

firewall-cmd --reload

firewall-cmd --list-all

三、安装MySql数据库

MySQL数据库,新版本已经更名为Mariadb,所以这里需要安装Mariadb,可以使用下面的命令进行安装:

 yum install -y mariadb mariadb-server

四、开启数据库服务

1、安装完成以后使用下面的命令开启数据库服务:
#启动MariaDB

 systemctl start mariadb.service   

#重启MariaDB

systemctl restart mariadb.service  

#设置开机启动

systemctl enable mariadb.service  

2、配置MariaDB的字符集

vim /etc/my.cnf.d/server.cnf

在[mysqld]标签下添加
init_connect='SET collation_connection = utf8_unicode_ci' 
init_connect='SET NAMES utf8' 
character-set-server=utf8 
collation-server=utf8_unicode_ci 
skip-character-set-client-handshake

文件/etc/my.cnf.d/client.cnf
vi /etc/my.cnf.d/client.cnf

在[client]中添加
default-character-set=utf8
文件/etc/my.cnf.d/mysql-clients.cnf
vi /etc/my.cnf.d/mysql-clients.cnf
在[mysql]中添加
default-character-set=utf8
 全部配置完成,重启mariadb
systemctl restart mariadb
之后进入MariaDB查看字符集

mysql -uroot -p 回车

mysql> show variables like "%character%";show variables like "%collation%";
字符集配置完成。

3、添加用户,设置权限
创建用户命令
mysql>create user username@localhost identified by 'password';
直接创建用户并授权的命令
mysql>grant all on *.* to username@localhost identified by 'password';
授予外网登陆权限 
mysql>grant all privileges on *.* to username@'%' identified by 'password';
授予权限并且可以授权
mysql>grant all privileges on *.* to username@'hostname' identified by 'password' with grant option;

简单的用户和权限配置基本就这样了。
其中只授予部分权限把 其中 all privileges或者all改为select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file其中一部分。
设置root账户密码
mysql_secure_installation
然后一路输入y就可以。
设置root密码后,重启MariaDB生效
systemctl restart mariadb.service
测试访问数据库:
mysql -uroot -p
show databases;
退命令:
exit;

五、安装PHP

 yum -y install php 

使用下面的命令安装php对Mariadb的支持:
yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash

一路“Y”

php --version

五、重启Mariadb和httpd服务:

使用下面的命令重启Mariadb和httpd服务:

#重启MariaDB

systemctl restart mariadb.service 

#重启apache

systemctl restart httpd.service 

vim /var/www/html/index.php ->内容:<?php phpinfo(); ?>

六、安装nginx

想在 CentOS 系统上安装 Nginx ,你得先去添加一个资源库,像这样:

vim /etc/yum.repos.d/nginx.repo 

使用 vim 命令去打开 /etc/yum.repos.d/nginx.repo ,如果 nginx.repo 不存在,就会去创建一个这样的文件,打开以后按一下小 i 键,进入编辑模式,然后复制粘贴下面这几行代码,完成以后按 esc 键退出,再输入 :wq (保存并退出)

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

完成以后,我们就可以使用 yum 命令去安装 nginx 了,像这样:

yum -y install nginx
由于安装了Httpd服务,所以要先停止,关闭apache之后再次启动nginx。

停止Httpd

systemctl stop httpd.service 

测试一下 nginx 服务:

systemctl status httpd.service

测试一下 nginx 的配置文件:

nginx -t   

返回

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful   

说明配置文件成功!

开启服务:systemctl start nginx.service

开机启动:systemctl enable nginx.service

七、配置服务

这里使用的是nginx做反向代理,将其客户端通过80端口请求的.php内容代理到apache服务器上。

要想使用nginx做反向代理,需要修改Apache的httpd和nginx的配置文件,使其监听不同的端口,这里我们使用nginx监听80端口,

使用Apache监听8080端口,这里我们分别配置Apache和nginx的配置文件,修改结果如下:

(1)Apache配置文件:/etc/httpd/conf/httpd.conf

#Listen 12.34.56.78:80
Listen 8080

(2)nginx配置如下:/etc/nginx/conf.d/default.conf

 # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    location ~ \.php$ {
      proxy_pass   http://127.0.0.1:8080;
    }

(3)不指定8080端口访问nginx服务器:

http://localhost

(4)指定8080端口访问apache服务器:

http://localhost:8080

(5)指定8080端口访问apache服务器下的mysql->mariadb

http://locahost:8080/phpmyadmin

 

参考:http://www.kimsom.com/article/138

http://www.jb51.net/article/68026.htm

添加nginx服务:

 http://www.cnblogs.com/riverdubu/p/6426852.html

posted on 2017-05-18 11:45  阚壠  阅读(4180)  评论(0编辑  收藏  举报