java日期时间工具类

工具类继承了OutPut类,这个类只是提供了一个out()的静态方法,用于测试。

package system.utils;

import system.lib.OutPut;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.time.temporal.*;
import java.util.Date;
import java.util.Locale;

/**
 * Created by alan on 2019/4/19.
 *
 * ********************************
 * getTime():1555776871585
 * getTimeInt():1555776871
 * getLocalDate():2019-04-21
 * parseLocalDate("2019-04-20",1):2019-04-20
 * parseLocalDate(2019,04,20):2019-04-20
 * plus(getLocalDate(),2,ChronoUnit.DAYS):2019-04-23
 * --------------------------------
 * getLocalTime():00:14:31.585
 * parseLocalTime("23:56:00"):23:56
 * parseLocalTime(23,56,12):23:56:12
 * plus(getLocalTime(),-3,ChronoUnit.HOURS):21:14:31.585
 * --------------------------------
 * getLocalDateTime():2019-04-21T00:14:31.585
 * parseLocalDateTime("2019-04-20 21:05:56",1):2019-04-20T21:05:56
 * parseLocalDateTime(2019,4,20,21,05,56):2019-04-20T21:05:56
 * plus(getLocalDateTime(),-1,ChronoUnit.MONTHS):2019-03-21T00:14:31.585
 * --------------------------------
 * format(int t):2019-04-21T00:14:31
 * format(long t):2019-04-21T00:14:31.585
 * format(int t,1):2019-4-21 0:14:31
 * format(long t,1):2019-4-21 0:14:31
 * format(LocalDate d,1):2019-4-21
 * format(LocalTime t):0:14:31
 * format(LocalDateTime t,1):2019-4-21 0:14:31
 * format(ZonedDateTime.now(),1):2019-4-21 0:14:31
 * format(LocalDate d,DateTimeFormatter.ISO_DATE):2019-04-21
 * format(LocalTime t,DateTimeFormatter.ISO_TIME):00:14:31.585
 * format(LocalDateTime t,DateTimeFormatter.ISO_DATE_TIME):2019-04-21T00:14:31.585
 * format(ZonedDateTime t,DateTimeFormatter.ISO_DATE_TIME):2019-04-21T00:14:31.585+08:00[Asia/Shanghai]
 * format(LocalDateTime t,DATE_TIME_FULL):2019-04-21 00:14:31
 * format(int i,DATE_TIME_FULL):2019-04-21 00:14:31
 * format(long l,DATE_TIME_FULL):2019-04-21 00:14:31
 * --------------------------------
 * getYear():2019
 * getMonthI():4
 * getMonth():APRIL
 * getMonthS():四月
 * getDayOfMonth():21
 * getDayOfYear():111
 * getDayOfMonthMax():30
 * getWeek():星期日
 * getWeekI():7
 * getDate():Sun Apr 21 00:14:31 CST 2019
 * getTimestamp():2019-04-21 00:14:31.587
 * getTimestampL():2019-04-21 00:14:31.587
 * getHour():0
 * getMinute():14
 * getSecond():31
 */
public class DateTimeUtils extends OutPut {

    public static final String YEAR = "yyyy";
    public static final String MONTH = "MM";
    public static final String DAY = "dd";
    public static final String DATE_FULL = "yyyy-MM-dd";
    public static final String DATE_FULL2 = "yyyyMMdd";
    public static final String DATE_TIME_FULL = "yyyy-MM-dd HH:mm:ss";
    public static final String DATE_TIME_FULL2 = "yyyyMMddHHmmss";
    public static final String WEEK = "EEEE";

    private static final int ZONE_HOUR = 8;

    public DateTimeUtils() {

    }

    /**
     * 取时间戳
     *
     * @return long
     */
    public static long getTime() {
        return System.currentTimeMillis();
    }

    /**
     * 取时间戳
     *
     * @return int
     */
    public static int getTimeInt() {
        return (int) (getTime() / 1000);
    }

    /**
     * 取本地日期对象
     *
     * @return LocalDate
     */
    public static LocalDate getLocalDate() {
        return LocalDate.now();
    }

    /**
     * 字符串日期转本地日期对象
     *
     * @param str    2012/01/01|2012-01-01
     * @param format 1|2
     * @return LocalDate
     */
    public static LocalDate parseLocalDate(String str, int format) {
        /**
         * format:1=-,2=/
         */
        String regx = "/";
        if (1 == format) {
            regx = "-";
        }
        String[] s = str.split(regx);
        return parseLocalDate(Integer.valueOf(s[0]), Integer.valueOf(s[1]), Integer.valueOf(s[2]));
    }

    /**
     * 整数日期转本地日期对象
     *
     * @param y 年
     * @param m 月
     * @param d 日
     * @return LocalDate
     */
    public static LocalDate parseLocalDate(int y, int m, int d) {
        return LocalDate.of(y, m, d);
    }

    /**
     * 本地日期增减
     *
     * @param date 本地日期
     * @param n    +正数则增加;-负数则减去
     * @param unit ChronoUnit.DAYS|ChronoUnit.YEARS|ChronoUnit.MONTHS
     * @return LocalDate
     */
    public static LocalDate plus(LocalDate date, int n, ChronoUnit unit) {
        return date.plus(n, unit);
    }

    /**
     * 取本地时间对象
     *
     * @return LocalTime
     */
    public static LocalTime getLocalTime() {
        return LocalTime.now();
    }

    /**
     * 本地时间增减
     *
     * @param time 本地时间
     * @param n    +正数则增加;-负数则减去
     * @param unit ChronoUnit.HOURS|ChronoUnit.MINUTES|ChronoUnit.SECONDS
     * @return LocalTime
     */
    public static LocalTime plus(LocalTime time, int n, ChronoUnit unit) {
        return time.plus(n, unit);
    }

    /**
     * 字符串时间转本地时间对象
     *
     * @param time 00:00:00
     * @return LocalTime
     */
    public static LocalTime parseLocalTime(String time) {
        String[] s = time.split(":");
        return parseLocalTime(Integer.valueOf(s[0]), Integer.valueOf(s[1]), Integer.valueOf(s[2]));
    }

    /**
     * 整数时间转本地时间对象
     *
     * @param h 小时
     * @param m 分钟
     * @param s 秒
     * @return LocalTime
     */
    public static LocalTime parseLocalTime(int h, int m, int s) {
        return LocalTime.of(h, m, s);
    }

    /**
     * 获取本地日期时间对象
     *
     * @return
     */
    public static LocalDateTime getLocalDateTime() {
        return LocalDateTime.now();
    }

