07 Linux

lix_uan
• 阅读 457

网卡设置

# vi /etc/sysconfig/network-scripts/ifcfg-ens33
# 先改 ONBOOT=yes, 连接xshell后再设置静态ip
# 修改完成后需要重启网络服务 systemctl restart network
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
IPADDR="192.168.50.132"        # 设置的静态IP地址
NETMASK="255.255.255.0"         # 子网掩码
GATEWAY="192.168.50.2"         # 网关地址
DNS1="192.168.50.2"            # DNS服务器
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=afd0baa3-8bf4-4e26-8d20-5bc426b75fd6
DEVICE=ens33
ONBOOT=yes
ZONE=public

安装JDK

tar -zxvf jdk-8u171-linux-x64.tar.gz -C /usr/local

vim /etc/profile

JAVA_HOME=/usr/local/jdk1.8.0_171
PATH=$JAVA_HOME/bin:$PATH

source /etc/profile

java -version

安装Tomcat

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

# 直接关闭防火墙
systemctl stop firewalld

# 或者开着防火墙,只放行端口号
firewall-cmd --zone=public --add-port=8080/tcp --permanent
# 重新加载防火墙
firewall-cmd --reload

# 启停服务
cd /usr/local/apache-tomcat-7.0.57/bin
./startup.sh

ps -ef|grep tomcat
kill -9 79947 

安装MySQL

# 查看是否已经安装过
rpm -qa | grep mysql
rpm -qa | grep mariadb    

# 卸载mariadb
rpm -e --nodeps  mariadb-libs-5.5.60-1.el7_5.x86_64


# 解压安装
tar -zxvf mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar.gz -C /usr/local/mysql

rpm -ivh mysql-community-common-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.25-1.el7.x86_64.rpm
yum install net-tools
rpm -ivh --nodeps mysql-community-server-5.7.25-1.el7.x86_64.rpm

# 启停
systemctl status mysqld
systemctl start mysqld
systemctl stop mysqld

# 开机自启
systemctl enable mysqld
# 查看初始密码
cat /var/log/mysqld.log | grep password

# 登录并修改密码
mysql -uroot -p    

set global validate_password_length=4;
set global validate_password_policy=LOW;
set password = password('root');

# 开启访问权限
grant all on *.* to 'root'@'%' identified by 'root';
flush privileges;

# 防火墙开着的话要放行3306端口windows上才能访问
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

安装lrzsz

yum install -y lrzsz

# 上传到Linux
rz

# 从Linux下载到windows
sz 文件名

手动部署项目

# 后台运行 java -jar 命令,并将日志输出到hello.log文件
nohup java -jar helloworld-1.0-SNAPSHOT.jar &> hello.log &

# 停止项目
ps -ef | grep java 
kill -9

shell脚本自动化部署

# 安装git
yum install -y git

# 克隆代码
git clone https://gitee.com/ChuanZhiBoKe/helloworld.git

# 安装Maven
tar -zxvf apache-maven-3.5.4-bin.tar.gz -C /usr/local

vim /etc/profile

export MAVEN_HOME=/usr/local/apache-maven-3.5.4
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH

source /etc/profile

# 修改仓库地址并配置阿里云镜像
cd /usr/local/apache-maven-3.5.4/conf
vim settings.xml

<localRepository>/usr/local/repo</localRepository>
<mirror> 
    <id>alimaven</id> 
    <mirrorOf>central</mirrorOf> 
    <name>aliyun maven</name> 
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror> 
# 上传shell脚本bootStart.sh

#!/bin/sh
echo =================================
echo  自动化部署脚本启动
echo =================================

echo 停止原来运行中的工程
APP_NAME=HelloWorld

tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'Stop Process...'
    kill -15 $tpid
fi
sleep 2
tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`
if [ ${tpid} ]; then
    echo 'Kill Process!'
    kill -9 $tpid
else
    echo 'Stop Success!'
fi

echo 准备从Git仓库拉取最新代码
cd /root/app/hello-world

echo 开始从Git仓库拉取最新代码
git pull
echo 代码拉取完成

echo 开始打包
output=`mvn clean package -Dmaven.test.skip=true`

cd target

echo 启动项目
nohup java -jar demo-0.0.1-SNAPSHOT.jar &> demo.log &
echo 项目启动完成
# 添加权限并执行脚本
chmod 777 bootStart.sh
./bootStart.sh
点赞
收藏
评论区
推荐文章

暂无数据

lix_uan
lix_uan
Lv1
学无止境,即刻前行
文章
7
粉丝
7
获赞
0