跳过正文
  1. Posts/

系统安装部署手册

·792 字·4 分钟·
Kubehan
作者
Kubehan
云原生知识栈:深度解析容器技术、Kubernetes、Istio、DevOps 实践、Prometheus 监控、Envoy 代理、Golang 开发及云原生架构与微服务趋势的专业博客

系统安装部署手册
#

第一章 部署环境
#

1.1服务器配置
#

内核CPU型号CPU数量内存磁盘
Linux3.10Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz28G40G+160G

1.2系统环境参数
#

名称版本
OSCentos7
Jdk1.8
Mysql5.7
Tomcat9..0

第二章 MySQL安装
#

2.1安装准备
#

下载mysql文件,上传文件至/root/software/mysql目录,

并解压至/usr/local/

[root@db1 ~]# tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

重命名文件

[root@db1 ~]# cd /usr/local
[root@db1 ~]# mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql

2.2配置用户
#

创建mysql用户组

[root@db1 ~]# groupadd mysql

创建mysql用户

[root@db1 ~]# useradd –r –g -M mysql mysql 

进入mysql目录

[root@db1 ~]# cd /usr/local/mysql
[root@db1 ~]# cd /usr/local/mysql
[root@db1 mysql]# rm -rf data/*

修改mysql目录内的所有文件及目录的所有者为mysql,所属用户组为mysql

[root@db1 mysql]#chown –R mysql:mysql ./
[root@db1 mysql]# chown –R mysql:root ./data

2.3初始化MySQL
#

将配置文件复制到/etc目录

如果/etc目录下存在先备份

[root@cms1 mysql]# cp /etc/my.cnf /etc/my.cnf.bak

初始化之前修改my.cnf文件

修改mysql数据文件目录配置

basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
innodb_file_per_table=1
innodb_log_buffer_size = 10M
innodb_flush_log_at_trx_commit = 2
innodb_lock_wait_timeout = 50
innodb_buffer_pool_size = 500M
character-set-server=utf8
max_connections=1000
server-id=1
lower_case_table_names=1
socket=/tmp/mysql.sock
[root@db1 mysql]# ./bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

看到如下提示表示初始化

2018-06-14T10:19:46.415292Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-06-14T10:19:47.757098Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-06-14T10:19:47.965184Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-06-14T10:19:48.025349Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 774397af-6fbc-11e8-acd6-00163e0a1ee6.
2018-06-14T10:19:48.027372Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-06-14T10:19:48.031017Z 1 [Note] A temporary password is generated for root@db1: e5hvPoGZ;/du

记住生成的root密码

将mysql.server启动文件复制到/etc/init.d目录

/etc/init.d目录下的文件可以使用service命令操作

[root@db1 mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@db1 mysql]# chmod +x /etc/init.d/mysqld
[root@db1 mysql]# vim /etc/init.d/mysqld  ###调整启动脚本
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
[root@db1 mysql]# /etc/init.d/mysqld start
[root@db1 mysql]# ss -tnl|grep 3306
LISTEN   0   128     :::3306          :::*

2.4执行MySQL安全加固脚本
#

[root@db1 mysql]# ./bin/mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: N  ###是否启用密码复杂度检查插件
Securing the MySQL server deployment.
Enter password for user root:  ###输入临时密码
New password:  ###输入新密码
Remove anonymous users? (Press y|Y for Yes, any other key for No) :Y  ###移除匿名用户
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y  ###禁止root远程登录
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y  ###移除测试数据库
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y  ###重载权限表

2.5配置MySQL环境变量
#

[root@db1 mysql]# vim /etc/profile

添加

export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH

保存退出

使修改的环境变量生效

[root@db1 ~]# source /etc/profile

启动mysql

[root@db1 ~]#  service mysqld start

关闭mysql

[root@db1 ~]# service mysqld stop

重启mysql

[root@db1 ~]# service mysqld restart

查看mysql运行状态

[root@db1 ~]# service mysqld status

2.6设置开机启动
#

添加mysqld 到系统服务

[root@db1 ~]# chkconfig --add mysqld

查看mysqld添加到mysql的启动状态

[root@db1 ~]#chkconfig --list mysqld

mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭

注意:0-6表示mysql的运行级别,可以在/etc/inittab中查看系统包含的运行级别。

  0 - halt (Do NOT set initdefault to this)
  1 - Single user mode
  2 - Multiuser, without NFS (The same as 3, if you do not have networking)
  3 - Full multiuser mode
  4 - unused
  5 - X11
  6 - reboot (Do NOT set initdefault to this)