    /**
     * 本地日期时间增减
     *
     * @param time 本地日期时间
     * @param n    +正数则增加;-负数则减去
     * @param unit ChronoUnit.DAYS|ChronoUnit.YEARS|ChronoUnit.MONTHS|ChronoUnit.HOURS|ChronoUnit.MINUTES|ChronoUnit.SECONDS
     * @return LocalDateTime
     */
    public static LocalDateTime plus(LocalDateTime time, int n, ChronoUnit unit) {
        return time.plus(n, unit);
    }

    /**
     * 本地日期增减
     *
     * @param time 本地时间
     * @param n    +正数则增加;-负数则减去
     * @param unit ChronoUnit.DAYS|ChronoUnit.YEARS|ChronoUnit.MONTHS
     * @return LocalDate
     */
    public static LocalDate plusDate(LocalDate time, int n, ChronoUnit unit) {
        return time.plus(n, unit);
    }

    /**
     * 本地时间增减
     *
     * @param time 本地时间
     * @param n    +正数则增加;-负数则减去
     * @param unit ChronoUnit.HOURS|ChronoUnit.MINUTES|ChronoUnit.SECONDS
     * @return LocalTime
     */
    public static LocalTime plusTime(LocalTime time, int n, ChronoUnit unit) {
        return time.plus(n, unit);
    }

    /**
     * 字符串日期时间转本地日期时间对象
     *
     * @param datetime string like it:2019-01-01 00:00:00 other is 2019/01/01 00:00:00
     * @param format   if == 1 then 2019-01-01 00:00:00 other is 2019/01/01 00:00:00
     * @return null|LocalDateTime
     */
    public static LocalDateTime parseLocalDateTime(String datetime, int format) {
        String[] x = datetime.split(" ");
        if (x.length != 2) {
            return null;
        }
        String regx = "/";
        if (1 == format) {
            regx = "-";
        }
        String[] d = x[0].split(regx);
        String[] s = x[1].split(":");
        return parseLocalDateTime(Integer.valueOf(d[0]), Integer.valueOf(d[1]), Integer.valueOf(d[2]),
                Integer.valueOf(s[0]), Integer.valueOf(s[1]), Integer.valueOf(s[2]));
    }

    /**
     * 整数日期时间转本地日期时间对象
     *
     * @param y 年
     * @param m 月
     * @param d 日
     * @param h 小时
     * @param i 分钟
     * @param s 秒
     * @return LocalDateTime
     */
    public static LocalDateTime parseLocalDateTime(int y, int m, int d, int h, int i, int s) {
        return LocalDateTime.of(y, m, d, h, i, s);
    }

    /**
     * 格式化当前时间
     * @return
     */
    public static String format() {
        return format(getTime(),1);
    }

    /**
     * 秒时间戳转本地日期时间对象
     *
     * @param datetime 秒时间戳
     * @return LocalDateTime
     */
    public static LocalDateTime format(int datetime) {
        return format((long) datetime * 1000L);
    }

    /**
     * 微秒时间戳转本地日期时间对象
     *
     * @param datetime 微秒时间戳
     * @return LocalDateTime
     */
    public static LocalDateTime format(long datetime) {
        LocalDateTime localDateTime = Instant.ofEpochMilli(datetime).atZone(ZoneOffset.systemDefault()).toLocalDateTime();
        return localDateTime;
    }

    /**
     * 秒时间戳格式化字符串文本
     *
     * @param datetime 秒时间戳
     * @param format   格式化字符串
     * @return String
     */
    public static String format(int datetime, int format) {
        return format((long) datetime * 1000L, format);
    }

    /**
     * 微秒时间戳格式化字符串文本
     *
     * @param datetime 微秒时间戳
     * @param format   格式化字符串
     * @return String
     */
    public static String format(long datetime, int format) {
        return format(format(datetime), format);
    }

    /**
     * 本地日期对象格式化文本
     *
     * @param date   本地日期对象
     * @param format 1~2
     * @return String
     */
    public static String format(LocalDate date, int format) {
        String regx = "/";
        if (1 == format) {
            regx = "-";
        }
        StringBuffer st = new StringBuffer();
        st.append(date.getYear()).append(regx)
                .append(date.getMonthValue()).append(regx)
                .append(date.getDayOfMonth());
        return st.toString();
    }


    /**
     * 本地时间对象格式化文本
     *
     * @param time 本地时间对象
     * @return String
     */
    public static String format(LocalTime time) {
        StringBuffer st = new StringBuffer();
        st.append(time.getHour()).append(":")
                .append(time.getMinute()).append(":")
                .append(time.getSecond());
        return st.toString();
    }

    /**
     * 本地日期时间对象格式化文本
     *
     * @param dateTime 本地日期时间对象
     * @param format   1~2
     * @return String
     */
    public static String format(LocalDateTime dateTime, int format) {
        String regx = "/";
        if (1 == format) {
            regx = "-";
        }
        StringBuffer st = new StringBuffer();
        st.append(dateTime.getYear()).append(regx)
                .append(dateTime.getMonthValue()).append(regx)
                .append(dateTime.getDayOfMonth()).append(" ")
                .append(dateTime.getHour()).append(":")
                .append(dateTime.getMinute()).append(":")
                .append(dateTime.getSecond());
        return st.toString();
    }

    /**
     * 时区时间格式化文本
     *
     * @param dateTime 时区时间对象
     * @param format 1~2
     * @return String
     */
    public static String format(ZonedDateTime dateTime, int format) {
        String regx = "/";
        if (1 == format) {
            regx = "-";
        }
        StringBuffer st = new StringBuffer();
        st.append(dateTime.getYear()).append(regx)
                .append(dateTime.getMonthValue()).append(regx)
                .append(dateTime.getDayOfMonth()).append(" ")
                .append(dateTime.getHour()).append(":")
                .append(dateTime.getMinute()).append(":")
                .append(dateTime.getSecond());
        return st.toString();
    }

    /**
     * 格式化本地日期
     * @param date 本地日期对象
     * @param format 日期时间格式化对象:DateTimeFormatter.ISO_DATE
     * @return String
     */
    public static String format(LocalDate date, DateTimeFormatter format) {
        return format.format(date);
    }

    /**
     * 格式化本地时间
     * @param time 本地时间对象
     * @param format 日期时间格式化对象:DateTimeFormatter.ISO_TIME
     * @return String
     */
    public static String format(LocalTime time, DateTimeFormatter format) {
        return format.format(time);
    }

    /**
     * 格式化本地日期时间
     * @param dateTime 本地日期时间对象
     * @param format 日期时间格式化对象:DateTimeFormatter.ISO_LOCAL_DATE_TIME|ISO_DATE_TIME
     * @return String
     */
    public static String format(LocalDateTime dateTime, DateTimeFormatter format) {
        return format.format(dateTime);
    }

    /**
     * 格式化时区日期时间
     * @param dateTime 时区日期时间对象
     * @param format 日期格式化对象:DateTimeFormatter.ISO_ZONED_DATE_TIME|ISO_DATE_TIME
     * @return String
     */
    public static String format(ZonedDateTime dateTime, DateTimeFormatter format) {
        return format.format(dateTime);
    }

