问答平台(8),阿里云部署

部署环境

部署环境-图示

centos 版本

cat /etc/redhat-release

阿里云服务器控制台

重置实例密码(智慧校园)

Xshell

连接到云服务器

Xftp

连接到云服务器

unzip

1
2
yum list unzip*
yum install -y unzip.x86_64

JDK

1
2
3
yum list java*
yum install -y java-1.8.0-openjdk.x86_64(JRE)
yum install -y java-1.8.0-openjdk-devel(JDK)

maven

1
2
3
4
5
6
7
8
tar -zvxf apache-maven-3.6.3-bin.tar.gz -C /opt
vim /etc/profile
export PATH=$PATH:/opt/apache-maven-3.6.3/bin
source /etc/profile
echo $PATH
mvn -version
cd conf/
vim settings.xml
  • settings.xml
    1
    2
    3
    4
    5
    6
    <mirror>
    <id>alimaven</id>
    <mirrorOf>central</mirrorOf>
    <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
    </mirror>

mysql

  • 安装
    1
    2
    3
    4
    5
    6
    7
    8
    cd /
    yum list mysql*
    cd /root
    ll
    yum install -y mysql80-community-release-el7-3.noarch.rpm
    cd /
    yum list mysql*
    yum install -y mysql-community-server.x86_64
  • 修改 root 用户密码
    1
    2
    3
    4
    5
    systemctl start mysqld
    systemctl status mysqld
    grep 'password' /var/log/mysqld.log
    mysql -u root -p
    alter user root@localhost identified by 'xxx';
  • 数据库文件初始化
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    cd /root
    ll
    unzip -d /root community-init-sql.zip
    mysql -u root -p
    create database community;
    use community;
    source /root/community-init-sql/init_schema.sql
    source /root/community-init-sql/init_data.sql
    source /root/community-init-sql/tables_mysql_innodb.sql
    show tables;
    select id, username, header_url from user;

redis

  • 安装
    1
    2
    3
    cd /
    yum list redis*
    yum install -y redis.x86_64
  • 启动
    1
    2
    systemctl start redis
    systemctl status redis

kafka

  • 安装
    1
    2
    3
    cd /root/
    ll
    tar -zvxf kafka_2.12-2.2.0.tgz -C /opt
  • 配置
    1
    2
    3
    4
    5
    cd /opt/kafka_2.12-2.2.0/
    ll
    cd config/
    vim zookeeper.properties
    vim server.properties
  • 启动
    1
    2
    3
    4
    5
    pwd
    cd ..
    bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
    nohup bin/kafka-server-start.sh config/server.properties 1>/dev/null 2>&1 &
    bin/kafka-topics.sh --list --bootstrap-server localhost:9092

elasticsearch

  • 安装
    1
    2
    3
    4
    cd /root/
    ll
    tar -zvxf elasticsearch-6.4.3.tar.gz -C /opt
    unzip -d /opt/elasticsearch-6.4.3/plugins/ik elasticsearch-analysis-ik-6.4.3.zip
  • 配置
    1
    2
    cd /opt/elasticsearch-6.4.3
    cd config/
  • elasticsearch.yml
    1
    2
    3
    cluster.name: nowcoder
    path.data: /tmp/elasticsearch/data
    path.logs: /tmp/elasticsearch/logs
  • vim jvm.options
    1
    2
    -Xms256m
    -Xmx512m
  • 用户
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    groupadd nowcoder
    useradd nowcoder1 -p 123456 -g nowcoder
    cd /opt
    chown -R nowcoder1:nowcoder *
    cd /tmp
    chown -R nowcoder1:nowcoder *
    su - nowcoder1
    clear
    cd /opt/elasticsearch-6.4.3/
    bin/elasticsearch -d(后台启动)
    su -
    curl -X GET "localhost:9200/_cat/health?v"
    elasticsearch正常-图示

