centos7安装教程备份
一,centos 网络选择
ping www.baidu.com 如果无网络
---开启centos7网络
打开 /etc/sysconfig/network-scripts/ifcfg-enp0s3 文件,将 ONBOOT 改为 yes
重新启动网络:
systemctl start network.service / service network restart
ping www.baidu.com ok 说明网络ok
---查看ip地址
ip addr
ifconfig
yum search ifconfig
yum install net-tools.x86_64
二,虚拟机下CentOS7开启SSH连接
ps aux | grep sshd
1、yum list installed | grep openssh-server
此处显示已经安装 如果未安装 执行下面语句安装
yum install openssh-server
2、 找到了 /etc/ssh/ 目录下的sshd服务配置文件 sshd_config,用vi编辑器打开
打开端口
然后开启允许远程登录
开启使用用户名密码来作为连接验证
开启 sshd 服务,输入 sudo service sshd start
检查 sshd 服务是否已经开启,输入ps -e | grep sshd
或者输入netstat -an | grep 22 检查 22 号端口是否开启监听
为了免去每次开启 CentOS 时,都要手动开启 sshd 服务,可以将 sshd 服务添加至自启动列表中,输入systemctl enable sshd.service
可以通过输入systemctl list-unit-files | grep sshd,查看是否开启了sshd 服务自启动
三,防火墙
开启防火墙命令:
systemctl start firewalld.service
重启防火墙命令:
firewall-cmd --reload 或者 service firewalld restart 添加
firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
firewall-cmd --add-port=80/tcp --permanent
删除
firewall-cmd --zone= public --remove-port=80/tcp --permanent
查看
firewall-cmd --zone=public --query-port=80/tcp查看端口列表:
firewall-cmd --permanent --list-port
#3306/tcp 80/tcp 禁用防火墙
systemctl stop firewalld
设置开机启动
systemctl enable firewalld
停止并禁用开机启动
systemctl disable firewalld
查看状态
systemctl status firewalld或者 firewall-cmd --state-----------------------------------------------------------------------------------------------------------------------------------------------------
CentOS 7 开放防火墙端口 命令 最近公司新的server要求用CentOS7, 发现以前CentOS 6 系列中的 iptables 相关命令不能用了,查了下,发现Centos 7使用firewalld代替了原来的iptables。
使用方法如下:
>>> 关闭防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动>>> 开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
>>> 重启防火墙
firewall-cmd --reload常用命令介绍
firewall-cmd --state ##查看防火墙状态,是否是running
firewall-cmd --reload ##重新载入配置,比如添加规则之后,需要执行此命令
firewall-cmd --get-zones ##列出支持的zone
firewall-cmd --get-services ##列出支持的服务,在列表中的服务是放行的
firewall-cmd --query-service ftp ##查看ftp服务是否支持,返回yes或者no
firewall-cmd --add-service=ftp ##临时开放ftp服务
firewall-cmd --add-service=ftp --permanent ##永久开放ftp服务
firewall-cmd --remove-service=ftp --permanent ##永久移除ftp服务
firewall-cmd --add-port=80/tcp --permanent ##永久添加80端口
iptables -L -n ##查看规则,这个命令是和iptables的相同的
man firewall-cmd ##查看帮助更多命令,使用 firewall-cmd --help 查看帮助文件
重新开启防火墙:Failed to start firewalld.service: Unit firewalld.service is masked 问题解决:
>>> CentOS 7.0默认使用的是firewall作为防火墙,使用iptables必须重新设置一下
1、直接关闭防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动2、设置 iptables service
yum -y install iptables-services
如果要修改防火墙配置,如增加防火墙端口3306
vi /etc/sysconfig/iptables
增加规则
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT保存退出后
systemctl restart iptables.service #重启防火墙使配置生效
systemctl enable iptables.service #设置防火墙开机启动
最后重启系统使设置生效即可。四,centos 安装 上传下载工具
自带scp
scp -i /Users/nealzhang/Desktop/hub.pem /Users/nealzhang/Desktop/vmz-ca/my自己生成/* ec2-user@18.159.63.174:/home/ec2-user
---lrzsz
yum install lrzsz -y
rpm -qa |grep lrzsz
上传文件的执行命令:
#rz 如果覆盖原文件,执行:
#rz -y 下载文件,执行:
#sz {文件}五,查看端口
查询端口
netstat -tunlp | grep :3306ps -ef | grep redis
kill -9 PID
kill -15 PID进程号PID
ps aux
关闭进程号
kill -9 PID六,测试端口
telnet 192.168.1.119 3306
七,后台运行jar
后台运行jar包方法:
1、nohup java -jar shareniu.jar &
nohup意为后台不挂断运行,与是否账号退出无关
2、nohup java -jar shareniu.jar >spring.log &
后台运行,并将相关日志输出到spring.log
&代表在后台运行。
nohup 意思是不挂断运行命令,当账户退出或终端关闭时,程序仍然运行运行:
nohup java -jar live-1.0.0.jar --spring.profiles.active=prod & nohup java -jar vmz-innogy.jar --spring.profiles.active=prod > nohuplog.log 2>&1 &
---
上面的2 和 1 的意思如下:
0 标准输入(一般是键盘)
1 标准输出(一般是显示屏,是用户终端控制台)
2 标准错误(错误信息输出)
将运行的jar 错误日志信息输出到log.file文件中,然后(>&1)就是继续输出到标准输出(前面加的&,是为了让系统识别是标准输出),最后一个&,表示在后台运行。 结束后台!!!!!
ps -ef | grep live通过ps aux命令查看进程号PID,然后执行 kill -9 PID
如果是前台进程的话,直接执行 Ctrl+c 就可以终止了
八,idea http请求实例
### 情报、前瞻支付
POST http://localhost:7771/content/pay
Content-Type: application/x-www-form-urlencodedcontentId=999
### 首页
POST http://localhost:7771/pc/banner/getBannerList
Content-Type: application/json{
"type":"1",
"bannerType":"555"
}###app比赛详情情报
GET http://localhost:7771/app/query/match/information?matchId=1111
###
GET http://localhost:7771/app/query/match/information/111
###
POST http://localhost:9092/userSessionStatView/visit/data
Content-Type: application/x-www-form-urlencodedstart='2019-03-19 00'
end='2019-03-19 23'<> 2019-03-19T022151.200.json
### 测试ok 表单提交
POST http://localhost:9092/userSessionStatView/content/pay
Content-Type: application/x-www-form-urlencoded
userId: 10contentId=123456&ttt=111
### 测试 传Date参数
POST http://localhost:9092/userSessionStatView/test
Content-Type: application/x-www-form-urlencoded
userId: 11start=2019-03-22%2017
<> 2019-03-22T053542.200.json
###
九,idea 配置RunDashboard
如图以上方法还没有显示出来的话,则可以通过修改idea的workspace.xml的方式来快速打开Run Dashboard窗口
打开workspace.xml文件之后,找到component为 RunDashboard 的节点处,然后在component标签里添加
<option name="configurationTypes">
<set>
<option value="SpringBootApplicationConfigurationType" />
</set>
</option>最后保存即可,保存完成之后立即自动弹出Run Dashboard窗口了
十,shell脚本批量单独启动,停止,重启java独立jar程序
touch service.sh
chmod 777 service.sh #!/bin/bash
#####################################################Environment Setting########################################################程序代码数组
APPS=(pushcode thirdpayment security redis commservice wechat point useraccount coupon interest experience dealaccount user send payment sms deal dispatch dealload recv innermsg reward finacial debt pushmsg esign crmda)#程序名称数组
NAMES=(邀请码模块 第三方支付模块 安全模块 Redis模块 公共服务模块 微信服务模块 积分账户子系统 用户账户子系统 用户模块 队列消息发送模块 支付模块 短信系统 交易系统 消息队列模块 消息队列接收模块 站内信模块 奖励管理模块 结算系统 消息推送模块 电子签章 数据仓库)
#jar包数组
JARS=(pushcode-provider-0.0.1.jar comm-thirdpayment-provider-0.0.1.jar comm-security-provider.jar comm-redis-provider-0.0.1.jar comm-service-provider-0.0.1.jar action-provider-wechat-0.0.1.jar action-provider-point-0.0.1.jar action-provider-useraccount-0.0.1.jar action-provider-user-0.0.1.jar comm-message-send-provider-0.0.1.jar action-provider-payment-0.0.1.jar action-provider-sms-0.0.1.jar action-provider-deal-0.0.1.jar message-recv-dealload-0.0.1.jar comm-message-recv-provider-0.0.1.jar action-provider-innermsg-0.0.1.jar action-provider-reward-0.0.1.jar action-provider-finacial-0.0.1.jar message-pushmsg-0.0.1.jar provider-esign-0.0.1.jar provider-crmda-0.0.1.jar)
#jar包路径数组
PATHS=(/application/provider/pushcode /application/provider/thirdpayment /application/provider/security /application/provider/redis /application/provider/commservice /application/provider/wechat /application/provider/point /application/provider/useraccount /application/provider/user /application/provider/message/send /application/provider/payment /application/provider/sms /application/provider/deal /application/provider/message/dealload /application/provider/message/recv /application/provider/innermsg /application/provider/reward /application/provider/finacial /application/provider/pushmsg /application/provider/esign /application/provider/crmda)
start(){
local APPNAME=
local NAME=
local CLASSNAME=
local PROJECTDIR=
local command="sh service.sh start"
local cmd2="$1"
local cmd2ok=0
local cnt=0
local okcnt=0
#local C_PID="0"
#for i in `seq 0 22`
echo "---------------------------开始启动服务..."
for(( i=0;i<${#APPS[@]};i++))
do
APPNAME=${APPS[$i]}
NAME=${NAMES[$i]}
CLASSNAME=${JARS[$i]}
PROJECTDIR=${PATHS[$i]}
if [ "$cmd2" == "all" ] || [ "$cmd2" == "$APPNAME" ]; then
cmd2ok=1
C_PID="0"
cnt=0
#ps -ef | grep "$CLASSNAME" | awk '{print $2}' | while read pid
PID=`ps -ef |grep $(echo $CLASSNAME |awk -F/ '{print $NF}') | grep -v grep | awk '{print $2}'`
#do
#C_PID=$(ps --no-heading $pid | wc -l)
#if [ "$C_PID" == "1" ]; then
if [ -n "$PID" ]
then
echo "$APPNAME---$NAME:己经运行,PID=$PID"
#okcnt=$(($okcnt+1))
else
cd $PROJECTDIR
rm -f $PROJECTDIR/nohup.out
command="nohup java -jar $CLASSNAME --spring.profiles.active=prod &"
exec $command >> $PROJECTDIR/nohup.out &
#ps -ef | grep "$CLASSNAME" | awk '{print $2}' | while read pid
#do
# C_PID=$(ps --no-heading $pid | wc -l)
#done
PID=`ps -ef |grep $(echo $CLASSNAME |awk -F/ '{print $NF}') | grep -v grep | awk '{print $2}'`
cnt=0
#while (("$C_PID" == "0"))
while [ -z "$PID" ]
do
if (($cnt==30))
then
echo "$APPNAME---$NAME:$cnt秒内未启动,请检查!"
break
fi
cnt=$(($cnt+1))
sleep 1s
#ps -ef | grep "$CLASSNAME" | awk '{print $2}' | while read pid
#do
# C_PID=$(ps --no-heading $pid | wc -l)
#done
PID=`ps -ef |grep $(echo $CLASSNAME |awk -F/ '{print $NF}') | grep -v grep | awk '{print $2}'`
done
okcnt=$(($okcnt+1))
echo "$APPNAME---$NAME:己经成功启动,PID=$PID"
#出借模块和总装模块启动较慢
if [ "$APPNAME" == "deal" ] ;
then
echo "$APPNAME---$NAME:启动中..."
sleep 30s
fi
if [ "$APPNAME" == "dispatch" ] ;
then
echo "$APPNAME---$NAME:启动中..."
sleep 10s
fi
fi
#done
fi
done
if (($cmd2ok==0))
then
echo "command2: all|pushcode|thirdpayment|security|redis|commservice|wechat|point|useraccount|coupon|interest|experience|dealaccount|user|send|payment|sms|deal|dispatch|dealload|recv|innermsg|reward|finacial|debt"
else
echo "---------------------------本次启动:$okcnt个服务"
fi
}stop(){
local APPNAME=
local CLASSNAME=
local PROJECTDIR=
local command="sh service.sh stop"
local cmd2="$1"
local cmd2ok=0
#local C_PID="0"
local okcnt=0
echo "---------------------------开始停止服务..."
for(( i=0;i<${#APPS[@]};i++))
do
APPNAME=${APPS[$i]}
NAME=${NAMES[$i]}
CLASSNAME=${JARS[$i]}
PROJECTDIR=${PATHS[$i]}
if [ "$cmd2" == "all" ] || [ "$cmd2" == "$APPNAME" ]; then
cmd2ok=1
#ps -ef | grep "$CLASSNAME" | awk '{print $2}' | while read PID
PID=`ps -ef |grep $(echo $CLASSNAME |awk -F/ '{print $NF}') | grep -v grep | awk '{print $2}'`
#do
#C_PID=$(ps --no-heading $PID | wc -l)
#if [ "$C_PID" == "1" ]; then
if [ -n "$PID" ]
then
echo "$NAME:PID=$PID准备结束"
kill $PID
#C_PID=$(ps --no-heading $PID | wc -l)
#while (("$C_PID" == "1"))
PID=`ps -ef |grep $(echo $CLASSNAME |awk -F/ '{print $NF}') | grep -v grep | awk '{print $2}'`
while [ -n "$PID" ]
do
sleep 1s
#C_PID=$(ps --no-heading $PID | wc -l)
PID=`ps -ef |grep $(echo $CLASSNAME |awk -F/ '{print $NF}') | grep -v grep | awk '{print $2}'`
done
echo "$NAME:成功结束"
okcnt=$(($okcnt+1))
else
echo "$NAME:未运行"
fi
#done
fi
done
if (($cmd2ok==0))
then
echo "command2: all|pushcode|thirdpayment|security|redis|commservice|wechat|point|useraccount|coupon|interest|experience|dealaccount|user|send|payment|sms|deal|dispatch|dealload|recv|innermsg|reward|finacial|debt"
else
echo "---------------------------本次共停止:$okcnt个服务"
fi
}case "$1" in
start)
start "$2"
exit 1
;;
stop)
stop "$2"
;;
restart)
stop "$2"
start "$2"
;;
*)
echo "command1: start|stop|restart"
exit 1
;;
esac linux命令用法:
1.启动所有jar程序:sh liveService.sh start all
2.停止所有jar程序:sh liveService.sh stop all
3.重启所有jar程序:sh liveService.sh restart all
4.单独启动、停止、重启某个jar程序:把最后面的all替换为某个jar程序的代码即可
---liveService.sh:
#程序代码数组
APPS=(草莓启动脚本)#程序名称数组
NAMES=(草莓模块)
#jar包数组
JARS=(live-1.0.0.jar)
#jar包路径数组
PATHS=(/runxsports/)
start(){
local APPNAME=
local NAME=
local CLASSNAME=
local PROJECTDIR=
local command="sh service.sh start"
local cmd2="$1"
local cmd2ok=0
local cnt=0
local okcnt=0
#local C_PID="0"
#for i in `seq 0 22`
echo "---------------------------开始启动服务..."
for(( i=0;i<${#APPS[@]};i++))
do
APPNAME=${APPS[$i]}
NAME=${NAMES[$i]}
CLASSNAME=${JARS[$i]}
PROJECTDIR=${PATHS[$i]}if [ "$cmd2" == "all" ] || [ "$cmd2" == "$APPNAME" ]; then
cmd2ok=1
C_PID="0"
cnt=0
#ps -ef | grep "$CLASSNAME" | awk '{print $2}' | while read pid
PID=`ps -ef |grep $(echo $CLASSNAME |awk -F/ '{print $NF}') | grep -v grep | awk '{print $2}'`
#do
#C_PID=$(ps --no-heading $pid | wc -l)
#if [ "$C_PID" == "1" ]; then
if [ -n "$PID" ]
then
echo "$APPNAME---$NAME:己经运行,PID=$PID"
#okcnt=$(($okcnt+1))
else
cd $PROJECTDIR
rm -f $PROJECTDIR/nohup.out
command="nohup java -jar $CLASSNAME --spring.profiles.active=prod &"
exec $command >> $PROJECTDIR/nohup.out &
#ps -ef | grep "$CLASSNAME" | awk '{print $2}' | while read pid
#do
# C_PID=$(ps --no-heading $pid | wc -l)
#done
PID=`ps -ef |grep $(echo $CLASSNAME |awk -F/ '{print $NF}') | grep -v grep | awk '{print $2}'`
cnt=0
#while (("$C_PID" == "0"))
while [ -z "$PID" ]
do
if (($cnt==30))
then
echo "$APPNAME---$NAME:$cnt秒内未启动,请检查!"
breakfi
cnt=$(($cnt+1))
sleep 1s
#ps -ef | grep "$CLASSNAME" | awk '{print $2}' | while read pid
#do
# C_PID=$(ps --no-heading $pid | wc -l)
#done
PID=`ps -ef |grep $(echo $CLASSNAME |awk -F/ '{print $NF}') | grep -v grep | awk '{print $2}'`
done
okcnt=$(($okcnt+1))
echo "$APPNAME---$NAME:己经成功启动,PID=$PID"
#出借模块和总装模块启动较慢
if [ "$APPNAME" == "deal" ] ;
then
echo "$APPNAME---$NAME:启动中..."
sleep 30s
fi
if [ "$APPNAME" == "dispatch" ] ;
then
echo "$APPNAME---$NAME:启动中..."
sleep 10s
fi
fi
#done
fi
done
if (($cmd2ok==0))
then
echo "command2: all|pushcode|thirdpayment|security|redis|commservice|wechat|point|useraccount|coupon|interest|experience|dealaccount|user|send|payment|sms|deal|dispatch|dealload|recv|innermsg|reward|finacial|debt"
else
echo "---------------------------本次启动:$okcnt个服务"
fi
}stop(){
local APPNAME=
local CLASSNAME=
local PROJECTDIR=
local command="sh service.sh stop"
local cmd2="$1"
local cmd2ok=0
#local C_PID="0"
local okcnt=0
echo "---------------------------开始停止服务..."
for(( i=0;i<${#APPS[@]};i++))
do
APPNAME=${APPS[$i]}
NAME=${NAMES[$i]}
CLASSNAME=${JARS[$i]}
PROJECTDIR=${PATHS[$i]}
if [ "$cmd2" == "all" ] || [ "$cmd2" == "$APPNAME" ]; then
cmd2ok=1
#ps -ef | grep "$CLASSNAME" | awk '{print $2}' | while read PID
PID=`ps -ef |grep $(echo $CLASSNAME |awk -F/ '{print $NF}') | grep -v grep | awk '{print $2}'`
#do
#C_PID=$(ps --no-heading $PID | wc -l)
#if [ "$C_PID" == "1" ]; then
if [ -n "$PID" ]
then
echo "$NAME:PID=$PID准备结束"
kill $PID
#C_PID=$(ps --no-heading $PID | wc -l)
#while (("$C_PID" == "1"))
PID=`ps -ef |grep $(echo $CLASSNAME |awk -F/ '{print $NF}') | grep -v grep | awk '{print $2}'`
while [ -n "$PID" ]
do
sleep 1s
#C_PID=$(ps --no-heading $PID | wc -l)
PID=`ps -ef |grep $(echo $CLASSNAME |awk -F/ '{print $NF}') | grep -v grep | awk '{print $2}'`
done
echo "$NAME:成功结束"
okcnt=$(($okcnt+1))
else
echo "$NAME:未运行"
fi
#done
fi
done
if (($cmd2ok==0))
then
echo "command2: all|pushcode|thirdpayment|security|redis|commservice|wechat|point|useraccount|coupon|interest|experience|dealaccount|user|send|payment|sms|deal|dispatch|dealload|recv|innermsg|reward|finacial|debt"
else
echo "---------------------------本次共停止:$okcnt个服务"
fi
}case "$1" in
start)
start "$2"
exit 1
;;
stop)
stop "$2"
;;
restart)
stop "$2"
start "$2"
;;
*)
echo "command1: start|stop|restart"
exit 1
;;
esac
---live.sh
#!/bin/bash
APP_NAME=live-1.0.0.jar
#使用说明,用来提示输入参数
usage() {
echo "Usage: sh 执行脚本.sh [start|stop|restart|status]"
exit 1
}#检查程序是否在运行
is_exist(){
pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' `
#如果不存在返回1,存在返回0
if [ -z "${pid}" ]; then
return 1
else
return 0
fi
}#启动方法
start(){
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} is already running. pid=${pid} ."
else
java -jar -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -Xloggc:logs/gc.log -XX:+PrintHeapAtGC -XX:+PrintReferenceGC -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintTenuringDistribution -XX:HeapDumpPath=./logs $APP_NAME --spring.profiles.active=prod &> /dev/null 2>&1 &
echo "${APP_NAME} is starting"
fi
}#停止方法
stop(){
is_exist
if [ $? -eq "0" ]; then
kill -9 $pid
echo "${APP_NAME} is stopping"
else
echo "${APP_NAME} is not running"
fi
}#输出运行状态
status(){
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} is running. Pid is ${pid}"
else
echo "${APP_NAME} is NOT running."
fi
}#重启
restart(){
stop
start
}#根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
*)
usage
;;
esac十一,问题:每次右键项目名-maven->update project 时候,项目jdk版本变了,变回1.5版本或者其他版本
问题:每次右键项目名-maven->update project 时候,项目jdk版本变了,变回1.5版本或者其他版本
解决方案一:修改maven的配置(解压目录的conf\setting.xml文件)
复制代码
<profile>
<id>jdk1.6</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.6</jdk>
</activation>
<properties>
<!-- want to use the Java 8 language features, Default 1.5 -->
<maven.compiler.source>1.6</maven.compiler.source>
<!-- want the compiled classes to be compatible with JVM 1.8, Default 1.5 -->
<maven.compiler.target>1.6</maven.compiler.target>
<!-- Version of the compiler to use, ex. "1.3", "1.5", if fork is set to true -->
<maven.compiler.compilerVersion>1.6</maven.compiler.compilerVersion>
</properties>
</profile>
复制代码
解决方案二:默认settigs.xml文件路径为:c:\users\xxx\.m2\settings.xml,只要把设置好的settings.xml文件复制到该目录下解决方案三:修改项目中的pom.xml
复制代码
<plugins>
<!--
指定maven插件编译版本
1:maven:since2.0, 默认用jdk1.3来编译,maven 3.x 貌似是默认用jdk 1.5。
2:windows默认使用GBK编码,java项目经常编码为utf8,也需要在compiler插件中指出,否则中文乱码可能会出现编译错误。
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- since 2.0 -->
<version>3.7.0</version>
<configuration>
<!-- use the Java 8 language features -->
<source>1.8</source>
<!-- want the compiled classes to be compatible with JVM 1.8 -->
<target>1.8</target>
<!-- The -encoding argument for the Java compiler. -->
<encoding>UTF8</encoding>
</configuration>
</plugin>
</plugins>十二,commons-codec是Apache开源组织提供的用于摘要运算、编码解码的包。常见的编码解码工具Base64、MD5、Hex、SHA1、DES等。
commons-codec是Apache开源组织提供的用于摘要运算、编码解码的包。常见的编码解码工具Base64、MD5、Hex、SHA1、DES等。
Base64编码
System.out.println("===============base64======================");
Base64 base64 = new Base64();
String s = base64.encodeToString("测试22222222222".getBytes());
System.out.println(s);
String s1 = new String(base64.decode(s));
System.out.println(s1);
1
2
3
4
5
6
运算结果:===============base64======================
5rWL6K+VMjIyMjIyMjIyMjI=测试22222222222
1
2
3
4
MD5摘要运算
System.out.println("===============MD5======================");
String result = DigestUtils.md5Hex("测试");
System.out.println(result);
1
2
3
远算结果:===============MD5======================
db06c78d1e24cf708a14ce81c9b617ec
1
2
SHA运算和MD5是使用的同一个工具类。
- URLCodec System.out.println("===============MD5======================");
URLCodec codec = new URLCodec();
String s = codec.encode("测试", "utf-8");
System.out.println(s); String s1 = codec.decode(s, "utf-8");
System.out.println(s1);
1
2
3
4
5
6
7
运算结果:===============MD5======================
%E6%B5%8B%E8%AF%95
测试
--------------------- 十三,es kibana
//查询索引为 megacorp 的数据库
POST /megacorp/_search
{
"query": { "match_all": {} }
}GET _cat/health?v
GET /_cat/nodes?v
GET /_cat/indices?v
PUT /custmer/external/1?pertty
十四,首先,如果我们git clone的下载代码的时候是连接的https://而不是git@git (ssh)的形式,当我们操作git pull/push到远程的时候,总是提示我们输入账号和密码才能操作成功,频繁的输入账号和密码会很麻烦,也特别烦恼。
解决办法:
git bash进入你的项目目录,输入:
git config --global credential.helper store
十五,nginx
ps -ef | grep nginx
启动nginx
/usr/sbin/nginxnginx -s quit
stop — fast shutdown
quit — graceful shutdown
reload — reloading the configuration file
reopen — reopening the log fileslinx进程发送到nginx信号
kill -s quit 1628查看版本 及 文件路径
ngin -V http://nginx.org/en/docs/beginners_guide.html#control
---
RHEL/CentOS
Install the prerequisites:sudo yum install yum-utils
To set up the yum repository, create the file named /etc/yum.repos.d/nginx.repo with the following contents:[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
By default, the repository for stable nginx packages is used. If you would like to use mainline nginx packages, run the following command:sudo yum-config-manager --enable nginx-mainline
To install nginx, run the following command:sudo yum install nginx
When prompted to accept the GPG key, verify that the fingerprint matches 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62, and if so, accept it.十六,redis
1 检查是否有redis yum 源
yum install redis
2、下载fedora的epel仓库
yum install epel-release
3、安装redis数据库
yum install redis
4、安装完毕后,使用下面的命令启动redis服务
# 启动redis
service redis start 或者使用systemctl start redis.service
# 停止redis
service redis stop 或者 systemctl stop redis.service
# 查看redis运行状态
service redis status 或者 systemctl status redis.status
# 查看redis进程
ps -ef | grep redisredis客户端连接服务器
# 进入本机redis
redis-cli
# 列出所有key
keys *
#set test 111 设置key编辑配置
1. vim /etc/redis.conf
找到下面这一行 (/bind回车n下一个,N上一个)
bind 127.0.0.1
注释掉
#bind 127.0.0.12. protected-mode no改为yes
protected-mode yes3. 查找(/requirepass回车)
requirepass foobared 将 foobared 修改为你的密码4. redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379>info
NOAUTH Authentication required.
127.0.0.1:6379>auth 密码5. 重启
service redis stop
service redis start停止进程
ps -ef | grep redis
kill -9 PID 十七,jdk1.8
这里使用yum方式安装,前提是必须有网络
安装jdk1.8
yum install java-1.8.0-openjdk安装完成,查看java版本
安装open-jdk后发现jps不能用
1 需要安装另外一个包才能使用java-1.8.0-openjdk-devel.x86_64
2 yum install java-1.8.0-openjdk-devel.x86_64 [root@localhost ~]# java -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
十八,查看端口号
查询端口
netstat -tunlp | grep :3306ps -ef | grep redis
kill -9 PID
kill -15 PID进程号PID
ps aux
关闭进程号
kill -9 PID十九,mysql
--------------------------------------centos7 安装mysql--------------------------------------------------------------------------------------------
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server 这将安装MySQL服务器的软件包以及其他所需的软件包。systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。
service mysqld start 启动MySQL服务
service mysqld restart 重启命令
service mysqld status 查看服务状态grep 'temporary password' /var/log/mysqld.log 查看MySQL5.7的root用户的初始密码,登陆进去之后必须先修改密码,否则不能进行任何操作!
mysql -uroot -pALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; 修改新密码
//SET PASSWORD = PASSWORD('!q2w3e4R');
然后设置root用户的远程访问权限
在mysql控制台执行
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'MyNewPass4' WITH GRANT OPTION ;
flush privileges;--------------------------------------------------------------------设置"sql_mode"----------------------------------------------------------------------------
show variables like "sql_mode";
set sql_mode='';
set sql_mode='NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES'; 03. MySQL开启远程登录权限
方法一:step1: 登录MySQL数据库
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 78
Server version: 5.7.23 MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
step2: 修改权限第一个root是用户名,后面一个root是数据库密钥, %表示所有主机都可以访问。
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
step3: 刷新权限mysql> flush privileges;
Query OK, 0 rows affected (0.22 sec)mysql>
step4: 查看权限mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -AsDatabase changed
mysql> select user, host from user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| root | % |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
4 rows in set (0.09 sec)mysql>
方法二:step1: 修改表user
mysql> use mysql;
mysql> update user set host = ‘%’ where user = ‘root’;
step2: 刷新权限mysql> flush privileges;
Query OK, 0 rows affected (0.22 sec)mysql>
到此远程权限开启成功。04. Navicat连接MySQL
step1: 新建连接,选择MySQL解决办法:
1、移除原来的MySQL服务
mysqld -remove MySQL
二十,RabbitMQ
基于centos7安装的,此方法不一定适用于旧版本
一、安装Erlang
1、下载esl-erlang_21.0-1~centos~7_amd64.rpm
wget https://packages.erlang-solutions.com/erlang/esl-erlang/FLAVOUR_1_general/esl-erlang_21.0-1~centos~7_amd64.rpm
2、安装
rpm -ivh esl-erlang_21.0-1~centos~7_amd64.rpm --force --nodeps
3、查看安装
[root@localhost opt]# yum list|grep erlang
esl-erlang.x86_64 21.0-1 installed
二、安装RabbitMQ
1、下载rabbitmq-server-3.7.7-1 //wget https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.7.7/rabbitmq-server-3.7.7-1.el7.noarch.rpm
wget https://dl.bintray.com/rabbitmq/all/rabbitmq-server/3.7.8/rabbitmq-server-3.7.8-1.el7.noarch.rpm
2、安装
rpm -ivh rabbitmq-server-3.7.7-1.el7.noarch.rpm --force --nodeps
3、查看安装
[root@localhost opt]# yum list|grep rabbit
rabbitmq-server.noarch 3.7.7-1.el7 installed
librabbitmq.i686 0.8.0-2.el7 base
librabbitmq.x86_64 0.8.0-2.el7 base
librabbitmq-devel.i686 0.8.0-2.el7 base
librabbitmq-devel.x86_64 0.8.0-2.el7 base
librabbitmq-examples.x86_64 0.8.0-2.el7 base 21.0-1 installed
3、配置远程用户访问 1、新建配置文件
vi /etc/rabbitmq/rabbitmq.conf
#默认用户名
default_user = guest
#默认密码
default_pass = guest
#远程用户访问
loopback_users = none
2、启动rabbitmq服务
/sbin/service rabbitmq-server start
3、查看运行
[root@localhost opt]# /sbin/service rabbitmq-server status
Redirecting to /bin/systemctl status rabbitmq-server.service
● rabbitmq-server.service - RabbitMQ broker
Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: disabled)
Active: activating (start) since Fri 2018-07-06 01:06:31 EDT; 1min 15s ago
Main PID: 2948 (beam.smp)
CGroup: /system.slice/rabbitmq-server.service
├─2948 /usr/lib/erlang/erts-10.0/bin/beam.smp -W w -A 64 -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs...
├─3121 /usr/lib/erlang/erts-10.0/bin/epmd -daemon
├─3259 erl_child_setup 1024
├─3296 inet_gethost 4
└─3297 inet_gethost 4
Jul 06 01:06:36 localhost.localdomain rabbitmq-server[2948]: ## ## RabbitMQ 3.7.7. Copyright (C) 2007-2018 Pi...Inc.
Jul 06 01:06:36 localhost.localdomain rabbitmq-server[2948]: ########## Licensed under the MPL. See http://www.ra...com/
Jul 06 01:06:36 localhost.localdomain rabbitmq-server[2948]: ###### ##
Jul 06 01:06:36 localhost.localdomain rabbitmq-server[2948]: ########## Logs: /var/log/rabbitmq/rabbit@localhost.log
Jul 06 01:06:36 localhost.localdomain rabbitmq-server[2948]: /var/log/rabbitmq/rabbit@localhost_upgrade.log
Jul 06 01:06:36 localhost.localdomain rabbitmq-server[2948]: Starting broker...
Jul 06 01:06:36 localhost.localdomain rabbitmq-server[2948]: systemd unit for activation check: "rabbitmq-server.service"
Jul 06 01:06:36 localhost.localdomain rabbitmq-server[2948]: Failed to start socat error:enoent
Jul 06 01:06:36 localhost.localdomain rabbitmq-server[2948]: systemd READY notification failed, beware of timeouts
Jul 06 01:06:36 localhost.localdomain rabbitmq-server[2948]: completed with 0 plugins.
Hint: Some lines were ellipsized, use -l to show in full.
4、开启RabbitMQ web访问
rabbitmq-plugins enable rabbitmq_management
/sbin/service rabbitmq-server stop
/sbin/service rabbitmq-server start
5、开启端口15672,5672
[root@localhost opt]# firewall-cmd --permanent --add-port=15672/tcp
success
[root@localhost opt]# firewall-cmd --permanent --add-port=5672/tcp
success
[root@localhost opt]# service network restart
Restarting network (via systemctl): [ OK ]
[root@localhost opt]#
5、设置开机启动
chkconfig rabbitmq-server on
安装完毕web访问
浏览器输入192.168.x.x:15672
默认账号密码
guest
guest