    /**
     * 取Date对象
     * @return Date
     */
    public static Date getDate() {
        return Date.from(Instant.now());
    }

    /**
     * 取Timestamp对象
     * @return Timestamp
     */
    public static Timestamp getTimestamp() {
        return Timestamp.from(Instant.now());
    }

    /**
     * 取Timestamp对象
     * @return Timestamp
     */
    public static Timestamp getTimestampL() {
        return Timestamp.valueOf(getLocalDateTime());
    }

    /**
     * 获取星期
     *
     * @return like 星期六|?
     */
    public static String getWeek() {
        return getLocalDate().getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.getDefault());
    }

    /**
     * 获取星期
     *
     * @return like 1~7
     */
    public static int getWeekI() {
        return getLocalDate().getDayOfWeek().getValue();
    }

    /**
     * 获取当天日(按月)
     * @return int
     */
    public static int getDayOfMonth() {
        return getLocalDate().getDayOfMonth();
    }

    /**
     * 获取当天日(按年)
     * @return int
     */
    public static int getDayOfYear() {
        return getLocalDate().getDayOfYear();
    }

    /**
     * 获取当月最后一天
     * @return int
     */
    public static int getDayOfMonthMax() {
        return getMonth().maxLength();
    }

    /**
     * 获取Month对象
     * @return Month
     */
    public static Month getMonth() {
        return getLocalDate().getMonth();
    }

    /**
     * 获取月份(当地格式)
     * @return String|六月
     */
    public static String getMonthS() {
        return getMonth().getDisplayName(TextStyle.FULL, Locale.getDefault());
    }

    /**
     * 获取月份
     * @return int
     */
    public static int getMonthI() {
        return getMonth().getValue();
    }

    /**
     * 取年份
     * @return int|2019
     */
    public static int getYear() {
        return getLocalDate().getYear();
    }

    /**
     * 取小时
     * @return int|0~23
     */
    public static int getHour() {
        return getLocalTime().getHour();
    }

    /**
     * 取分钟
     * @return int|0~59
     */
    public static int getMinute() {
        return getLocalTime().getMinute();
    }

    /**
     * 取秒
     * @return int|0~59
     */
    public static int getSecond() {
        return getLocalTime().getSecond();
    }

    /**
     * 格式化本地日期时间对象
     * @param dateTime 本地日期时间对象
     * @param pattern  public static final String YEAR = "yyyy";
     *                 public static final String MONTH = "MM";
     *                 public static final String DAY = "dd";
     *                 public static final String FULL_DATE = "yyyy-MM-dd";
     *                 public static final String FULL_DATE_Q = "yyyyMMdd";
     *                 public static final String FULL_DATE_TIME = "yyyy-MM-dd HH:mm:ss";
     *                 public static final String FULL_DATE_TIME_Q = "yyyyMMddHHmmss";
     *                 public static final String WEEK = "EEEE";
     * @return String
     */
    public static String format(LocalDateTime dateTime, String pattern) {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        return sdf.format(Date.from(dateTime.atZone(ZoneOffset.systemDefault()).toInstant()));
    }

    /**
     * 格式化日期时间(整数)
     * @param dateTime 时间戳
     * @param pattern 格式化文本
     * @return String
     */
    public static String format(int dateTime, String pattern) {
        return format((long) dateTime * 1000L, pattern);
    }

    /**
     * 格式化日期时间(长整数)
     * @param dateTime 微秒时间戳
     * @param pattern 格式化文本
     * @return String
     */
    public static String format(long dateTime, String pattern) {
        return format(format(dateTime), pattern);
    }

    public static void main(String[] args) {
        out("********************************");
        out("getTime():"+getTime());
        out("getTimeInt():"+getTimeInt());
        out("getLocalDate():"+getLocalDate());
        out("parseLocalDate(\"2019-04-20\",1):"+parseLocalDate("2019-04-20",1));
        out("parseLocalDate(2019,04,20):"+parseLocalDate(2019,04,20));
        out("plus(getLocalDate(),2,ChronoUnit.DAYS):"+plus(getLocalDate(),2,ChronoUnit.DAYS));
        out("--------------------------------");
        out("getLocalTime():"+getLocalTime());
        out("parseLocalTime(\"23:56:00\"):"+parseLocalTime("23:56:00"));
        out("parseLocalTime(23,56,12):"+parseLocalTime(23,56,12));
        out("plus(getLocalTime(),-3,ChronoUnit.HOURS):"+plus(getLocalTime(),-3,ChronoUnit.HOURS));
        out("--------------------------------");
        out("getLocalDateTime():"+getLocalDateTime());
        out("parseLocalDateTime(\"2019-04-20 21:05:56\",1):"+parseLocalDateTime("2019-04-20 21:05:56",1));
        out("parseLocalDateTime(2019,4,20,21,05,56):"+parseLocalDateTime(2019,4,20,21,05,56));
        out("plus(getLocalDateTime(),-1,ChronoUnit.MONTHS):"+plus(getLocalDateTime(),-1,ChronoUnit.MONTHS));
        out("--------------------------------");
        out("format(int t):"+format(getTimeInt()));
        out("format(long t):"+format(getTime()));
        out("format(int t,1):"+format(getTimeInt(),1));
        out("format(long t,1):"+format(getTime(),1));
        out("format(LocalDate d,1):"+format(getLocalDate(),1));
        out("format(LocalTime t):"+format(getLocalTime()));
        out("format(LocalDateTime t,1):"+format(getLocalDateTime(),1));
        out("format(ZonedDateTime.now(),1):"+format(ZonedDateTime.now(),1));
        out("format(LocalDate d,DateTimeFormatter.ISO_DATE):"+format(getLocalDate(),DateTimeFormatter.ISO_DATE));
        out("format(LocalTime t,DateTimeFormatter.ISO_TIME):"+format(getLocalTime(),DateTimeFormatter.ISO_TIME));
        out("format(LocalDateTime t,DateTimeFormatter.ISO_DATE_TIME):"+format(getLocalDateTime(),DateTimeFormatter.ISO_DATE_TIME));
        out("format(ZonedDateTime t,DateTimeFormatter.ISO_DATE_TIME):"+format(ZonedDateTime.now(),DateTimeFormatter.ISO_DATE_TIME));
        out("format(LocalDateTime t,DATE_TIME_FULL):"+format(getLocalDateTime(),DATE_TIME_FULL));
        out("format(int i,DATE_TIME_FULL):"+format(getTimeInt(),DATE_TIME_FULL));
        out("format(long l,DATE_TIME_FULL):"+format(getTime(),DATE_TIME_FULL));
        out("--------------------------------");
        out("getYear():"+getYear());
        out("getMonthI():"+getMonthI());
        out("getMonth():"+getMonth());
        out("getMonthS():"+getMonthS());
        out("getDayOfMonth():"+getDayOfMonth());
        out("getDayOfYear():"+getDayOfYear());
        out("getDayOfMonthMax():"+getDayOfMonthMax());
        out("getWeek():"+getWeek());
        out("getWeekI():"+getWeekI());
        out("getDate():"+getDate());
        out("getTimestamp():"+getTimestamp());
        out("getTimestampL():"+getTimestampL());
        out("getHour():"+getHour());
        out("getMinute():"+getMinute());
        out("getSecond():"+getSecond());


    }
}

