Mac Osx下腾讯云centos7.2配置

来源:互联网 发布:淘宝助理如何使用 编辑:程序博客网 时间:2024/05/17 04:18

Mac Osx下腾讯云centos7.2配置

  • Mac Osx下腾讯云centos72配置
    • 服务器配置
      • a开放端口
      • b下载ssh私钥文件
    • 远程连接
      • a远程命令行
      • b远程可视化界面
    • java
    • mysql
    • tomcat
      • 支持https
      • http自动跳转https的安全配置
    • nginx
      • 安装 Nginx
      • 配置静态服务器访问路径
      • 支持https
      • 转发给Tomcat页面去掉端口号
    • 常用配置
      • a防火墙

1.服务器配置

a.开放端口

进腾讯云购买好云主机后,打开控制台:

这里写图片描述

配置安全组,放通全部端口:

这里写图片描述

b.下载ssh私钥文件。

这里写图片描述

上图是创建了私钥的网页,创建之前会有下载按钮,点击下载把私钥文件保存到本地用户名目录下的.ssh目录,私钥名字自己定义。.ssh是隐藏目录,要显示所有隐藏目录,可在终端输入:

defaults write com.apple.finder AppleShowAllFiles TRUE && killall Finder
  • 1

保存好之后,需要修改这个文件的权限为600,在终端输入:

chmod 600 文件名
  • 1

然后再拷贝一份这个文件到非隐藏目录,以便稍后的使用,目录随意,我自己的是放在文稿里了。


2.远程连接

a.远程命令行

下载Iterm2,打开设置,profiles,如图: 
 
参考我的设置,把Command中的sanqi改为你自己的私钥文件名,把ip改为你的服务器公网ip,在Basics中设置一个Shortcut key,之后就可以使用快捷键一键打开这个命令连接服务器了,连接后的界面:

这里写图片描述

b.远程可视化界面

要想ubentu一样看到界面,需要安装VNC server和图形包。 
第一步,安装GNOME桌面:

yum groupinstall GNOME Desktop
  • 1

第二步,安装VNC server:

yum install tigervnc-server -y
  • 1

第三步,设置登录密码:

vncpasswd
  • 1

第四步,启动VNC server:

vncserver :1 
  • 1

当然你可以输入其他数字,之后的输入对应上就行。

第五步,在你的本地电脑上安装VNCVieweer。输入服务器公网ip:1(我的是123.206.234.13:1)。界面如图: 
 
如果连不上,可能需要关闭防火墙,

systemctl stop firewalld
  • 1

用完再开启防火墙,

systemctl start firewalld
  • 1

关闭VNC server的命令为:

vncserver -kill :1
  • 1

3.java

在iTerm2上连接服务器,查看可用的jar包:

yum -y list java*
  • 1

安装列表中的jdk1.8

yum -y install java-1.8.0-openjdk*
  • 1

可能会提示是否继续,输入y即可。 
安装完,查看Java版本:

java -version
  • 1

4.mysql

下载repo源:

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 
  • 1

安装mysql-community-release-el7-5.noarch.rpm

sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
  • 1

安装MySQL

sudo yum install mysql-server
  • 1

重启MySQL

service mysqld restart
  • 1

修改MySQL密码

mysql -u root
  • 1
set PASSWORD for 'root'@'localhost' = PASSWORD('123456');
  • 1
exit
  • 1

设置MySQL可以远程连接

mysql -u root -pmysql-> grant all privileges on *.* to 'root'@'%' identified by '你的密码';mysql-> flush privileges;
  • 1
  • 2
  • 3
  • 4
  • 5

此时你已经可以远程连接数据库了,我是用的Navicat管理数据库,navicat11.2.14破解版。 
打开Navicat, 
这里写图片描述

点击Connection,选MySQL,

这里写图片描述

输入你的服务器公网IP和数据库登录名和密码就可以连上了。如果连不上,按照文章最后的防火墙命令开放3306端口再试下。


5.tomcat

查看安装包

yum search tomcat  
  • 1

安装tomcat

yum install tomcat tomcat-webapps tomcat-admin-webapps  
  • 1

防火墙添加80端口

firewall-cmd --zone=public --add-port=80/tcp --permanent
  • 1

80端口转发到8080,

firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080
  • 1

此时直接输IP就可以访问Tomcat了,8080端口可以不用输了。

常用命令:

 systemctl start tomcat.service   //启动 systemctl stop tomcat.service //停止 systemctl restart tomcat.service //重启 yum -y remove tomcat*  //卸载
  • 1
  • 2
  • 3
  • 4

支持https

参考https://www.qcloud.com/document/product/400/4143

配置SSL连接器,将www.domain.com.jks文件存放到/etc/tomcat/目录下,然后配置同目录下的server.xml文件:

 <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"                   maxThreads="150" SSLEnabled="true" scheme="https" secure="true"                   keystoreFile="/etc/tomcat/www.sanqis.cn.jks" keystorePass="12345666"                   clientAuth="false" sslProtocol="TLS" />
  • 1
  • 2
  • 3
  • 4

http自动跳转https的安全配置

到conf目录下的web.xml。在后面,,也就是倒数第二段里,加上这样一段