只需要3、5启动就行了,其它的不关心。

如果3、5运行级别没有设置开机启动,则需要添加3、5运行级别运行mysql

[root@db1 ~]#  chkconfig --level 35 mysqld on

Mysql****配置文件修改:

编辑配置文件

/etc/my.cnf

添加

[mysqld]
character_set_server=utf8  #修改数据库使用utf8编码
lower_case_table_names=1 #修改表名不区分大小写
max_allowed_packet = 1M  #主要影响insert内容的大小,适量修改
max_connections=1000   #mysql的最大连接数
innodb_file_per_table=1    #InnoDB引擎独立表空间

建立数据库应用帐号

mysql> grant all on *.* to "zcms"@"%" identified by "zving10301";  

第三章 JDK环境安装
#

3.1版本选择
#

jdk-8uXX

3.2安装
#

[root@web1 ~]#tar xf 755 jdk-8u171-linux-x64.tar.gz
[root@web1 ~]#mkdir /usr/java
[root@web1 ~]#mv jdk1.8.0_171 /usr/java/

3.3 配置环境变量
#

编辑/etc/profile
vim /etc/profile
添加
export JAVA_HOME=/usr/java/jdk1.8.0_171
export PATH=$JAVA_HOME/bin:$PATH
使配置生效
source /etc/profile

第四章 Tomcat安装
#

4.1 版本选择
#

apache-tomcat-9.0.xx.tar.gz

4.2 安装
#

解压文件到/usr/local/

tar -zxvf apache-tomcat-9.0.31.tar.gz -C /usr/local/

修改目录名

cd /usr/local/
mv apache-tomcat-9.0.31 tomcat

删除webapps目录下的所有文件

rm –rf /usr/local/tomcat/webapps/*

4.3 Tomcat开机启动配置
#

执行vim /etc/rc.d/init.d/tomcat ,添加以下内容

\#!/bin/bash
 \#
 \# /etc/rc.d/init.d/tomcat
 \# init script for tomcat precesses
 \#
 \# processname: tomcat
 \# description: tomcat is a j2se server
 \# chkconfig: 2345 86 16
 \# description: Start up the Tomcat servlet engine.

if [ -f /etc/init.d/functions ]; then
     . /etc/init.d/functions
 elif [ -f /etc/rc.d/init.d/functions ]; then
     . /etc/rc.d/init.d/functions
 else
     echo -e "/atomcat: unable to locate functions lib. Cannot continue."
     exit -1
 fi

RETVAL=$?

\#Tomcat目录
 CATALINA_HOME="/usr/local/tomcat"

case "$1" in
 start)
     if [ -f $CATALINA_HOME/bin/startup.sh ];
      then
       echo $"Starting Tomcat"
       $CATALINA_HOME/bin/startup.sh
     fi
     ;;
 stop)
     if [ -f $CATALINA_HOME/bin/shutdown.sh ];
      then
       echo $"Stopping Tomcat"
       $CATALINA_HOME/bin/shutdown.sh
     fi
     ;;
 *)
     echo $"Usage: $0 {start|stop}"
     exit 1
     ;;
 esac
exit $RETVAL

添加开机启动
\# chmod 775 /etc/rc.d/init.d/tomcat  #赋予文件执行权限
\# chkconfig --level 35 tomcat on  #设置开机启动
防火墙开放8080:端口
修改/etc/sysconfig/iptables
\# vim /etc/sysconfig/iptables
重启防火墙
\#service iptables restart

第五章 项目部署
#

上传项目程序war包到/usr/local/tomcat/weapps/下

将所有程序包上传至该目录,根据情况更改项目名称便于访问

解压程序包

unzip  *.war -d  ROOT

更改数据库连接信息

vim /usr/local/tomcat/webapps/web/WEB-INF/clas
ses/application-prop.yml

根据数据使用情况进行更改

数据导入

将数据库的sql文件上传至服务器/usr/local/tomcat/下

导入数据文件

mysqldump -uroot -ppassword databasename < /usr/local/*.sql

启动Tomcat

/usr/local/tomcat/bin/startup.sh

查看日志情况

tail -f  /usr/local/tomcat/logs/catalina.out

项目访问

打开浏览器输入地址IP:端口/项目名称