CSS样式形状

PS:代码来源于网络。

CSS能够生成各种形状。正方形和矩形很容易,因为它们是 web 的自然形状。添加宽度和高度,就得到了所需的精确大小的矩形。添加边框半径,你就可以把这个形状变成圆形,足够多的边框半径,你就可以把这些矩形变成圆形和椭圆形。

我们还可以使用 CSS 伪元素中的 ::before::after,这为我们提供了向原始元素添加另外两个形状的可能性。通过巧妙地使用定位、转换和许多其他技巧,我们可以只用一个 HTML 元素在 CSS 中创建许多形状。

1.正方形

1555920540-9852-o88wosemav
#square {
  width: 100px;
  height: 100px;
  background: red;
}

2.长方形

1555920541-6008-rj4xn4mycs
#rectangle {
  width: 200px;
  height: 100px;
  background: red;
}

3.圆形

1555920540-5020-52z7b78uym
#circle {
  width: 100px;
  height: 100px;
  background: red;
  border-radius: 50%
}

4.椭圆形

1555920540-6489-u5866htngx
#oval {
  width: 200px;
  height: 100px;
  background: red;
  border-radius: 100px / 50px;
}

5.上三角

1555920540-9812-v5w2fgnwuw
#triangle-up {
  width: 0;
  height: 0;
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  border-bottom: 100px solid red;
}

6.下三角

1555920541-2519-mna60vffgb
#triangle-down {
  width: 0;
  height: 0;
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  border-top: 100px solid red;
}

7.左三角

1555920548-6518-mazrvjyfbf
#triangle-left {
  width: 0;
  height: 0;
  border-top: 50px solid transparent;
  border-right: 100px solid red;
  border-bottom: 50px solid transparent;
}

8.右三角

1555920548-3876-dbkk3ni2pn
#triangle-right {
  width: 0;
  height: 0;
  border-top: 50px solid transparent;
  border-left: 100px solid red;
  border-bottom: 50px solid transparent;
}

9.左上角

1555920548-7309-5281l9kr4j
#triangle-topleft {
  width: 0;
  height: 0;
  border-top: 100px solid red;
  border-right: 100px solid transparent;
}

10.右上角

1555920548-7953-6usd6ua1sm
#triangle-topright {
  width: 0;
  height: 0;
  border-top: 100px solid red;
  border-left: 100px solid transparent;
}

11.左下角

1555920548-1871-6cfqjsgqzj
#triangle-bottomleft {
  width: 0;
  height: 0;
  border-bottom: 100px solid red;
  border-right: 100px solid transparent;
}

12.右下角

1555920548-8490-it3p7fpxak
#triangle-bottomright {
  width: 0;
  height: 0;
  border-bottom: 100px solid red;
  border-left: 100px solid transparent;
}

13.箭头

1555920556-9955-94kri0bujn
#curvedarrow {
  position: relative;
  width: 0;
  height: 0;
  border-top: 9px solid transparent;
  border-right: 9px solid red;
  transform: rotate(10deg);
}
#curvedarrow:after {
  content: "";
  position: absolute;
  border: 0 solid transparent;
  border-top: 3px solid red;
  border-radius: 20px 0 0 0;
  top: -12px;
  left: -9px;
  width: 12px;
  height: 12px;
  transform: rotate(45deg);
}

14.梯形

1555920555-8764-89vuvjwknv
#trapezoid {
  border-bottom: 100px solid red;
  border-left: 25px solid transparent;
  border-right: 25px solid transparent;
  height: 0;
  width: 100px;
}

15.平行四边形

1555920556-1272-85ekanr2mk
#parallelogram {
  width: 150px;
  height: 100px;
  transform: skew(20deg);
  background: red;
}

16.星星 (6角)

1555920555-9404-luli3pn3js
#star-six {
  width: 0;
  height: 0;
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  border-bottom: 100px solid red;
  position: relative;
}
#star-six:after {
  width: 0;
  height: 0;
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  border-top: 100px solid red;
  position: absolute;
  content: "";
  top: 30px;
  left: -50px;
}

17.星星 (5角)

1555920555-5612-u6j9nn5zrt
#star-five {
  margin: 50px 0;
  position: relative;
  display: block;
  color: red;
  width: 0px;
  height: 0px;
  border-right: 100px solid transparent;
  border-bottom: 70px solid red;
  border-left: 100px solid transparent;
  transform: rotate(35deg);
}
#star-five:before {
  border-bottom: 80px solid red;
  border-left: 30px solid transparent;
  border-right: 30px solid transparent;
  position: absolute;
  height: 0;
  width: 0;
  top: -45px;
  left: -65px;
  display: block;
  content: '';
  transform: rotate(-35deg);
}
#star-five:after {
  position: absolute;
  display: block;
  color: red;
  top: 3px;
  left: -105px;
  width: 0px;
  height: 0px;
  border-right: 100px solid transparent;
  border-bottom: 70px solid red;
  border-left: 100px solid transparent;
  transform: rotate(-70deg);
  content: '';
}

18.五边形

1555920555-5853-39fj96ppzf
#pentagon {
  position: relative;
  width: 54px;
  box-sizing: content-box;
  border-width: 50px 18px 0;
  border-style: solid;
  border-color: red transparent;
}
#pentagon:before {
  content: "";
  position: absolute;
  height: 0;
  width: 0;
  top: -85px;
  left: -18px;
  border-width: 0 45px 35px;
  border-style: solid;
  border-color: transparent transparent red;
}

19.六边形

1555920562-9701-85tfgk090z
#hexagon {
  width: 100px;
  height: 55px;
  background: red;
  position: relative;
}
#hexagon:before {
  content: "";
  position: absolute;
  top: -25px;
  left: 0;
  width: 0;
  height: 0;
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  border-bottom: 25px solid red;
}
#hexagon:after {
  content: "";
  position: absolute;
  bottom: -25px;
  left: 0;
  width: 0;
  height: 0;
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  border-top: 25px solid red;
}

20.八边形