<login-config>    <!-- Authorization setting for SSL -->    <auth-method>CLIENT-CERT</auth-method>    <realm-name>Client Cert Users-only Area</realm-name>    </login-config>    <security-constraint>    <!-- Authorization setting for SSL -->    <web-resource-collection>    <web-resource-name>SSL</web-resource-name>    <url-pattern>/*</url-pattern>    </web-resource-collection>    <user-data-constraint>    <transport-guarantee>CONFIDENTIAL</transport-guarantee>    </user-data-constraint>    </security-constraint>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

最后记得访问的端口是8443,不是8080

nginx

安装 Nginx

yum install nginx -y
  • 1

安装完成后,使用 nginx 命令启动 Nginx:

nginx
  • 1

此时,访问 http://<您的域名> 可以看到 Nginx 的测试页面

如果无法访问,请重试用 nginx -s reload 命令重启 Nginx

配置静态服务器访问路径

外网用户访问服务器的 Web 服务由 Nginx 提供,Nginx 需要配置静态资源的路径信息才能通过 url 正确访问到服务器上的静态资源。

打开 Nginx 的默认配置文件 /etc/nginx/nginx.conf ,修改 Nginx 配置,将默认的 root /usr/share/nginx/html; 修改为: root /data/www;,如下:

示例代码:/etc/nginx/nginx.conf

user nginx;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;include /usr/share/nginx/modules/*.conf;events {    worker_connections 1024;}http {    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  /var/log/nginx/access.log  main;    sendfile            on;    tcp_nopush          on;    tcp_nodelay         on;    keepalive_timeout   65;    types_hash_max_size 2048;    include             /etc/nginx/mime.types;    default_type        application/octet-stream;    include /etc/nginx/conf.d/*.conf;    server {        listen       80 default_server;        listen       [::]:80 default_server;        server_name  _;        root         /data/www;        include /etc/nginx/default.d/*.conf;        location / {        }        error_page 404 /404.html;            location = /40x.html {        }        error_page 500 502 503 504 /50x.html;            location = /50x.html {        }    }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50

配置文件将 /data/www/static 作为所有静态资源请求的根路径,如访问: http://<您的域名>/static/index.js,将会去 /data/www/static/ 目录下去查找 index.js。现在我们需要重启 Nginx 让新的配置生效,如:

nginx -s reload
  • 1

重启后,现在我们应该已经可以使用我们的静态服务器了,现在让我们新建一个静态文件,查看服务是否运行正常。

首先让我们在 /data 目录 下创建 www 目录,如:

mkdir -p /data/www
  • 1

创建第一个静态文件

在 /data/www 目录下创建我们的第一个静态文件 index.html

示例代码:/data/www/index.html

<!DOCTYPE html><html lang="zh"><head>    <meta charset="UTF-8">    <title>第一个静态文件</title></head><body>Hello world!</body></html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

现在访问 http://<您的域名>/index.html 应该可以看到页面输出 [Hello world!]

到此,一个基于 Nginx 的静态服务器就搭建完成了,现在所有放在 /data/www 目录下的的静态资源都可以直接通过域名访问。

支持https

申请:https://www.qcloud.com/document/product/400/6814 
参考:https://www.qcloud.com/document/product/400/4143

将域名 www.domain.com 的证书文件1_www.domain.com_bundle.crt 、私钥文件2_www.domain.com.key保存到同一个目录,例如/usr/local/nginx/conf目录下。 
更新Nginx根目录下 conf/nginx.conf 文件如下:

server {        listen       80 default_server;        listen       [::]:80 default_server;        server_name  www.sanqis.cn;        # Load configuration files for the default server block.        include /etc/nginx/default.d/*.conf;        rewrite ^(.*)$ https://$host$1 permanent;        location / {        root         /data/www;        index index.html;        }        error_page 404 /404.html;            location = /40x.html {        }        error_page 500 502 503 504 /50x.html;            location = /50x.html {        }}server {        listen 443;        server_name www.domain.com; #填写绑定证书的域名        ssl on;        ssl_certificate 1_www.domain.com_bundle.crt;        ssl_certificate_key 2_www.domain.com.key;        ssl_session_timeout 5m;        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置        ssl_prefer_server_ciphers on;        location / {            root   html; #站点目录            index  index.html index.htm;        }    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38

重启生效。

转发给Tomcat页面去掉端口号

继续修改nginx.conf:

server {        listen       80 default_server;        listen       [::]:80 default_server;        server_name  www.sanqis.cn;        # Load configuration files for the default server block.        include /etc/nginx/default.d/*.conf;        rewrite ^(.*)$ https://$host$1 permanent;        location / {        root         /data/www;        index index.html;        }        location ^~ /server/ {            proxy_pass   https://10.154.13.189:8443/;            proxy_redirect off;            proxy_set_header X-Real-IP $remote_addr;            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        }        error_page 404 /404.html;            location = /40x.html {        }        error_page 500 502 503 504 /50x.html;            location = /50x.html {        }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

常用配置

a.防火墙

开启防火墙

 systemctl start firewalld
  • 1

停止

systemctl disable firewalld
  • 1

禁用

systemctl stop firewalld
  • 1

重启

systemctl restart firewalld.service
  • 1

显示状态

firewall-cmd –state
  • 1

更新防火墙规则

firewall-cmd –reload
  • 1

添加端口(比如:80)

firewall-cmd --zone=public --add-port=80/tcp --permanent
  • 1

permanent表示永久生效。

移除端口

firewall-cmd --remove-port=80/tcp 
  • 1

查看开放的端口

firewall-cmd --list-ports 
  • 1

查询端口是否开启(比如:80)

firewall-cmd --query-port=80/tcp
  • 1

查看所有端口状态

netstat -tunlp
  • 1

端口转发(比如:80–>8080)

firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080原文地址:http://blog.csdn.net/u013005791/article/details/58049079
原创粉丝点击