发表于: 2016-06-23 14:46:32
1 2057
1、下载安装ssh客户端Xshell5,并远程登录linux服务器(参考:http://jingyan.baidu.com/article/295430f13fb4db0c7f005065.html)
2、安装mysql
我申请的服务器系统是Centos7,Centos7中用MariaDB代替了mysql数据库,所以安装mysql时默认的是MariaDB
安装过程:# yum -y install mariadb*(安装MariaDB)
# systemctl start mariadb.service (启动MariaDB)
# systemctl enable mariadb.service(设置开机启动)
# systemctl stop mariadb (停止MariaDB)
# systemctl restart mariadb (重启MariaDB)
# mysql(进入mysql)
exit (退出mysql)
# mysql_secure_installation (mysql安全配置)
Enter current password for root (enter for none): (初次运行直接回车)
Set root password? [Y/n] y (是否设置root用户密码,输入y并回车或直接回车)New password: (设置root用户的密码)Re-enter new password: (再输入一次你设置的密码)Remove anonymous users? [Y/n] y(是否删除匿名用户,生产环境建议删除,以直接回车)Disallow root login remotely? [Y/n] y(是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止)Remove test database and access to it? [Y/n] y(是否删除test数据库,直接回车)Reload privilege tables now? [Y/n] y(是否重新加载权限表,直接回车 ---至此,安全配置设置完毕)# mysql -uroot -p (登录mysql)
Enter password:quit;(退出mysql)
3、新建数据库和表
create database xztest1; use xztest1; drop table if EXISTS users2; create table users2( id int auto_increment primary key, name varchar(32), birth bigint, create_at bigint, update_at bigint, profession varchar(200) )ENGINE=InnoDB DEFAULT CHARSET=utf8; insert into users2(name,birth,create_at,update_at,profession) values ('tom',19910709,now(),now(),'java'); insert into users2(name,birth,create_at,update_at,profession) values ('mary',19930912,now(),now(),'c#');
4、安装JDK
# yum -y install java-1.7.0-openjdk
5、安装Jetty
# wget http://repo1.maven.org/maven2/org/eclipse/jetty/jetty-distribution/9.2.17.v20160517/jetty-distribution-9.2.17.v20160517.tar.gz(下载Jetty)
# tar zxvf jetty-distribution-9.2.17.v20160517.tar.gz -C /opt/(解压并移动下载的包到/opt)
# mv /opt/jetty-distribution-9.2.17.v20160517/ /opt/jetty (重命名文件夹名为jetty)
# useradd -m jetty(创建一个jetty用户)
# chown -R jetty:jetty /opt/jetty/(改变jetty文件夹的所属用户)
# ln -s /opt/jetty/bin/jetty.sh /etc/init.d/jetty(jetty.sh创建一个软链接到 /etc/init.d directory 来创建一个启动脚本文件)
# chkconfig --add jetty(添加脚本)
# chkconfig --level 345 jetty on(设置jetty在系统启动时启动)
# vi /etc/default/jetty(用vi文本编辑器打开 /etc/default/jetty 并修改端口和监听地址,vi编辑器用法参考:http://www.cnblogs.com/shenliang123/archive/2013/07/20/3202645.html)
JETTY_USER=jettyJETTY_HOME=/opt/jetty
JETTY_PORT=8080
JETTY_HOST=50.116.24.78JETTY_LOGS=/opt/jetty/logs/
# service jetty start(启动jetty服务)
输入 http://123.206.6.60:8080访问Jetty,显示如下
6、Maven install打包war文件,上传到服务器(详见:http://www.linuxidc.com/Linux/2014-10/108115.htm)
上传文件的方式有两种:
# yum install lrzsz(安装lrzsz工具包)
# rz(打开windowns的对话框,选择你要上传的文件)
② scp <本地文件名> <用户名>@<ssh服务器地址>:<上传保存路径即文件名> (写在本地终端)
scp task2.war root@123.206.6.60:/opt/jetty/webapps
7、启动Jetty,访问接口
8、安装nginx
# yum install nginx nginx.x86_64(安装 nginx)
# /bin/systemctl start nginx.servic(输入service nginx start提示:Redirecting to /bin/systemctl start nginx.service)(启动 nginx)
# /bin/systemctl stop nginx.service(输入service nginx stop 提示:Redirecting to /bin/systemctl stop nginx.service)(关闭 nginx)
输入http://123.206.6.60,显示:
9、修改nginx.conf配置文件
# nginx -t(查看nginx.conf配置文件路径,显示如下:)
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# cd /etc/nginx(进入nginx.conf所在目录)
# vi nginx.conf(用vi打开nginx.conf)
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location /task2/ {
root html;
index index.html index.htm;
proxy_pass http://123.206.6.60:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
10、#serivice jetty start
# /bin/systemctl start nginx.service
11、访问接口: http://123.206.6.60/task2/user/selectusers
12、查看nginx日志
cd /var/log/nginx
cat error.log(查看错误日志)
cat access.log(查看访问日志)
评论