1555920562-3808-6keelsm0vb
#octagon {
  width: 100px;
  height: 100px;
  background: red;
  position: relative;
}
#octagon:before {
  content: "";
  width: 100px;
  height: 0;
  position: absolute;
  top: 0;
  left: 0;
  border-bottom: 29px solid red;
  border-left: 29px solid #eee;
  border-right: 29px solid #eee;
}
#octagon:after {
  content: "";
  width: 100px;
  height: 0;
  position: absolute;
  bottom: 0;
  left: 0;
  border-top: 29px solid red;
  border-left: 29px solid #eee;
  border-right: 29px solid #eee;
}

21.爱心

1555920563-9495-qlc2eyp66r
#heart {
  position: relative;
  width: 100px;
  height: 90px;
}
#heart:before,
#heart:after {
  position: absolute;
  content: "";
  left: 50px;
  top: 0;
  width: 50px;
  height: 80px;
  background: red;
  border-radius: 50px 50px 0 0;
  transform: rotate(-45deg);
  transform-origin: 0 100%;
}
#heart:after {
  left: 0;
  transform: rotate(45deg);
  transform-origin: 100% 100%;
}

22.无穷大

1555920562-6265-yq1e4m8kjd
#infinity {
  position: relative;
  width: 212px;
  height: 100px;
  box-sizing: content-box;
}
#infinity:before,
#infinity:after {
  content: "";
  box-sizing: content-box;
  position: absolute;
  top: 0;
  left: 0;
  width: 60px;
  height: 60px;
  border: 20px solid red;
  border-radius: 50px 50px 0 50px;
  transform: rotate(-45deg);
}
#infinity:after {
  left: auto;
  right: 0;
  border-radius: 50px 50px 50px 0;
  transform: rotate(45deg);
}

23.菱形

1555920562-1011-cr6nbch1a1
#diamond {
  width: 0;
  height: 0;
  border: 50px solid transparent;
  border-bottom-color: red;
  position: relative;
  top: -50px;
}
#diamond:after {
  content: '';
  position: absolute;
  left: -50px;
  top: 50px;
  width: 0;
  height: 0;
  border: 50px solid transparent;
  border-top-color: red;
}

代码部署后可能存在的BUG没法实时知道,事后为了解决这些BUG,花了大量的时间进行log 调试,这边顺便给大家推荐一个好用的BUG监控工具 Fundebug

24.钻石1

1555920563-2362-aq5env1pic
#diamond-shield {
  width: 0;
  height: 0;
  border: 50px solid transparent;
  border-bottom: 20px solid red;
  position: relative;
  top: -50px;
}
#diamond-shield:after {
  content: '';
  position: absolute;
  left: -50px;
  top: 20px;
  width: 0;
  height: 0;
  border: 50px solid transparent;
  border-top: 70px solid red;
}

25.钻石2

1555920570-6519-41iu9fau8q
#cut-diamond {
  border-style: solid;
  border-color: transparent transparent red transparent;
  border-width: 0 25px 25px 25px;
  height: 0;
  width: 50px;
  box-sizing: content-box;
  position: relative;
  margin: 20px 0 50px 0;
}
#cut-diamond:after {
  content: "";
  position: absolute;
  top: 25px;
  left: -25px;
  width: 0;
  height: 0;
  border-style: solid;
  border-color: red transparent transparent transparent;
  border-width: 70px 50px 0 50px;
}

26.钻戒

1555920570-3764-7zt0mxmacs
#diamond-narrow {
  width: 0;
  height: 0;
  border: 50px solid transparent;
  border-bottom: 70px solid red;
  position: relative;
  top: -50px;
}
#diamond-narrow:after {
  content: '';
  position: absolute;
  left: -50px;
  top: 70px;
  width: 0;
  height: 0;
  border: 50px solid transparent;
  border-top: 70px solid red;
}

27. 鸡蛋

1555920570-3901-90u4mhvc51
#egg {
  display: block;
  width: 126px;
  height: 180px;
  background-color: red;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
}

28.吃豆人

1555920570-4027-lix78qjb2p
#pacman {
  width: 0px;
  height: 0px;
  border-right: 60px solid transparent;
  border-top: 60px solid red;
  border-left: 60px solid red;
  border-bottom: 60px solid red;
  border-top-left-radius: 60px;
  border-top-right-radius: 60px;
  border-bottom-left-radius: 60px;
  border-bottom-right-radius: 60px;
}

29.对话泡泡

1555920570-2424-5eb6e64ju8
#talkbubble {
  width: 120px;
  height: 80px;
  background: red;
  position: relative;
  -moz-border-radius: 10px;
  -webkit-border-radius: 10px;
  border-radius: 10px;
}
#talkbubble:before {
  content: "";
  position: absolute;
  right: 100%;
  top: 26px;
  width: 0;
  height: 0;
  border-top: 13px solid transparent;
  border-right: 26px solid red;
  border-bottom: 13px solid transparent;
}

30. 12点 爆发

1555920570-3819-xss6p6taac
#burst-12 {
  background: red;
  width: 80px;
  height: 80px;
  position: relative;
  text-align: center;
}
#burst-12:before,
#burst-12:after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  height: 80px;
  width: 80px;
  background: red;
}
#burst-12:before {
  transform: rotate(30deg);
}
#burst-12:after {
  transform: rotate(60deg);
}

31. 8点 爆发

1555920577-6692-5c7v2mdrgb
#burst-8 {
  background: red;
  width: 80px;
  height: 80px;
  position: relative;
  text-align: center;
  transform: rotate(20deg);
}
#burst-8:before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  height: 80px;
  width: 80px;
  background: red;
  transform: rotate(135deg);
}

32.太极

1555920577-9643-wjx9rogtp2
#yin-yang {
  width: 96px;
  box-sizing: content-box;
  height: 48px;
  background: #eee;
  border-color: red;
  border-style: solid;
  border-width: 2px 2px 50px 2px;
  border-radius: 100%;
  position: relative;
}
#yin-yang:before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  background: #eee;
  border: 18px solid red;
  border-radius: 100%;
  width: 12px;
  height: 12px;
  box-sizing: content-box;
}
#yin-yang:after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  background: red;
  border: 18px solid #eee;
  border-radius: 100%;
  width: 12px;
  height: 12px;
  box-sizing: content-box;
}

33.徽章丝带

1555920577-4075-nd4r68sv4z
#badge-ribbon {
  position: relative;
  background: red;
  height: 100px;
  width: 100px;
  border-radius: 50px;
}
#badge-ribbon:before,
#badge-ribbon:after {
  content: '';
  position: absolute;
  border-bottom: 70px solid red;
  border-left: 40px solid transparent;
  border-right: 40px solid transparent;
  top: 70px;
  left: -10px;
  transform: rotate(-140deg);
}
#badge-ribbon:after {
  left: auto;
  right: -10px;
  transform: rotate(140deg);
}

34.太空入侵者(电脑游戏名)

