快速安装部署CentOS7 64位环境(jdk1.8+Tomcat9+Openresty+mariaDB)

16 篇文章 0 订阅
15 篇文章 0 订阅

安装内容:

1) 关闭SELinex

2)禁用防火墙

3)安装Jdk1.8.0_181

4)安装Tomcat9.0.10

5)安装Openresty

6)安装MariaDB

7)配置开机启动Tomcat

8)配置开机启动Openresy的Nginx

 

 

具体如下:

1) 关闭SELinex

参看:https://blog.csdn.net/xinluke/article/details/51925293

查看

[root@dev-server ~]# getenforce
Disabled
[root@dev-server ~]# /usr/sbin/sestatus -v
SELinux status:                 disabled

临时关闭

##设置SELinux 成为permissive模式
##setenforce 1 设置SELinux 成为enforcing模式
setenforce 0

永久关闭

vi /etc/selinux/config

将SELINUX=enforcing改为SELINUX=disabled 
设置后需要重启才能生效

 

2)禁用防火墙

参看:https://www.cnblogs.com/moxiaoan/p/5683743.html

1、firewalld的基本使用

启动: systemctl start firewalld

关闭: systemctl stop firewalld

查看状态: systemctl status firewalld 

开机禁用  : systemctl disable firewalld

开机启用  : systemctl enable firewalld

 

3)安装Jdk1.8.0_181

参看:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

mkdir -p /data/local/java

cd /data/local/java

《将下载的jdk-8u181-linux-x64.tar.gz放到/data/local/java目录中》

tar -zxvf jdk-8u181-linux-x64.tar.gz
vi /etc/profile

export JAVA_HOME=/data/local/java/jdk1.8.0_181
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export  PATH=${JAVA_HOME}/bin:$PATH
source /etc/profile

4)安装Tomcat9.0.10

参看:https://tomcat.apache.org/download-90.cgi

cd /data/local/

wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.10/bin/apache-tomcat-9.0.10.tar.gz

tar -zxvf apache-tomcat-9.0.10.tar.gz

《配置tomcat的Jdk》

vi /data/local/apache-tomcat-9.0.10/bin/setenv.sh 

添加几行内容:

#!/bin/sh

export JAVA_HOME=/data/local/java/jdk1.8.0_181/
export JRE_HOME=/data/local/java/jdk1.8.0_181/jre/
export CATALINA_HOME=/data/local/apache-tomcat-9.0.10/
export CATALINA_BASE=/data/local/apache-tomcat-9.0.10/
#设置Tomcat的PID文件
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
#添加JVM选项
JAVA_OPTS="-Xms1024m -Xmx2048m"

《配置tomcat的端口号》

也可以不修改,保持默认的8080

如果要修改做如下命令

vi /data/local/apache-tomcat-9.0.10/conf/server.xml

 

启动命令

nohup /data/local/apache-tomcat-9.0.10/bin/start.sh

 

 

 

5)安装Openresty

参看:http://wiki.jikexueyuan.com/project/openresty/openresty/install_on_centos.html

sudo yum-config-manager --add-repo https://openresty.org/yum/cn/centos/OpenResty.repo
sudo yum install openresty
 

 

6)安装MariaDB

参看:https://blog.csdn.net/u013488847/article/details/81265998

1.使用rpm -qa | grep mariadb搜索 MariaDB 现有的包:

如果存在,使用rpm -e --nodeps mariadb-*全部删除:

rpm -qa | grep mariadb

rpm -e --nodeps mariadb-*

 

2.使用rpm -qa | grep mariadb搜索 MariaDB 现有的包:

如果存在,使用yum remove mysql mysql-server mysql-libs compat-mysql51全部删除;

 

3.开始新的安装, 创建MariaDB.repo文件

vi /etc/yum.repos.d/MariaDB.repo

[mariadb]
name = MariaDB
baseurl = http://mirrors.ustc.edu.cn/mariadb/yum/10.4/centos7-amd64/
gpgkey=http://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1

4.运行安装命令安装MariaDB

yum -y install MariaDB-server MariaDB-client

 

首先下载安装包,然后进行自动安装,安装成功之后启动MariaDB服务。

systemctl start mariadb #启动服务
systemctl enable mariadb #设置开机启动
systemctl restart mariadb #重新启动
systemctl stop mariadb.service #停止MariaDB

systemctl start mariadb #启动服务
systemctl enable mariadb #设置开机启动
systemctl restart mariadb #重新启动
systemctl stop mariadb.service #停止MariaDB

systemctl status mariadb #查看服务状态

 

5.登录到数据库

  用mysql -uroot命令登录到MariaDB,此时root账户的密码为空。

mysql -uroot -p
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'xxxxxx' WITH GRANT OPTION;
FLUSH PRIVILEGES;

 

6.进行MariaDB的相关简单配置,使用mysql_secure_installation命令进行配置。

配置文件如下:

/etc/my.cnf

/etc/my.cnf.d/mysql-clients.cnf

/etc/my.cnf.d/server.cnf

