mkdir /opt/jdk
# 配置jdk环境变量
vi /etc/profile
export JAVA_HOME=/opt/jdk/jdk1.8.0_191;
export PATH=$PATH:$JAVA_HOME/bin;
export CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jar
#使配置生效
source profile
[root@VM_0_10_centos jdk1.8.0_191]# java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
[root@VM_0_10_centos jdk1.8.0_191]#
tar -zxvf apache-tomcat-7.0.99.tar.gz -C /opt
mv apache-tomcat-7.0.99/ tomcat
cd /opt/tomcat/bin
./start.sh
./shutdown.sh
或者通过ps -ef |java 命令查找进程,然后kill掉
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
执行完成后会在/etc/yum.repos.d/目录下生成两个repo文件mysql-community.repo mysql-community-source.repo
SHOW VARIABLES LIKE 'validate_password%';
set global validate_password_policy=LOW;
ALTER USER 'root'@'*' IDENTIFIED BY '123456';
grant all privileges on *.* to root@"*" identified by "123456789";
flush privileges;
启动mysql
systemctl start mysqld
重启
systemctl restart mysqld
关闭
systemctl stop mysqld
查看启动状态
systemctl status mysqld
设置(开启/关闭)开机启动
systemctl enable/disable mysqld
查看版本
select version();
vi /etc/my.cnf
#添加 [mysqld] character_set_server=utf8 init_connect='SET NAMES utf8'
配置文件:/etc/my.cnf 日志文件:/var/log//var/log/mysqld.log 服务启动脚本:/usr/lib/systemd/system/mysqld.service socket文件:/var/run/mysqld/mysqld.pid
update user set authentication_string=password('123') where user='root';
tar -zxvf nginx-1.14.2.tar.gz -C /opt/nginx-1.14.2
出现错误
./configure: error: C compiler cc is not found
出现这个错误,是因为gcc包没有安装
yum -y install gcc
出现错误:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.
执行
# yum -y install pcre-devel
如果报错:
Require the zlib library
则执行安装
# yum install -y zlib-devel
make
make install
找到nginx安装目录
whereis nginx
nginx:/usr/local/nginx
在/etc/profile 中加入配置
# vi /etc/profile
在配置文件中加入:
#nginx configure
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
使配置生效
# source /etc/profile
# cd /usr/local/nginx
# nginx -c conf/nginx.conf
启动成功后,将在浏览器打开 ip加端口号 默认端口号是80
9. 启动、停止nginx 命令如下
cd /usr/local/nginx/sbin/
./nginx 启动
./nginx -t 测试nginx配置是否正确
./nginx -s stop此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。
./nginx -s quit此方式停止步骤是待nginx进程处理任务完毕进行停止。
./nginx -s reload 重新加载nginx配置
查询nginx进程:
ps aux|grep nginx
cd /usr/local/src/nginx-1.11.3
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
server {
listen 443;
server_name domain;
ssl on;
ssl_certificate /soft/domain.crt;
ssl_certificate_key /soft/server0228.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
client_max_body_size 16m;
client_body_buffer_size 128k;
proxy_pass http://domain;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_next_upstream off;
proxy_connect_timeout 30;
proxy_read_timeout 300;
proxy_send_timeout 300;
}
}
cd /opt/nginx/nginx-1.14.2/src/
wget https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/master.tar.gz
tar -zcxf master.tar.gz
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/opt/nginx/nginx-1.14.2/src/nginx-sticky
/usr/local/nginx/sbin/nginx –V
service nginx stop
cd /usr/local/nginx-1.12.2
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
cd /usr/local/nginx/sbin
mv nginx nginx.old
//执行make之后再src目录下面的objs下会生成一个nginx文
件,需要替换开始的文件
cp /usr/local/nginx-1.12.2/objs/nginx ./
upstream domain
{
sticky;
server serverip1:8080 weight=5 max_fails=2 fail_timeout=30s;
server serverip2:8080 weight=5 max_fails=2 fail_timeout=30s;
}
因为集群部署的话就需要有文件共享目录,因为没有使用阿里云的oss服务,所以只能自己通过ntf方式共享文件夹
rpm –qa|grep nfs
rpm –qa|grep portmap
yum install nfs-utils rpcbind
vi /etc/exports
输入
/sharedata 192.168.0.1(rw)次
/sharedata 192.168.0.2(rw) 主
mkdir sharedata
chmod -R 777 sharedata
service rpcbind start
service nfs start
service rpcbind status
service nfs status
service rpcbind start
service nfs start
service rpcbind status
service nfs status
showmount -e 192.168.0.1
mkdir /sharedata
chmod –R 777 /sharedata
mount -t nfs -o nolock,nfsvers=3,vers=3 192.168.0.1:/home/adam/static
/sharedata /sharedata
注意共享目录子权限问题。
cp -rf /opt/tomcat/webapps/appName /usr/local/nginx/html/
删除WEB-INF
rm -rf WEB-INF/
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
client_header_buffer_size 128k;
client_body_buffer_size 1m;
proxy_buffer_size 32k;
proxy_buffers 64 32k;
proxy_busy_buffers_size 1m;
proxy_temp_file_write_size 512k;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
keepalive_timeout 65;
gzip on;
upstream domain
{
sticky;
server ip:port weight=5 max_fails=2 fail_timeout=30s;
server ip:port weight=5 max_fails=2 fail_timeout=30s;
}
server {
listen 80;
server_name domain;
location / {
proxy_pass http://ip:port/appName/;
proxy_cookie_path /appName /;
}
location ~/appName/.*\.(js|css|ico|png|jpg|eot|svg|ttf|woff)?$
{
root /usr/local/nginx/html;
expires 30d;
}
location ~/appName/ {
proxy_pass http://ip:port;
proxy_cookie_path /appName / ;
proxy_connect_timeout 500s;
proxy_read_timeout 500s;
proxy_send_timeout 500s;
client_max_body_size 20m;
}
#另一个应用
location /forms_tb_client/login/{
proxy_pass http://ip2:port2;
}
rewrite ^(.*)$ https://$host$1 permanent;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
# HTTPS server
server {
listen 443;
server_name domain;
ssl on;
ssl_certificate /soft/domain.crt;
ssl_certificate_key /soft/server0228.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
client_max_body_size 16m;
client_body_buffer_size 128k;
proxy_pass http://domain;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_next_upstream off;
proxy_connect_timeout 30;
proxy_read_timeout 300;
proxy_send_timeout 300;
}
}
}
以上就是整个应用服务器搭建、部署过程,其中https申请的过程会根据不同的证书颁发机构不同,生成现有文件的过程也不同,其中阿里云上面还提供免费的证书,如果不是很正式的项目可以在阿里云上申请一个免费的https证书试一下。我另一篇文章会写一下处理https证书的过程以及踩得坑。