1555920578-4427-dzgg8erh4x
#space-invader {
  box-shadow: 0 0 0 1em red,
  0 1em 0 1em red,
  -2.5em 1.5em 0 .5em red,
  2.5em 1.5em 0 .5em red,
  -3em -3em 0 0 red,
  3em -3em 0 0 red,
  -2em -2em 0 0 red,
  2em -2em 0 0 red,
  -3em -1em 0 0 red,
  -2em -1em 0 0 red,
  2em -1em 0 0 red,
  3em -1em 0 0 red,
  -4em 0 0 0 red,
  -3em 0 0 0 red,
  3em 0 0 0 red,
  4em 0 0 0 red,
  -5em 1em 0 0 red,
  -4em 1em 0 0 red,
  4em 1em 0 0 red,
  5em 1em 0 0 red,
  -5em 2em 0 0 red,
  5em 2em 0 0 red,
  -5em 3em 0 0 red,
  -3em 3em 0 0 red,
  3em 3em 0 0 red,
  5em 3em 0 0 red,
  -2em 4em 0 0 red,
  -1em 4em 0 0 red,
  1em 4em 0 0 red,
  2em 4em 0 0 red;
  background: red;
  width: 1em;
  height: 1em;
  overflow: hidden;
  margin: 50px 0 70px 65px;
}

35.电视

1555920577-9174-pajfavgico
#tv {
  position: relative;
  width: 200px;
  height: 150px;
  margin: 20px 0;
  background: red;
  border-radius: 50% / 10%;
  color: white;
  text-align: center;
  text-indent: .1em;
}
#tv:before {
  content: '';
  position: absolute;
  top: 10%;
  bottom: 10%;
  right: -5%;
  left: -5%;
  background: inherit;
  border-radius: 5% / 50%;
}

36.雪佛龙

1555920578-4004-8fxu68r0ac
#chevron {
  position: relative;
  text-align: center;
  padding: 12px;
  margin-bottom: 6px;
  height: 60px;
  width: 200px;
}
#chevron:before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 51%;
  background: red;
  transform: skew(0deg, 6deg);
}
#chevron:after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 50%;
  background: red;
  transform: skew(0deg, -6deg);
}

37.放大镜

1555920585-4418-bavd9hoid4
#magnifying-glass {
  font-size: 10em;
  display: inline-block;
  width: 0.4em;
  box-sizing: content-box;
  height: 0.4em;
  border: 0.1em solid red;
  position: relative;
  border-radius: 0.35em;
}
#magnifying-glass:before {
  content: "";
  display: inline-block;
  position: absolute;
  right: -0.25em;
  bottom: -0.1em;
  border-width: 0;
  background: red;
  width: 0.35em;
  height: 0.08em;
  transform: rotate(45deg);
}

38.Facebook图标

1555920585-4803-lfd04facxu
#facebook-icon {
  background: red;
  text-indent: -999em;
  width: 100px;
  height: 110px;
  box-sizing: content-box;
  border-radius: 5px;
  position: relative;
  overflow: hidden;
  border: 15px solid red;
  border-bottom: 0;
}
#facebook-icon:before {
  content: "/20";
  position: absolute;
  background: red;
  width: 40px;
  height: 90px;
  bottom: -30px;
  right: -37px;
  border: 20px solid #eee;
  border-radius: 25px;
  box-sizing: content-box;
}
#facebook-icon:after {
  content: "/20";
  position: absolute;
  width: 55px;
  top: 50px;
  height: 20px;
  background: #eee;
  right: 5px;
  box-sizing: content-box;
}

39.月亮

1555920585-5902-54oftem3df
#moon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  box-shadow: 15px 15px 0 0 red;
}

40.旗

1555920585-6712-ek6zr17xvt
#flag {
  width: 110px;
  height: 56px;
  box-sizing: content-box;
  padding-top: 15px;
  position: relative;
  background: red;
  color: white;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-align: center;
  text-transform: uppercase;
}
#flag:after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 0;
  border-bottom: 13px solid #eee;
  border-left: 55px solid transparent;
  border-right: 55px solid transparent;
}

41.圆锥

1555920585-9424-v16dp8ajj6
 #cone {
  width: 0;
  height: 0;
  border-left: 70px solid transparent;
  border-right: 70px solid transparent;
  border-top: 100px solid red;
  border-radius: 50%;
}

42.十字架

1555920585-9326-87bq1dfxge
#cross {
  background: red;
  height: 100px;
  position: relative;
  width: 20px;
}
#cross:after {
  background: red;
  content: "";
  height: 20px;
  left: -40px;
  position: absolute;
  top: 40px;
  width: 100px;
}

43.根基

1555920590-1712-yw2u85cogf
 #base {
  background: red;
  display: inline-block;
  height: 55px;
  margin-left: 20px;
  margin-top: 55px;
  position: relative;
  width: 100px;
}
#base:before {
  border-bottom: 35px solid red;
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  content: "";
  height: 0;
  left: 0;
  position: absolute;
  top: -35px;
  width: 0;
}

44.指示器

1555920590-7140-omz3qy9ep1
#pointer {
  width: 200px;
  height: 40px;
  position: relative;
  background: red;
}
#pointer:after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 0;
  border-left: 20px solid white;
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;
}
#pointer:before {
  content: "";
  position: absolute;
  right: -20px;
  bottom: 0;
  width: 0;
  height: 0;
  border-left: 20px solid red;
  border-top: 20px solid transparent;
  border-bottom: 20px solid transparent;
}

45.锁

1555920590-1045-804p4klbbk
#lock {
  font-size: 8px;
  position: relative;
  width: 18em;
  height: 13em;
  border-radius: 2em;
  top: 10em;
  box-sizing: border-box;
  border: 3.5em solid red;
  border-right-width: 7.5em;
  border-left-width: 7.5em;
  margin: 0 0 6rem 0;
}
#lock:before {
  content: "";
  box-sizing: border-box;
  position: absolute;
  border: 2.5em solid red;
  width: 14em;
  height: 12em;
  left: 50%;
  margin-left: -7em;
  top: -12em;
  border-top-left-radius: 7em;
  border-top-right-radius: 7em;
}
#lock:after {
  content: "";
  box-sizing: border-box;
  position: absolute;
  border: 1em solid red;
  width: 5em;
  height: 8em;
  border-radius: 2.5em;
  left: 50%;
  top: -1em;
  margin-left: -2.5em;
}

 

ContOS使用vsftpd服务器的问题

一直都不适用vsftp,但是最近因为公司需要一个官网,所以才启动起来,安装vsftp很简单,可以搜索本站的资源“vsftpd”进行查阅,这个帖子只要是记录使用过程中的问题。

