記錄阿里雲ECS伺服器Java開發環境的搭建過程
阿新 • • 發佈:2019-01-05
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 指令
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的世界,你永遠少不了更復雜的配置,這些將會在日後的開發過程中遇到。