记录阿里云ECS服务器Java开发环境的搭建过程

时间:2022-05-03 13:00:40

1、新增用户admin,添加权限到wheel组

adduser admin
passwd admin
gpasswd -a admin wheel

参考:https://www.digitalocean.com/community/tutorials/initial-server-setup-with-centos-7

2、更新yum源

参考:http://help.aliyun.com/knowledge_detail.htm?knowledgeId=5974184

yum update

3、安装nginx

yum install nginx 

配置文件路径:/etc/nginx

4、systemctl 指令

http://cnzhx.net/blog/centos-7-rhel-7-systemd-commands/

5、Java环境安装

wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie;"  http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45-linux-x64.rpm

rpm -ivh jdk-8u45-linux-x64.rpm

/usr/java/jdk1.8.0_45

vi /etc/profile

export JAVA_HOME=/usr/java/jdk1.8.0_45
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

source /etc/profile

6、Tomcat的安装和配置

cd /usr

wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.0.23/bin/apache-tomcat-8.0.23.tar.gz
tar -xzvf apache-tomcat-8.0.23.tar.gz

安装目录:/usr/apache-tomcat-8.0.23

配置:
<Host name="localhost" appBase="/home/admin/webapps" unpackWARs="true" autoDeploy="true">

<Context path="/" docBase="application" reloadable="true"/>

</Host>

7、一些便捷操作

ln -s /usr/apache-tomcat-8.0.23/bin/startup.sh /home/admin/bin/start_tomcat.sh
ln -s /usr/apache-tomcat-8.0.23/bin/shutdown.sh /home/admin/bin/stop_tomcat.sh

ln -s /usr/apache-tomcat-8.0.23/logs /home/admin/logs/tomcat

nginx_status.sh:

#!/bin/sh
exec /bin/systemctl status nginx.service

restart_nginx.sh:

#!/bin/sh
exec /bin/systemctl restart nginx.service

nginx_stop.sh:

#!/bin/sh
exec /bin/systemctl stop nginx.service

8、nginx配置

/etc/nginx/nginx.conf:

user nginx;
worker_processes 4;

error_log /home/admin/logs/nginx/error.log;

pid /run/nginx.pid;


events
{
worker_connections 10240;
}


http
{
include /etc/nginx/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 /home/admin/logs/nginx/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

gzip on;

index index.html index.htm;

upstream tomcat_server{
server 127.0.0.1:8080 weight=1;
}


include /etc/nginx/conf.d/*.conf;
}

/etc/nginx/conf.d/www.nzaom.com.conf:

server
{
listen 80 default_server;
server_name www.nzaom.com nzaom.com nzaom.hehuyou.com;

charset utf-8;
access_log /home/admin/logs/nginx/access.log main;

location / {
root /home/admin/webapps;
proxy_pass http://tomcat_server;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}


error_page 404 /error.htm;

# redirect server error pages to the static page /50x.html
#
}

以上这些都是基础配置,相关参数还待优化。当然,进入了Java的世界,你永远少不了更复杂的配置,这些将会在日后的开发过程中遇到。