以前服务器的ContOS是6.5版本的,现在的版本是7.5,问题就随之而来了,以前出现过一次无法上传文件的问题,该问题是防火墙,帖子:“http://www.lanxinbase.com/?p=607”。

问题1:500 OOPS: vsftpd: refusing to run with writable root inside chroot ()。

解答:这个问题是因为你在vsftpd目录下的chroot_list文件中加入了FTP的用户名,只要把它删除就可以了;也可以把写入的权限去掉:chmod a-w /www。或者你可以在vsftpd的配置文件中增加下列两项中的一项:allow_writeable_chroot=YES

造成这个原因是因为,如:我们新建了一个www的用户,目录指向/www,并给/www赋予了写入的权限,所有就出现了500的错误。而chroot_list文件列表是制定需要锁定用户在它当前根目录的一个权限文件。简单点,如果你给了写入的权限,而又限制用户只能在它当前的根目录下,这样子会造成冲突,比如我上传一个文件夹。

*注:以前也遇到过这个问题是selinux的问题,所以要排除一下。

问题2:修改vsftp用户目录的问题。

解答:修改用户信息,使用usermod命令,其参数:

[root@iZ2zed1931stl3pem7ew6vZ vsftpd]# usermod –help
Usage: usermod [options] LOGIN

Options:
-c, –comment COMMENT new value of the GECOS field
-d, –home HOME_DIR new home directory for the user account
-e, –expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-f, –inactive INACTIVE set password inactive after expiration
to INACTIVE
-g, –gid GROUP force use GROUP as new primary group
-G, –groups GROUPS new list of supplementary GROUPS
-a, –append append the user to the supplemental GROUPS
mentioned by the -G option without removing
him/her from other groups
-h, –help display this help message and exit
-l, –login NEW_LOGIN new value of the login name
-L, –lock lock the user account
-m, –move-home move contents of the home directory to the
new location (use only with -d)
-o, –non-unique allow using duplicate (non-unique) UID
-p, –password PASSWORD use encrypted password for the new password
-R, –root CHROOT_DIR directory to chroot into
-s, –shell SHELL new login shell for the user account
-u, –uid UID new UID for the user account
-U, –unlock unlock the user account
-Z, –selinux-user SEUSER new SELinux user mapping for the user account

我就不翻译出来了,具体的自己拷贝到翻译软件里看一下就清楚了,但是这里主要介绍一下参数:-d、-u。

  • -d:new home directory for the user account(用户账号的新目录)
  • -u:new UID for the user account(用户的UID,应该就是唯一标识)

-d参数后面跟的目录很好解决,但是如果是-u的UID,你不知道是多少,那么可以使用命令: cat /etc/passwd |grep www

[root@iZ2zed1931stl3pem7ew6vZ vsftpd]# cat /etc/passwd |grep www
www:x:1000:1000::/www:/sbin/nologin

其中第一个1000就是UID,那么修改目录的命令,就应该如下:

usermod -m -d /www/home -u 1000 www;

usermod -d /www/home -m -u 1000 www;

*注:有些系统可能不需要-m的参数。

问题3:修改vsftp用户登陆密码。

解答:这个应该不是问题,就是:passwd www。

问题4:访问vsftp服务器出现200、227错误。

 

解答:ftp服务器有两种工作模式,port和pasv(主动和被动),这两种模式都是客户端先向服务器端发出请求,服务器建立链接,以服务器为对象,当传输数据时,如果是服务器从20端口向客户端空闲端口发送请求建立链接,就是port(主动),反之,如果是客户端向服务器空闲端口请求建立链接,就是pasv(被动)。

打开IE浏览器:选择设置—-internet—–高级—-使用被动FTP(为防火墙和DSL调制解调器兼容性)”前面的勾去掉。

001

 

问题5:450:读取目录列表失败。

解答:这个挺困扰的,我找了很久才发现,只需要在vsftp的配置文件vsftpd.conf加入pasv_enable=NO就可以了,接着重启一下服务器,引起整个原因是pasv的问题。

问题6:中文乱码的问题。

解答:中文乱码的问题其实我没有遇到过,网上的解决方案是改i18n,不过我们服务器的名称一般都是英文的,所以就不需要搭理它了。

问题7:530 Login incorrect.

解答:请检查一下密码是否输入错误。

问题8:550 外网无法登录。

解答:这个可能是没有开放tcp 20的端口,请检查一下防火墙规则配置文件。

问题9:其他问题。

这次出现过一次很奇葩的问题,但其实是FTP客户端的问题,我在登陆www账号的时候,FTP客户端居然把服务器“/”目录当成了用户的主目录,0.0吓死我了,搞了我一下午都没有找出问题来,后来第二天再登陆进去,发现正常了,根目录是/www,这就奇怪了,后来我再次改一下配置文件,然后换了不同的FTP客户端登陆,确定这个是客户端的问题。

所以遇到问题不要怕麻烦,一个个去排查就可以了。

 

 

 

Linux加载磁盘并分区

disk

fdisk [选项] <disk> 改变分区表

fdisk [选项] –l <disk> 列出所有分区表

fdisk –s <partition(分区编号)> 以分区块为单位,给出指定分区的大小

这是一个创建和维护分区的命令,兼容DOS类型的分区表、BSD或SUN类型的磁盘列表。注意fdisk不支持2T以上的硬盘分区,此时需要使用gdisk。

相关了解:

磁头数(Heads)表示硬盘有几个磁头,也就是有几面盘片,一个硬盘最多有255个磁头

柱面数(Cylinders)表示硬盘每面盘片上有几条磁道

扇区数(Sectors)表示每条磁道上有几个扇区,每条磁道最多有63个扇区

(1).参数

-b <size>  指定扇区大小(512,1024,2048或4096 B)
-c  关闭DOS兼容模式
-u <size>  以扇区编号取代柱面编号来表示每个分区的起始地址,一般与-l选项联合使用
-C <number>  指定柱面编号
-H <number>  指定磁头编号
-S <number>  指定磁道扇区编号

 

(2).菜单操作说明

a 设置可引导标记(活动分区/引导分区之间切换)
b 编辑BSD磁盘标签
c 设置DOS操作系统兼容标记(兼容/不兼容之间切换)
d 删除一个分区
l 显示已知的分区类型,其中82为Linux swap分区,83为Linux分区
m 显示帮助信息
n 增加一个新的分区
o 创建一个新的空白的DOS分区表
p 显示磁盘当前的分区表
q 退出fdisk程序,不保存任何修改
s 创建一个新的空白的Sun磁盘标签
t 改变一个分区的系统ID,就是改变分区类型(比如把Linux Swap分区改为Linux分区)
u 改变显示或输入单位
v 验证磁盘分区表
w 将分区表写入磁盘并退出(保存并退出)
x 额外功能(专家级)

注:使用fdisk <磁盘>可以进入到菜单操作,如:fdisk /dev/vdb