/etc/my.cnf.d/client.cnf

 

其中,要修改的就后面三个文件

 

/etc/my.cnf.d/mysql-clients.cnf

#
# These groups are read by MariaDB command-line tools
# Use it for options that affect only one utility
#

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates


[mysql_upgrade]

[mysqladmin]

[mysqlbinlog]

[mysqlcheck]

[mysqldump]
quick
max_allowed_packet = 16M

[mysqlimport]

[mysqlshow]

[mysqlslap]
 

/etc/my.cnf.d/server.cnf

#
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#

# this is read by the standalone daemon and embedded servers
[server]

# this is only for the mysqld standalone daemon
[mysqld]
port        = 3306
socket        = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M

character_set_server = utf8mb4
event_scheduler=ON
init_connect='SET NAMES utf8mb4'

log-error = /usr/local/mysql/log/error.log
general-log-file = /usr/local/mysql/log/mysql.log
lower_case_table_name=1
max_connections = 1000

#slow query 
slow-query-log=1
slow-query-log-file=/usr/local/mysql/log/slowquery.log
long_query_time=2

# Point the following paths to different dedicated disks
#tmpdir        = /tmp/

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!

#skip-networking

# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin

# binary logging format - mixed recommended
binlog_format=mixed

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id    = 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
#    the syntax is:
#
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;
#
#    where you replace <host>, <user>, <password> by quoted strings and
#    <port> by the master's port number (3306 by default).
#
#    Example:
#
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
#    MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
#    start replication for the first time (even unsuccessfully, for example
#    if you mistyped the password in master-password and the slave fails to
#    connect), the slave will create a master.info file, and any later
#    change in this file to the variables' values below will be ignored and
#    overridden by the content of the master.info file, unless you shutdown
#    the slave server, delete master.info and restart the slaver server.
#    For that reason, you may want to leave the lines below untouched
#    (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id       = 2
#
# The replication master for this slave - required
#master-host     =   <hostname>
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user     =   <username>
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password =   <password>
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port     =  <port>
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/data
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/data
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

#
# * Galera-related settings
#
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0

# this is only for embedded server
[embedded]

# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]

# This group is only read by MariaDB-10.3 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.3]

/etc/my.cnf.d/client.cnf
[client]
#password    = your_password
port        = 3306
socket        = /tmp/mysql.sock
default-character-set = utf8mb4
 

 

dump备份/mysql还原数据库

 

参看:https://blog.csdn.net/u010098331/article/details/50896175

备份数据库

"D:\tools\MariaDB 10.2\bin\mysqldump" -uroot -p xxx_site > d:/websites/dumpsvs0729.sql

 

还原数据库

mysql -uroot -hlocalhost -p'xxxx' -P3306 -databases test xxx_site < /data/local/db/dumpsvs0729.sql

 

7)配置开机启动Tomcat

参看:https://blog.csdn.net/u012351661/article/details/76254268

假设Tomcat的安装路径为/data/local/apache-tomcat-9.0.10

1 为Tomcat添加启动参数

catalina.sh在执行的时候会调用同级路径下的setenv.sh来设置额外的环境变量,因此在/opt/tomcat/bin路径下创建setenv.sh文件,内容如下:

vi /data/local/apache-tomcat-9.0.10/bin/setenv.sh

#!/bin/sh

export JAVA_HOME=/data/local/java/jdk1.8.0_181/
export JRE_HOME=/data/local/java/jdk1.8.0_181/jre/
export CATALINA_HOME=/data/local/apache-tomcat-9.0.10/
export CATALINA_BASE=/data/local/apache-tomcat-9.0.10/
#设置Tomcat的PID文件
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
#添加JVM选项
JAVA_OPTS="-Xms1024m -Xmx2048m"

chmod 755 /data/local/apache-tomcat-9.0.10/bin/setenv.sh


2 编写tomcat.service文件

先创建并保存一个tomcat.pid

vi /data/local/apache-tomcat-9.0.10/tomcat.pid

chmod 775 tomcat.pid


在/usr/lib/systemd/system路径下添加tomcat.service文件,内容如下:

vi /usr/lib/systemd/system/tomcat.service

[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/data/local/apache-tomcat-9.0.10/tomcat.pid
ExecStart=/data/local/apache-tomcat-9.0.10/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

##[unit]配置了服务的描述,规定了在network启动之后执行,
##[service]配置服务的pid,服务的启动,停止,重启
##[install]配置了使用用户
 


3 将Tomcat加入服务管理

systemctl enable tomcat.service
systemctl disable tomcat.service
systemctl start tomcat.service
systemctl stop tomcat.service

systemctl restart tomcat.service

 

 

8)配置开机启动Openresy的Nginx

参看:http://stevendu.iteye.com/blog/2269166

vi /usr/lib/systemd/system/nginx.service

[Service]
Type=forking
PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

systemctl daemon-reload

systemctl enable nginx.service

systemctl start nginx.service

systemctl stop nginx.service

systemctl status nginx.service

systemctl restart nginx.service

 

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值