wkhtmltopdf

  • 安装
    1
    2
    3
    4
    5
    cd /
    yum list wkhtmltopdf*
    yum install -y wkhtmltopdf.x86_64
    yum list *xvfb*
    yum install -y xorg-x11-server-Xvfb.x86_64
  • 测试
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    cd /root/test/
    ll
    xvfb-run --server-args="-screen 0, 1024x768x24" wkhtmltopdf http://www.aliyun.com 1.png
    ll
    cd /opt
    vim wkhtmltoimage.sh
    xvfb-run --server-args="-screen 0, 1024x768x24" wkhtmltoimage "$@"
    ll
    chmod +x wkhtmltoimage.sh
    ll
    cd /root/test/
    /opt/wkhtmltoimage.sh http://www.aliyun.com 2.png

tomcat

  • 安装
    1
    2
    3
    cd /root
    ll
    tar -zvxf apache-tomcat-9.0.31.tar.gz -C /opt
  • 配置
    1
    2
    3
    4
    5
    6
    cd /opt/apache-tomcat-9.0.31/
    cd bin/
    pwd
    vim /etc/profile
    source /etc/profile
    echo $PATH
    /etc/profile
    1
    export PATH=$PATH:/opt/apache-tomcat-9.0.31/bin
  • 启动
    1
    2
    3
    4
    5
    startup.sh
    cd /opt/apache-tomcat-9.0.31/
    ll
    cd webapps/
    ll

安全组问题

安全组-图示
阿里云Tomcat-图示

nginx

  • 安装
    1
    2
    3
    cd /
    yum list nginx*
    yum install -y nginx.x86_64
  • 配置
    1
    vim /etc/nginx/nginx.conf
    nginx.conf
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    upstream myserver {
    server 127.0.0.1:8080 max_fails=3 fail_timeout=30s;
    }

    server {
    listen 80;
    server_name 47.93.84.81/;
    location / {
    proxy_pass http://myserver;
    }
    }
  • 启动
    1
    2
    systemctl start nginx
    systemctl status nginx

部署原理

部署原理-图示

tomcat

1
2
3
4
5
shutdown.sh
cd /opt/apache-tomcat-9.0.31/
ll
rm -rf *(删除所有示例)
ll

修改代码

  • application-produce.properties
  • global.js
  • HomeController
  • pom.xml
  • application.properties
  • application-produce.properties
  • logback-spring-produce.xml
  • CommunityServletInitializer

正式部署

  • mvn 打包
    1
    2
    3
    4
    cd /root
    unzip -d /root community-deploy-Aliyun.zip
    cd community
    mvn clean package -Dmaven.test.skip=true(忽略测试,第一次会下载比较慢)

mvn打包成功-图示

  • tomcat 部署项目
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    ll
    cd target/
    ll
    mv ROOT.war /opt/apache-tomcat-9.0.31/webapps/
    ll
    cd /opt/apache-tomcat-9.0.31/webapps/
    ll
    startup.sh
    cd ..
    ll
    cd logs/
    vim catalina.2020-06-16.log
    cd /tmp
    cd /community
    ll
    tmp目录-图示

项目部署日志

项目部署日志-图示
部署日志报错-图示

云服务器访问异常

1
2
http://47.93.84.81:8080/(正常访问)
http://47.93.84.81/

安全组重新设置后,生效时间问题?
云服务器重启后,nginx 没启动…

发帖测试

能点赞,redis 正常。
发帖测试-图示

消息测试

能收发消息,kafka 正常。
消息测试-图示

搜索测试

elasticsearch 异常,后来证明是内存不够,待解决。热帖排行,使用 elasticsearch,也异常。
解决方法:CentOS开启虚拟内存

修改头像

修改头像成功,wkhtmltoimage、七牛云正常。
修改头像-图示

参考资料


问答平台(8),阿里云部署
https://lcf163.github.io/2020/06/28/问答平台(8),阿里云部署/
作者
乘风的小站
发布于
2020年6月28日
许可协议