Linux 服务器系列(一)简单搭建服务器

本贴最后更新于 2235 天前,其中的信息可能已经时过境迁

原文地址 https://www.heayan.com/articles/2018/01/17/1516179224931.html

前言

世界互联网发展迅速,各大互联网企业纷纷步入服务器托管、服务器租用服务行业,其中暴利可见一斑。目前国内主要服务器提供商有阿里云、腾讯云、京东云、亚马逊云、西部数据、景安等等,国外常用的有 Google Compute Engine、Linode、Vultr、Host1plus、Ramnode。国内个人用户常常会遇到几件麻烦事儿。首先,国内法律严格要求网站备案,且过程相当繁琐,对于个人来说,租用国外的服务器会省去大部分麻烦。其次,由于远距离访问会有较高的网络延迟,所以尽量租用香港、新加坡、日本等等邻近国家的服务器。另外 ,针对开发者最好租用 VPS,拒绝虚拟云主机,原因就是不能对操作系统有直接的操作权限,只能通过控制面板间接控制系统,一旦出现灵异问题,很难定位很难解决。针对以上问题,下面推荐几款常用国外服务器提供商:

环境准备

CentOS7

1.JDK 安装配置

查看已安装JDK
[root@heayan local]# rpm -qa | grep java
卸载验证JDK
[root@heayan local]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
安装JDK
[root@heayan local]# mkdir jdk1.8	
[root@heayan local]# wget http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.tar.gz
[root@heayan local]# tar -zxvf jdk-8u161-linux-x64.tar.gz
[root@heayan local]# mv jdk-8u161-linux-x64 jdk1.8
[root@heayan local]# cd jdk1.8
[root@heayan jdk1.8]# ./configure
[root@heayan jdk1.8]# make
[root@heayan jdk1.8]# make install
配置环境变量,最后一行添加如下配置信息
[root@heayan jdk1.8]# vi /etc/profile
#java environment
export JAVA_HOME=/usr/local/jdk1.8
export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar
export PATH=$PATH:${JAVA_HOME}/bin
查看JDK版本
java -version

2.MySQL 安装配置

[root@heayan local]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
[root@heayan local]# yum -y install mysql57-community-release-el7-10.noarch.rpm
[root@heayan local]# yum -y install mysql-community-server	
启动
[root@heayan local]# systemctl start  mysqld.service
查看状态
[root@heayan local]# systemctl status mysqld.service
查看默认密码
[root@heayan local]# grep "password" /var/log/mysqld.log
进入数据库
[root@heayan local]# mysql -uroot -p
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';

3.Nginx 安装配置

安装支持库
[root@heayan bin]# yum install gcc-c++	
检查支持库
[root@heayan bin]# rpm -qa | grep gcc	
下载nginx-1.12.2.tar.gz
[root@heayan /]# cd /usr/local
[root@heayan local]# wget http://nginx.org/download/nginx-1.12.2.tar.gz
解压
[root@heayan local]# tar -zxvf nginx-1.12.2.tar.gz
编译、安装
[root@heayan local]# mkdir nginx
[root@heayan local]# cd nginx-1.12.2
[root@heayan nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module
[root@heayan nginx-1.12.2]# make
[root@heayan nginx-1.12.2]# make install	
配置
[root@heayan nginx-1.12.2]# cd /usr/local/nginx/conf
[root@heayan conf]# vi nginx.conf	
upstream heayan{#配置上游服务器
	ip_hash;
   server 127.0.0.1:8501;
   server 127.0.0.1:8502;
   server 127.0.0.1:8503;
}
server {	  	
	server_name  www.heayan.com;#配置域名	  	
	location / {#请求转发
	  proxy_pass http://heayan;
	}
	#其他信息默认	   
}
[root@heayan bin]# cd /usr/local/nginx/sbin
启动
[root@heayan bin]# ./nginx 或 ./nginx -t 
停止
[root@heayan bin]# ./nginx -s stop
退出
[root@heayan bin]# ./nginx -s quit
重新加载
[root@heayan bin]# ./nginx -s reload

4.Tomcat 安装配置

下载
[root@heayan /]# cd /usr/local
[root@heayan local]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.24/bin/apache-tomcat-8.5.24.tar.gz	
解压
[root@heayan local]# tar -zxvf apache-tomcat-8.5.24.tar.gz	
[root@heayan local]# mv apache-tomcat-8.5.24 tomcat8501
配置
[root@heayan local]# vi /usr/local/tomcat8501/conf/server.xml
<!--配置端口号port、项目路径docBase-->
<Connector port="8501" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">		
	<Context path="/" docBase="/opt/www/www.heayan.com" reloadable="true" />
	<!--其他信息默认-->
</Host>
启动
[root@heayan bin]# startup.sh
停止
[root@heayan bin]# shutdown.sh

项目部署

将项目上传
[root@heayan /]# /usr/local/tomcat8501/webapps
[root@heayan webapps]# rz
配置server.xml
[root@heayan /] vi /usr/local/tomcat8501/conf/server.xml	
Host中添加如下信息
<Context path="/" docBase="/opt/www/www.heayan.com" reloadable="true" />

版权声明:版权所有,转载请注明原文地址。

  • Linux

    Linux 是一套免费使用和自由传播的类 Unix 操作系统,是一个基于 POSIX 和 Unix 的多用户、多任务、支持多线程和多 CPU 的操作系统。它能运行主要的 Unix 工具软件、应用程序和网络协议,并支持 32 位和 64 位硬件。Linux 继承了 Unix 以网络为核心的设计思想,是一个性能稳定的多用户网络操作系统。

    915 引用 • 931 回帖
  • 服务器

    服务器,也称伺服器,是提供计算服务的设备。由于服务器需要响应服务请求,并进行处理,因此一般来说服务器应具备承担服务并且保障服务的能力。

    124 引用 • 580 回帖
  • CentOS

    CentOS(Community Enterprise Operating System)是 Linux 发行版之一,它是来自于 Red Hat Enterprise Linux 依照开放源代码规定释出的源代码所编译而成。由于出自同样的源代码,因此有些要求高度稳定的服务器以 CentOS 替代商业版的 Red Hat Enterprise Linux 使用。两者的不同在于 CentOS 并不包含封闭源代码软件。

    238 引用 • 224 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...