(3).磁盘分类

磁盘类型,从输出的文字区别,如/dev/vda 和 /dev/vdb 都是 virtio-block 类型的设备:
  • /dev/sda 是 sd 即 SCSI 类型的设备
  • fd:软盘驱动器
  • hd:IDE 磁盘
  • sd:SCSI 磁盘
  • tty:terminals
  • vd:virtio 磁盘

(3).例子

  • 使用-l选项,列出所有分区表

[root@iZ2zed1931stl3pem7ew6vZ /]# fdisk -l

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a57df

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83884031 41940992 83 Linux

Disk /dev/vdb: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

我这台linux有两个磁盘,一个是/dev/vda共42.9GB,另一个是/dev/vdb共64.4GB。

  • 使用-l和-u选项,以扇区编号取代柱面编号来表示每个分区的起始地址

[root@iZ2zed1931stl3pem7ew6vZ /]# fdisk -lu

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a57df

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83884031 41940992 83 Linux

Disk /dev/vdb: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

  • fdisk主要的菜单操作

[root@iZ2zed1931stl3pem7ew6vZ /]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x90e7133d.

Command (m for help):

分区操作(扩展分区):

[root@iZ2zed1931stl3pem7ew6vZ /]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x90e7133d.

Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): e
Partition number (1-4, default 1): 1
First sector (2048-125829119, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-125829119, default 125829119):
Using default value 125829119
Partition 1 of type Extended and of size 60 GiB is set

Command (m for help): p

Disk /dev/vdb: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x90e7133d

Device Boot Start End Blocks Id System
/dev/vdb1 2048 125829119 62913536 5 Extended

写入磁盘(保存):

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

此时在分一个逻辑分区:

[root@iZ2zed1931stl3pem7ew6vZ /]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): 1
Invalid partition type `1′

Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (4096-125829119, default 4096):
Using default value 4096
Last sector, +sectors or +size{K,M,G} (4096-125829119, default 125829119):
Using default value 125829119
Partition 5 of type Linux and of size 60 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@iZ2zed1931stl3pem7ew6vZ /]#

 

至此,分区完毕,使用fdisk -l查看磁盘分区:

[root@iZ2zed1931stl3pem7ew6vZ /]# fdisk -l

Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a57df

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83884031 41940992 83 Linux

Disk /dev/vdb: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x90e7133d

Device Boot Start End Blocks Id System
/dev/vdb1 2048 125829119 62913536 5 Extended
/dev/vdb5 4096 125829119 62912512 83 Linux

最后的/dev/vdb1就是刚刚分区的扩展分区,/dev/vdb5 是逻辑分区,但是还没有挂载到系统中。

Linux mount命令

Linux mount命令是经常会使用到的命令,它用于挂载Linux系统外的文件。

语法

mount [-hV]
mount -a [-fFnrsvw] [-t vfstype]
mount [-fnrsvw] [-o options [,...]] device | dir
mount [-fnrsvw] [-t vfstype] [-o options] device dir

参数说明:

  • -V:显示程序版本
  • -h:显示辅助讯息
  • -v:显示较讯息,通常和 -f 用来除错。
  • -a:将 /etc/fstab 中定义的所有档案系统挂上。
  • -F:这个命令通常和 -a 一起使用,它会为每一个 mount 的动作产生一个行程负责执行。在系统需要挂上大量 NFS 档案系统时可以加快挂上的动作。
  • -f:通常用在除错的用途。它会使 mount 并不执行实际挂上的动作,而是模拟整个挂上的过程。通常会和 -v 一起使用。
  • -n:一般而言,mount 在挂上后会在 /etc/mtab 中写入一笔资料。但在系统中没有可写入档案系统存在的情况下可以用这个选项取消这个动作。
  • -s-r:等于 -o ro
  • -w:等于 -o rw
  • -L:将含有特定标签的硬盘分割挂上。
  • -U:将档案分割序号为 的档案系统挂下。-L 和 -U 必须在/proc/partition 这种档案存在时才有意义。
  • -t:指定档案系统的型态,通常不必指定。mount 会自动选择正确的型态。
  • -o async:打开非同步模式,所有的档案读写动作都会用非同步模式执行。
  • -o sync:在同步模式下执行。
  • -o atime、-o noatime:当 atime 打开时,系统会在每次读取档案时更新档案的『上一次调用时间』。当我们使用 flash 档案系统时可能会选项把这个选项关闭以减少写入的次数。
  • -o auto、-o noauto:打开/关闭自动挂上模式。
  • -o defaults:使用预设的选项 rw, suid, dev, exec, auto, nouser, and async.
  • -o dev、-o nodev-o exec、-o noexec允许执行档被执行。
  • -o suid、-o nosuid:
  • 允许执行档在 root 权限下执行。
  • -o user、-o nouser:使用者可以执行 mount/umount 的动作。
  • -o remount:将一个已经挂下的档案系统重新用不同的方式挂上。例如原先是唯读的系统,现在用可读写的模式重新挂上。
  • -o ro:用唯读模式挂上。
  • -o rw:用可读写模式挂上。
  • -o loop=:使用 loop 模式用来将一个档案当成硬盘分割挂上系统。

(1).例子:

将/dev/vdb1挂在 /ww2 之下

[root@iZ2zed1931stl3pem7ew6vZ /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 4.9G 33G 14% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 600K 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 379M 0 379M 0% /run/user/0

首先使用df -h查看一下,当前的分区情况,然后再使用mount挂载分区:

[root@iZ2zed1931stl3pem7ew6vZ /]# mount /dev/vdb1 /ww2
mount: /dev/vdb1 is write-protected, mounting read-only
mount: unknown filesystem type ‘(null)’

//这里出错了,因为没有格式化,下面在试一次:

[root@iZ2zed1931stl3pem7ew6vZ /]# mkfs.ext4 /dev/vdb
vdb vdb1 vdb5
[root@iZ2zed1931stl3pem7ew6vZ /]# mkfs.ext4 /dev/vdb5
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3932160 inodes, 15728128 blocks
786406 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2164260864
480 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

[root@iZ2zed1931stl3pem7ew6vZ /]#

挂载分区:

[root@iZ2zed1931stl3pem7ew6vZ /]# mount /dev/vdb5 /ww2
[root@iZ2zed1931stl3pem7ew6vZ /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 4.9G 33G 14% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 604K 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
tmpfs 379M 0 379M 0% /run/user/0
/dev/vdb5 59G 53M 56G 1% /ww2

/dev/vdb5 59G 53M 56G 1% /ww2指向了ww2的目录,这样子挂载是临时的,如果需要下次开机自动挂载磁盘,就需要修改/etc/fstab文件。

12829303132118
 
Copyright © 2008-2021 lanxinbase.com Rights Reserved. | 粤ICP备14086738号-3 |