学习笔记
1.Liunx防火墙入门,C段,B类
service iptables status
service iptables start
service iptables service
service iptables stop
service iptables save
2.sftp一个端口,ftp两个端口 21和数据传输端口
3.关联查优化:首先配合explain加索引,然后inner join让B最简单(仅过滤那几个字段)
最优化:不关联查,子查询不能使用索引,性能差,尽量集中一张表里查
4.获取协议、ip、端口、路径:
logger.info("ip={},port={},context={},http={}", NetworkUtils.getLocalIP(), NetworkUtils.getLocalPort(), req.getContextPath(),req.getScheme());
public class NetworkUtils {
/**
* 获取当前机器端口号
*/
public static String getLocalPort() throws Exception {
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objectNames = mBeanServer.queryNames(new ObjectName("*:type=Connector,*"), null);
if (objectNames == null || objectNames.size() <= 0) {
throw new IllegalStateException("Cannot get the names of MBeans controlled by the MBean server.");
}
for (ObjectName objectName : objectNames) {
String protocol = String.valueOf(mBeanServer.getAttribute(objectName, "protocol"));
String port = String.valueOf(mBeanServer.getAttribute(objectName, "port"));
// windows下属性名称为HTTP/1.1, linux下为org.apache.coyote.http11.Http11NioProtocol
if (protocol.equals("HTTP/1.1") || protocol.equals("org.apache.coyote.http11.Http11NioProtocol")) {
return port;
}
}
throw new IllegalStateException("Failed to get the HTTP port of the current server");
}
/**
* 获取当前机器的IP
*/
public static String getLocalIP() throws Exception {
InetAddress addr = InetAddress.getLocalHost();
byte[] ipAddr = addr.getAddress();
String ipAddrStr = "";
for (int i = 0; i < ipAddr.length; i++) {
if (i > 0) {
ipAddrStr += ".";
}
ipAddrStr += ipAddr[i] & 0xFF;
}
return ipAddrStr;
}
}
/**
* 获取当前机器的IP4地址
*/
public static String getLocalIP() throws Exception {
try{
Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
while (allNetInterfaces.hasMoreElements()){
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
while (addresses.hasMoreElements()){
InetAddress ip = (InetAddress) addresses.nextElement();
if (ip != null
&& ip instanceof Inet4Address
&& !ip.isLoopbackAddress() //loopback地址即本机地址,IPv4的loopback范围是127.0.0.0 ~ 127.255.255.255
&& ip.getHostAddress().indexOf(":")==-1){
System.out.println("本机的IP = " + ip.getHostAddress());
return ip.getHostAddress();
}
}
}
}catch(Exception e){
e.printStackTrace();
}
return null;
}
浙公网安备 33010602011771号