VOTING POWER100.00%
DOWNVOTE POWER100.00%
RESOURCE CREDITS100.00%
REPUTATION PROGRESS0.00%
Net Worth
0.007USD
STEEM
0.000STEEM
SBD
0.000SBD
Effective Power
5.007SP
├── Own SP
0.125SP
└── Incoming DelegationsDeleg
+4.881SP
Detailed Balance
| STEEM | ||
| balance | 0.000STEEM | STEEM |
| market_balance | 0.000STEEM | STEEM |
| savings_balance | 0.000STEEM | STEEM |
| reward_steem_balance | 0.000STEEM | STEEM |
| STEEM POWER | ||
| Own SP | 0.125SP | SP |
| Delegated Out | 0.000SP | SP |
| Delegation In | 4.881SP | SP |
| Effective Power | 5.007SP | SP |
| Reward SP (pending) | 0.000SP | SP |
| SBD | ||
| sbd_balance | 0.000SBD | SBD |
| sbd_conversions | 0.000SBD | SBD |
| sbd_market_balance | 0.000SBD | SBD |
| savings_sbd_balance | 0.000SBD | SBD |
| reward_sbd_balance | 0.000SBD | SBD |
{
"balance": "0.000 STEEM",
"savings_balance": "0.000 STEEM",
"reward_steem_balance": "0.000 STEEM",
"vesting_shares": "203.955921 VESTS",
"delegated_vesting_shares": "0.000000 VESTS",
"received_vesting_shares": "7939.703885 VESTS",
"sbd_balance": "0.000 SBD",
"savings_sbd_balance": "0.000 SBD",
"reward_sbd_balance": "0.000 SBD",
"conversions": []
}Account Info
| name | pmliang |
| id | 905201 |
| rank | 1,455,826 |
| reputation | 152858178 |
| created | 2018-04-02T09:39:06 |
| recovery_account | steem |
| proxy | None |
| post_count | 13 |
| comment_count | 0 |
| lifetime_vote_count | 0 |
| witnesses_voted_for | 0 |
| last_post | 2018-06-03T10:26:42 |
| last_root_post | 2018-06-03T10:12:03 |
| last_vote_time | 2018-06-04T04:21:57 |
| proxied_vsf_votes | 0, 0, 0, 0 |
| can_vote | 1 |
| voting_power | 0 |
| delayed_votes | 0 |
| balance | 0.000 STEEM |
| savings_balance | 0.000 STEEM |
| sbd_balance | 0.000 SBD |
| savings_sbd_balance | 0.000 SBD |
| vesting_shares | 203.955921 VESTS |
| delegated_vesting_shares | 0.000000 VESTS |
| received_vesting_shares | 7939.703885 VESTS |
| reward_vesting_balance | 0.000000 VESTS |
| vesting_balance | 0.000 STEEM |
| vesting_withdraw_rate | 0.000000 VESTS |
| next_vesting_withdrawal | 1969-12-31T23:59:59 |
| withdrawn | 0 |
| to_withdraw | 0 |
| withdraw_routes | 0 |
| savings_withdraw_requests | 0 |
| last_account_recovery | 1970-01-01T00:00:00 |
| reset_account | null |
| last_owner_update | 1970-01-01T00:00:00 |
| last_account_update | 1970-01-01T00:00:00 |
| mined | No |
| sbd_seconds | 0 |
| sbd_last_interest_payment | 1970-01-01T00:00:00 |
| savings_sbd_last_interest_payment | 1970-01-01T00:00:00 |
{
"id": 905201,
"name": "pmliang",
"owner": {
"weight_threshold": 1,
"account_auths": [],
"key_auths": [
[
"STM6ZzrmyJLMBDgYPL5HPNndbT1CJYPd2Beey7Aa3TFiPsrsNRtqS",
1
]
]
},
"active": {
"weight_threshold": 1,
"account_auths": [],
"key_auths": [
[
"STM6uQRsiZUTHmyrfP8R1ZxX8XuUdmpYBktZky74Si5MYq2ARS86V",
1
]
]
},
"posting": {
"weight_threshold": 1,
"account_auths": [],
"key_auths": [
[
"STM7xtH1TVHGoM7ycSbf5awcwH1aFuWdSE7b5k1MZUJhk1toWNCDX",
1
]
]
},
"memo_key": "STM6Ghf4hVZcPgcwME28XHiSGvXYEF6Mdbrdu5Ji1kryuBdas2YWx",
"json_metadata": "{}",
"posting_json_metadata": "",
"proxy": "",
"last_owner_update": "1970-01-01T00:00:00",
"last_account_update": "1970-01-01T00:00:00",
"created": "2018-04-02T09:39:06",
"mined": false,
"recovery_account": "steem",
"last_account_recovery": "1970-01-01T00:00:00",
"reset_account": "null",
"comment_count": 0,
"lifetime_vote_count": 0,
"post_count": 13,
"can_vote": true,
"voting_manabar": {
"current_mana": "8143659806",
"last_update_time": 1779080985
},
"downvote_manabar": {
"current_mana": 2035914951,
"last_update_time": 1779080985
},
"voting_power": 0,
"balance": "0.000 STEEM",
"savings_balance": "0.000 STEEM",
"sbd_balance": "0.000 SBD",
"sbd_seconds": "0",
"sbd_seconds_last_update": "1970-01-01T00:00:00",
"sbd_last_interest_payment": "1970-01-01T00:00:00",
"savings_sbd_balance": "0.000 SBD",
"savings_sbd_seconds": "0",
"savings_sbd_seconds_last_update": "1970-01-01T00:00:00",
"savings_sbd_last_interest_payment": "1970-01-01T00:00:00",
"savings_withdraw_requests": 0,
"reward_sbd_balance": "0.000 SBD",
"reward_steem_balance": "0.000 STEEM",
"reward_vesting_balance": "0.000000 VESTS",
"reward_vesting_steem": "0.000 STEEM",
"vesting_shares": "203.955921 VESTS",
"delegated_vesting_shares": "0.000000 VESTS",
"received_vesting_shares": "7939.703885 VESTS",
"vesting_withdraw_rate": "0.000000 VESTS",
"next_vesting_withdrawal": "1969-12-31T23:59:59",
"withdrawn": 0,
"to_withdraw": 0,
"withdraw_routes": 0,
"curation_rewards": 0,
"posting_rewards": 0,
"proxied_vsf_votes": [
0,
0,
0,
0
],
"witnesses_voted_for": 0,
"last_post": "2018-06-03T10:26:42",
"last_root_post": "2018-06-03T10:12:03",
"last_vote_time": "2018-06-04T04:21:57",
"post_bandwidth": 0,
"pending_claimed_accounts": 0,
"vesting_balance": "0.000 STEEM",
"reputation": 152858178,
"transfer_history": [],
"market_history": [],
"post_history": [],
"vote_history": [],
"other_history": [],
"witness_votes": [],
"tags_usage": [],
"guest_bloggers": [],
"rank": 1455826
}Withdraw Routes
| Incoming | Outgoing |
|---|---|
Empty | Empty |
{
"incoming": [],
"outgoing": []
}From Date
To Date
2026/05/18 05:09:45
2026/05/18 05:09:45
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 7939.703885 VESTS |
| Transaction Info | Block #106149313/Trx b2cbe1a3bf212d366bb434f6159d1ba6cea2f3fe |
View Raw JSON Data
{
"trx_id": "b2cbe1a3bf212d366bb434f6159d1ba6cea2f3fe",
"block": 106149313,
"trx_in_block": 0,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2026-05-18T05:09:45",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "7939.703885 VESTS"
}
]
}2026/05/12 23:45:18
2026/05/12 23:45:18
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 5227.493480 VESTS |
| Transaction Info | Block #105999556/Trx 2ba09cb3b9b792907c05586d0a0e1156516e4b2b |
View Raw JSON Data
{
"trx_id": "2ba09cb3b9b792907c05586d0a0e1156516e4b2b",
"block": 105999556,
"trx_in_block": 0,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2026-05-12T23:45:18",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "5227.493480 VESTS"
}
]
}2026/04/26 04:23:15
2026/04/26 04:23:15
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 7952.219641 VESTS |
| Transaction Info | Block #105516830/Trx b061be9ad514858f9183ca726be679c07734bec5 |
View Raw JSON Data
{
"trx_id": "b061be9ad514858f9183ca726be679c07734bec5",
"block": 105516830,
"trx_in_block": 2,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2026-04-26T04:23:15",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "7952.219641 VESTS"
}
]
}2026/01/23 20:59:09
2026/01/23 20:59:09
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 5269.040299 VESTS |
| Transaction Info | Block #102867605/Trx 9edb61439c0f43984e6d21b07e7b9a8c862076d6 |
View Raw JSON Data
{
"trx_id": "9edb61439c0f43984e6d21b07e7b9a8c862076d6",
"block": 102867605,
"trx_in_block": 1,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2026-01-23T20:59:09",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "5269.040299 VESTS"
}
]
}2024/12/17 16:10:00
2024/12/17 16:10:00
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 5433.259496 VESTS |
| Transaction Info | Block #91313835/Trx ff58bbffe48157505d6a9da1034298b628c1ead9 |
View Raw JSON Data
{
"trx_id": "ff58bbffe48157505d6a9da1034298b628c1ead9",
"block": 91313835,
"trx_in_block": 2,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2024-12-17T16:10:00",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "5433.259496 VESTS"
}
]
}2023/11/14 07:51:27
2023/11/14 07:51:27
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 5602.393028 VESTS |
| Transaction Info | Block #79867996/Trx 345a22f1fa77977d189b98da2c4112d1e63fe019 |
View Raw JSON Data
{
"trx_id": "345a22f1fa77977d189b98da2c4112d1e63fe019",
"block": 79867996,
"trx_in_block": 1,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2023-11-14T07:51:27",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "5602.393028 VESTS"
}
]
}2023/09/22 09:02:51
2023/09/22 09:02:51
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 8539.301814 VESTS |
| Transaction Info | Block #78361258/Trx bcc6d2e83cdf2562ba8a36ef1b444769db7db2bb |
View Raw JSON Data
{
"trx_id": "bcc6d2e83cdf2562ba8a36ef1b444769db7db2bb",
"block": 78361258,
"trx_in_block": 6,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2023-09-22T09:02:51",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "8539.301814 VESTS"
}
]
}2022/11/03 16:41:18
2022/11/03 16:41:18
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 8761.353252 VESTS |
| Transaction Info | Block #69119216/Trx ffcb8c821e896c7c15b8d6c74c1abc744ee35a26 |
View Raw JSON Data
{
"trx_id": "ffcb8c821e896c7c15b8d6c74c1abc744ee35a26",
"block": 69119216,
"trx_in_block": 2,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2022-11-03T16:41:18",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "8761.353252 VESTS"
}
]
}2022/01/17 22:00:24
2022/01/17 22:00:24
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 8981.460853 VESTS |
| Transaction Info | Block #60822605/Trx bf58a8ea0fbb0533445aea63f3e3157486372b11 |
View Raw JSON Data
{
"trx_id": "bf58a8ea0fbb0533445aea63f3e3157486372b11",
"block": 60822605,
"trx_in_block": 19,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2022-01-17T22:00:24",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "8981.460853 VESTS"
}
]
}2021/06/14 05:14:06
2021/06/14 05:14:06
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 9165.655141 VESTS |
| Transaction Info | Block #54612991/Trx 9120c16888c1803a6af82b61af139a1fd4e546b9 |
View Raw JSON Data
{
"trx_id": "9120c16888c1803a6af82b61af139a1fd4e546b9",
"block": 54612991,
"trx_in_block": 5,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2021-06-14T05:14:06",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "9165.655141 VESTS"
}
]
}2020/12/11 15:27:21
2020/12/11 15:27:21
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 9353.077115 VESTS |
| Transaction Info | Block #49360287/Trx 9af7f29263ac2f73d5bbf807b01b9e195173f247 |
View Raw JSON Data
{
"trx_id": "9af7f29263ac2f73d5bbf807b01b9e195173f247",
"block": 49360287,
"trx_in_block": 0,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2020-12-11T15:27:21",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "9353.077115 VESTS"
}
]
}2020/12/06 09:03:30
2020/12/06 09:03:30
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 1912.543513 VESTS |
| Transaction Info | Block #49211817/Trx e5b3f84cc1471e4b5b0acf9755fcc6e5856a401c |
View Raw JSON Data
{
"trx_id": "e5b3f84cc1471e4b5b0acf9755fcc6e5856a401c",
"block": 49211817,
"trx_in_block": 1,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2020-12-06T09:03:30",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "1912.543513 VESTS"
}
]
}2020/12/05 19:05:12
2020/12/05 19:05:12
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 9359.284969 VESTS |
| Transaction Info | Block #49195369/Trx cf2d35ad394ff0eeb09807b9ea7e74f66b6adaa6 |
View Raw JSON Data
{
"trx_id": "cf2d35ad394ff0eeb09807b9ea7e74f66b6adaa6",
"block": 49195369,
"trx_in_block": 13,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2020-12-05T19:05:12",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "9359.284969 VESTS"
}
]
}2020/11/03 00:36:51
2020/11/03 00:36:51
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 1920.017158 VESTS |
| Transaction Info | Block #48268368/Trx 8d006024fe4a6d0e843712e57382d69246498b17 |
View Raw JSON Data
{
"trx_id": "8d006024fe4a6d0e843712e57382d69246498b17",
"block": 48268368,
"trx_in_block": 0,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2020-11-03T00:36:51",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "1920.017158 VESTS"
}
]
}2020/05/09 10:05:24
2020/05/09 10:05:24
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 9562.090328 VESTS |
| Transaction Info | Block #43222131/Trx 3eaebf7309458c8b968260bbea78f4423320004b |
View Raw JSON Data
{
"trx_id": "3eaebf7309458c8b968260bbea78f4423320004b",
"block": 43222131,
"trx_in_block": 22,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2020-05-09T10:05:24",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "9562.090328 VESTS"
}
]
}2020/05/08 14:20:51
2020/05/08 14:20:51
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 1953.311140 VESTS |
| Transaction Info | Block #43198999/Trx 74fe08cbb4523396b317fd979e6b8aef5ae8ac33 |
View Raw JSON Data
{
"trx_id": "74fe08cbb4523396b317fd979e6b8aef5ae8ac33",
"block": 43198999,
"trx_in_block": 3,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2020-05-08T14:20:51",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "1953.311140 VESTS"
}
]
}2019/08/18 00:18:09
2019/08/18 00:18:09
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 9713.187220 VESTS |
| Transaction Info | Block #35645405/Trx de5537e94e34e0c9904db62e7086acea5d4e70b3 |
View Raw JSON Data
{
"trx_id": "de5537e94e34e0c9904db62e7086acea5d4e70b3",
"block": 35645405,
"trx_in_block": 33,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2019-08-18T00:18:09",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "9713.187220 VESTS"
}
]
}2019/04/02 11:01:06
2019/04/02 11:01:06
| parent author | pmliang |
| parent permlink | kubernetes |
| author | steemitboard |
| permlink | steemitboard-notify-pmliang-20190402t110106000z |
| title | |
| body | Congratulations @pmliang! You received a personal award! <table><tr><td>https://steemitimages.com/70x70/http://steemitboard.com/@pmliang/birthday1.png</td><td>Happy Birthday! - You are on the Steem blockchain for 1 year!</td></tr></table> <sub>_You can view [your badges on your Steem Board](https://steemitboard.com/@pmliang) and compare to others on the [Steem Ranking](http://steemitboard.com/ranking/index.php?name=pmliang)_</sub> ###### [Vote for @Steemitboard as a witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1) to get one more award and increased upvotes! |
| json metadata | {"image":["https://steemitboard.com/img/notify.png"]} |
| Transaction Info | Block #31691068/Trx 5bd28728b32042d49b453f350a681d39365c9b3e |
View Raw JSON Data
{
"trx_id": "5bd28728b32042d49b453f350a681d39365c9b3e",
"block": 31691068,
"trx_in_block": 14,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2019-04-02T11:01:06",
"op": [
"comment",
{
"parent_author": "pmliang",
"parent_permlink": "kubernetes",
"author": "steemitboard",
"permlink": "steemitboard-notify-pmliang-20190402t110106000z",
"title": "",
"body": "Congratulations @pmliang! You received a personal award!\n\n<table><tr><td>https://steemitimages.com/70x70/http://steemitboard.com/@pmliang/birthday1.png</td><td>Happy Birthday! - You are on the Steem blockchain for 1 year!</td></tr></table>\n\n<sub>_You can view [your badges on your Steem Board](https://steemitboard.com/@pmliang) and compare to others on the [Steem Ranking](http://steemitboard.com/ranking/index.php?name=pmliang)_</sub>\n\n\n###### [Vote for @Steemitboard as a witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1) to get one more award and increased upvotes!",
"json_metadata": "{\"image\":[\"https://steemitboard.com/img/notify.png\"]}"
}
]
}2018/09/03 04:49:30
2018/09/03 04:49:30
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 9911.695365 VESTS |
| Transaction Info | Block #25626842/Trx 7c86a971b829a7e0f979c7516f284d342b37f081 |
View Raw JSON Data
{
"trx_id": "7c86a971b829a7e0f979c7516f284d342b37f081",
"block": 25626842,
"trx_in_block": 31,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-09-03T04:49:30",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "9911.695365 VESTS"
}
]
}2018/08/08 01:21:15
2018/08/08 01:21:15
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 30185.714588 VESTS |
| Transaction Info | Block #24874223/Trx 6cbfdc0b28276681b22922a1249a5d336abbb83b |
View Raw JSON Data
{
"trx_id": "6cbfdc0b28276681b22922a1249a5d336abbb83b",
"block": 24874223,
"trx_in_block": 4,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-08-08T01:21:15",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "30185.714588 VESTS"
}
]
}2018/06/04 13:54:18
2018/06/04 13:54:18
| voter | standard-energy |
| author | pmliang |
| permlink | re-standard-energy-cryptocurrency-ontology-soars-finally-koreans-have-noticed-something-20180603t102329751z |
| weight | -10000 (-100.00%) |
| Transaction Info | Block #23028903/Trx 87c9b71ddb77335c359f3759797bc7c42523cb66 |
View Raw JSON Data
{
"trx_id": "87c9b71ddb77335c359f3759797bc7c42523cb66",
"block": 23028903,
"trx_in_block": 0,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-04T13:54:18",
"op": [
"vote",
{
"voter": "standard-energy",
"author": "pmliang",
"permlink": "re-standard-energy-cryptocurrency-ontology-soars-finally-koreans-have-noticed-something-20180603t102329751z",
"weight": -10000
}
]
}2018/06/04 13:23:57
2018/06/04 13:23:57
| voter | standard-energy |
| author | pmliang |
| permlink | re-standard-energy-cryptocurrency-ontology-soars-finally-koreans-have-noticed-something-20180603t102329751z |
| weight | 0 (0.00%) |
| Transaction Info | Block #23028296/Trx fcce0db8d51a6bf80a38c0a1c823b04bbff7bf93 |
View Raw JSON Data
{
"trx_id": "fcce0db8d51a6bf80a38c0a1c823b04bbff7bf93",
"block": 23028296,
"trx_in_block": 5,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-04T13:23:57",
"op": [
"vote",
{
"voter": "standard-energy",
"author": "pmliang",
"permlink": "re-standard-energy-cryptocurrency-ontology-soars-finally-koreans-have-noticed-something-20180603t102329751z",
"weight": 0
}
]
}2018/06/04 12:27:33
2018/06/04 12:27:33
| voter | standard-energy |
| author | pmliang |
| permlink | re-standard-energy-cryptocurrency-ontology-soars-finally-koreans-have-noticed-something-20180603t102329751z |
| weight | 10000 (100.00%) |
| Transaction Info | Block #23027168/Trx 4130a99047d23f0063cd68b0d7577a2b3a550978 |
View Raw JSON Data
{
"trx_id": "4130a99047d23f0063cd68b0d7577a2b3a550978",
"block": 23027168,
"trx_in_block": 3,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-04T12:27:33",
"op": [
"vote",
{
"voter": "standard-energy",
"author": "pmliang",
"permlink": "re-standard-energy-cryptocurrency-ontology-soars-finally-koreans-have-noticed-something-20180603t102329751z",
"weight": 10000
}
]
}2018/06/04 12:27:21
2018/06/04 12:27:21
| voter | standard-energy |
| author | pmliang |
| permlink | re-standard-energy-cryptocurrency-ontology-soars-finally-koreans-have-noticed-something-20180603t102329751z |
| weight | 0 (0.00%) |
| Transaction Info | Block #23027164/Trx 7e0f28f5661105199a931742adca6608727d9727 |
View Raw JSON Data
{
"trx_id": "7e0f28f5661105199a931742adca6608727d9727",
"block": 23027164,
"trx_in_block": 32,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-04T12:27:21",
"op": [
"vote",
{
"voter": "standard-energy",
"author": "pmliang",
"permlink": "re-standard-energy-cryptocurrency-ontology-soars-finally-koreans-have-noticed-something-20180603t102329751z",
"weight": 0
}
]
}pmliangupvoted (100.00%) @pmliang / kubernetes2018/06/04 04:21:57
pmliangupvoted (100.00%) @pmliang / kubernetes
2018/06/04 04:21:57
| voter | pmliang |
| author | pmliang |
| permlink | kubernetes |
| weight | 10000 (100.00%) |
| Transaction Info | Block #23017457/Trx c4beeb71774248934fc18af585eaca1b873bd7b3 |
View Raw JSON Data
{
"trx_id": "c4beeb71774248934fc18af585eaca1b873bd7b3",
"block": 23017457,
"trx_in_block": 33,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-04T04:21:57",
"op": [
"vote",
{
"voter": "pmliang",
"author": "pmliang",
"permlink": "kubernetes",
"weight": 10000
}
]
}2018/06/03 13:23:42
2018/06/03 13:23:42
| parent author | pmliang |
| parent permlink | kubernetes |
| author | steemitboard |
| permlink | steemitboard-notify-pmliang-20180603t132344000z |
| title | |
| body | Congratulations @pmliang! You have completed some achievement on Steemit and have been rewarded with new badge(s) : [](http://steemitboard.com/@pmliang) You got a First Reply Click on any badge to view your Board of Honor. For more information about SteemitBoard, click [here](https://steemit.com/@steemitboard) If you no longer want to receive notifications, reply to this comment with the word `STOP` > Do you like **SteemitBoard**'s project? **[Vote for its witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1)** and **get one more award**! |
| json metadata | {"image":["https://steemitboard.com/img/notify.png"]} |
| Transaction Info | Block #22999493/Trx c978624b177a72a3ac0b928fcf6aa551eed325ab |
View Raw JSON Data
{
"trx_id": "c978624b177a72a3ac0b928fcf6aa551eed325ab",
"block": 22999493,
"trx_in_block": 68,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-03T13:23:42",
"op": [
"comment",
{
"parent_author": "pmliang",
"parent_permlink": "kubernetes",
"author": "steemitboard",
"permlink": "steemitboard-notify-pmliang-20180603t132344000z",
"title": "",
"body": "Congratulations @pmliang! You have completed some achievement on Steemit and have been rewarded with new badge(s) :\n\n[](http://steemitboard.com/@pmliang) You got a First Reply\n\nClick on any badge to view your Board of Honor.\nFor more information about SteemitBoard, click [here](https://steemit.com/@steemitboard)\n\nIf you no longer want to receive notifications, reply to this comment with the word `STOP`\n\n> Do you like **SteemitBoard**'s project? **[Vote for its witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1)** and **get one more award**!",
"json_metadata": "{\"image\":[\"https://steemitboard.com/img/notify.png\"]}"
}
]
}2018/06/03 12:17:27
2018/06/03 12:17:27
| parent author | pmliang |
| parent permlink | re-dinhtien95tn-cap-nhat-quan-trong-bounty-aelf-oct-and-cortex-nhiem-vu-moi-20180603t102609672z |
| author | dinhtien95tn |
| permlink | re-pmliang-re-dinhtien95tn-cap-nhat-quan-trong-bounty-aelf-oct-and-cortex-nhiem-vu-moi-20180603t121724815z |
| title | |
| body | yes, thank you! |
| json metadata | {"tags":["aelf"],"app":"steemit/0.1"} |
| Transaction Info | Block #22998168/Trx e030f4c92611344ea67d2595a5ad3ac969b99de3 |
View Raw JSON Data
{
"trx_id": "e030f4c92611344ea67d2595a5ad3ac969b99de3",
"block": 22998168,
"trx_in_block": 33,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-03T12:17:27",
"op": [
"comment",
{
"parent_author": "pmliang",
"parent_permlink": "re-dinhtien95tn-cap-nhat-quan-trong-bounty-aelf-oct-and-cortex-nhiem-vu-moi-20180603t102609672z",
"author": "dinhtien95tn",
"permlink": "re-pmliang-re-dinhtien95tn-cap-nhat-quan-trong-bounty-aelf-oct-and-cortex-nhiem-vu-moi-20180603t121724815z",
"title": "",
"body": "yes, thank you!",
"json_metadata": "{\"tags\":[\"aelf\"],\"app\":\"steemit/0.1\"}"
}
]
}anomalyupvoted (1.00%) @pmliang / kubernetes2018/06/03 10:46:51
anomalyupvoted (1.00%) @pmliang / kubernetes
2018/06/03 10:46:51
| voter | anomaly |
| author | pmliang |
| permlink | kubernetes |
| weight | 100 (1.00%) |
| Transaction Info | Block #22996356/Trx b4de4199e1c0fb6f47b53331d3855f5792c45298 |
View Raw JSON Data
{
"trx_id": "b4de4199e1c0fb6f47b53331d3855f5792c45298",
"block": 22996356,
"trx_in_block": 35,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-03T10:46:51",
"op": [
"vote",
{
"voter": "anomaly",
"author": "pmliang",
"permlink": "kubernetes",
"weight": 100
}
]
}standard-energyupvoted (100.00%) @pmliang / kubernetes2018/06/03 10:31:24
standard-energyupvoted (100.00%) @pmliang / kubernetes
2018/06/03 10:31:24
| voter | standard-energy |
| author | pmliang |
| permlink | kubernetes |
| weight | 10000 (100.00%) |
| Transaction Info | Block #22996047/Trx 8d4af0c411f1a11375b26a0f781fa2abdbf973f6 |
View Raw JSON Data
{
"trx_id": "8d4af0c411f1a11375b26a0f781fa2abdbf973f6",
"block": 22996047,
"trx_in_block": 19,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-03T10:31:24",
"op": [
"vote",
{
"voter": "standard-energy",
"author": "pmliang",
"permlink": "kubernetes",
"weight": 10000
}
]
}2018/06/03 10:27:57
2018/06/03 10:27:57
| parent author | pmliang |
| parent permlink | re-standard-energy-cryptocurrency-ontology-soars-finally-koreans-have-noticed-something-20180603t102329751z |
| author | standard-energy |
| permlink | re-pmliang-re-standard-energy-cryptocurrency-ontology-soars-finally-koreans-have-noticed-something-20180603t102757705z |
| title | |
| body | Thank you for your "First reply" on my Steemit. You will be my VIP! |
| json metadata | {"tags":["cryptocurrency"],"app":"steemit/0.1"} |
| Transaction Info | Block #22995978/Trx 113eca712a9961530e26b7493bec145a801884b9 |
View Raw JSON Data
{
"trx_id": "113eca712a9961530e26b7493bec145a801884b9",
"block": 22995978,
"trx_in_block": 35,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-03T10:27:57",
"op": [
"comment",
{
"parent_author": "pmliang",
"parent_permlink": "re-standard-energy-cryptocurrency-ontology-soars-finally-koreans-have-noticed-something-20180603t102329751z",
"author": "standard-energy",
"permlink": "re-pmliang-re-standard-energy-cryptocurrency-ontology-soars-finally-koreans-have-noticed-something-20180603t102757705z",
"title": "",
"body": "Thank you for your \"First reply\" on my Steemit.\nYou will be my VIP!",
"json_metadata": "{\"tags\":[\"cryptocurrency\"],\"app\":\"steemit/0.1\"}"
}
]
}2018/06/03 10:27:03
2018/06/03 10:27:03
| voter | standard-energy |
| author | pmliang |
| permlink | re-standard-energy-cryptocurrency-ontology-soars-finally-koreans-have-noticed-something-20180603t102329751z |
| weight | 10000 (100.00%) |
| Transaction Info | Block #22995960/Trx 25ac4b1c2c00530e5c9196b6616c67bf809580bf |
View Raw JSON Data
{
"trx_id": "25ac4b1c2c00530e5c9196b6616c67bf809580bf",
"block": 22995960,
"trx_in_block": 4,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-03T10:27:03",
"op": [
"vote",
{
"voter": "standard-energy",
"author": "pmliang",
"permlink": "re-standard-energy-cryptocurrency-ontology-soars-finally-koreans-have-noticed-something-20180603t102329751z",
"weight": 10000
}
]
}2018/06/03 10:26:42
2018/06/03 10:26:42
| parent author | dinhtien95tn |
| parent permlink | cap-nhat-quan-trong-bounty-aelf-oct-and-cortex-nhiem-vu-moi |
| author | pmliang |
| permlink | re-dinhtien95tn-cap-nhat-quan-trong-bounty-aelf-oct-and-cortex-nhiem-vu-moi-20180603t102609672z |
| title | |
| body | Hello, can you give the thumbs-up each other, thank you |
| json metadata | {"tags":["aelf"],"app":"steemit/0.1"} |
| Transaction Info | Block #22995953/Trx 22990dadda444978af380bb65beb6a6ba1664d63 |
View Raw JSON Data
{
"trx_id": "22990dadda444978af380bb65beb6a6ba1664d63",
"block": 22995953,
"trx_in_block": 5,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-03T10:26:42",
"op": [
"comment",
{
"parent_author": "dinhtien95tn",
"parent_permlink": "cap-nhat-quan-trong-bounty-aelf-oct-and-cortex-nhiem-vu-moi",
"author": "pmliang",
"permlink": "re-dinhtien95tn-cap-nhat-quan-trong-bounty-aelf-oct-and-cortex-nhiem-vu-moi-20180603t102609672z",
"title": "",
"body": "Hello, can you give the thumbs-up each other, thank you",
"json_metadata": "{\"tags\":[\"aelf\"],\"app\":\"steemit/0.1\"}"
}
]
}pmliangupvoted (100.00%) @dinhtien95tn / cap-nhat-quan-trong-bounty-aelf-oct-and-cortex-nhiem-vu-moi2018/06/03 10:26:18
pmliangupvoted (100.00%) @dinhtien95tn / cap-nhat-quan-trong-bounty-aelf-oct-and-cortex-nhiem-vu-moi
2018/06/03 10:26:18
| voter | pmliang |
| author | dinhtien95tn |
| permlink | cap-nhat-quan-trong-bounty-aelf-oct-and-cortex-nhiem-vu-moi |
| weight | 10000 (100.00%) |
| Transaction Info | Block #22995945/Trx 06a6ad791170773be5b967120ae253cd2c60b1f9 |
View Raw JSON Data
{
"trx_id": "06a6ad791170773be5b967120ae253cd2c60b1f9",
"block": 22995945,
"trx_in_block": 30,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-03T10:26:18",
"op": [
"vote",
{
"voter": "pmliang",
"author": "dinhtien95tn",
"permlink": "cap-nhat-quan-trong-bounty-aelf-oct-and-cortex-nhiem-vu-moi",
"weight": 10000
}
]
}pmliangupvoted (100.00%) @maarnio / crypto-contest-june-2-aelf2018/06/03 10:25:09
pmliangupvoted (100.00%) @maarnio / crypto-contest-june-2-aelf
2018/06/03 10:25:09
| voter | pmliang |
| author | maarnio |
| permlink | crypto-contest-june-2-aelf |
| weight | 10000 (100.00%) |
| Transaction Info | Block #22995922/Trx 8336bf79a743136f7340408f0a75b3778337592c |
View Raw JSON Data
{
"trx_id": "8336bf79a743136f7340408f0a75b3778337592c",
"block": 22995922,
"trx_in_block": 5,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-03T10:25:09",
"op": [
"vote",
{
"voter": "pmliang",
"author": "maarnio",
"permlink": "crypto-contest-june-2-aelf",
"weight": 10000
}
]
}2018/06/03 10:24:18
2018/06/03 10:24:18
| voter | pmliang |
| author | standard-energy |
| permlink | cryptocurrency-ontology-soars-finally-koreans-have-noticed-something |
| weight | 10000 (100.00%) |
| Transaction Info | Block #22995905/Trx 137903b11835cd8002d27fcf6a4e1c2464990d46 |
View Raw JSON Data
{
"trx_id": "137903b11835cd8002d27fcf6a4e1c2464990d46",
"block": 22995905,
"trx_in_block": 16,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-03T10:24:18",
"op": [
"vote",
{
"voter": "pmliang",
"author": "standard-energy",
"permlink": "cryptocurrency-ontology-soars-finally-koreans-have-noticed-something",
"weight": 10000
}
]
}2018/06/03 10:23:30
2018/06/03 10:23:30
| parent author | standard-energy |
| parent permlink | cryptocurrency-ontology-soars-finally-koreans-have-noticed-something |
| author | pmliang |
| permlink | re-standard-energy-cryptocurrency-ontology-soars-finally-koreans-have-noticed-something-20180603t102329751z |
| title | |
| body | Hello, can you give the thumbs-up each other, thank you |
| json metadata | {"tags":["cryptocurrency"],"app":"steemit/0.1"} |
| Transaction Info | Block #22995889/Trx 2c3cd3ea517b47fc2125b14e0685301a0a890ae1 |
View Raw JSON Data
{
"trx_id": "2c3cd3ea517b47fc2125b14e0685301a0a890ae1",
"block": 22995889,
"trx_in_block": 36,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-03T10:23:30",
"op": [
"comment",
{
"parent_author": "standard-energy",
"parent_permlink": "cryptocurrency-ontology-soars-finally-koreans-have-noticed-something",
"author": "pmliang",
"permlink": "re-standard-energy-cryptocurrency-ontology-soars-finally-koreans-have-noticed-something-20180603t102329751z",
"title": "",
"body": "Hello, can you give the thumbs-up each other, thank you",
"json_metadata": "{\"tags\":[\"cryptocurrency\"],\"app\":\"steemit/0.1\"}"
}
]
}pmliangpublished a new post: kubernetes2018/06/03 10:12:03
pmliangpublished a new post: kubernetes
2018/06/03 10:12:03
| parent author | |
| parent permlink | kubernetes |
| author | pmliang |
| permlink | kubernetes |
| title | kubernetes集群安装 |
| body | ## `kubernetes`集群手工安装 > 这里以一台`master`节点和一台`node`节点为例,其中我将`master`也用作`node` #### 一、master节点 > 先关闭防火墙: ``` # systemctl stop firewalld # systemctl disable firewalld ``` - 安装`etcd` 首先需要在GitHub上下载`etcd`的二进制文件包,这里以`etcd-v3.1.15-linux-amd64.tar.gz`为例 我写了个简单的安装etcd的脚本,可以参考一下 ``` # cat install-etcd.sh #!/bin/bash tar xzf etcd-v3.1.15-linux-amd64.tar.gz cp etcd-v3.1.15-linux-amd64/etcd etcd-v3.1.15-linux-amd64/etcdctl /usr/bin if [ ! -e /var/lib/etcd ]; then mkdir /var/lib/etcd fi cat > /usr/lib/systemd/system/etcd.service << EOF [Unit] Description=Etcd Server After=network.target [Service] Type=simple WorkingDirectory=/var/lib/etcd/ EnvironmentFile=-/etc/etcd/etcd.conf ExecStart=/usr/bin/etcd Restart=on-failure [Install] WantedBy=multi-user.target EOF if [ ! -e /etc/etcd ]; then mkdir /etc/etcd fi cat > /etc/etcd/etcd.conf << EOF ETCD_DATA_DIR="/var/lib/etcd/default.etcd" ETCD_LISTEN_CLIENT_URLS="http://127.0.0.1:2379" ETCD_NAME="default" ETCD_ADVERTISE_CLIENT_URLS="http://127.0.0.1:2379" EOF systemctl daemon-reload systemctl start etcd.service systemctl enable etcd.service etcdctl cluster-health ``` 步骤为:1.将etcd和etcdctl二进制文件复制到`/usr/bin`目录下,或者其他`PATH`路径下,只需要在service文件中写正确即可。2.设置服务文件。3.编辑配置文件(详细的参数可以参考官网) 至此,etcd服务安装完成。 - `kube-apiserver`服务,首先在GitHub上下载kubernetes的二进制包,这里以1.3.0版本的`kubernetes.tar.gz`为例 这里也通过脚本来说明: ``` # cat install-apiserver.sh tar xzf kubernetes.tar.gz tar xzf kubernetes/server/kubernetes-server-linux-amd64.tar.gz cp -a kubernetes/server/bin/kube-apiserver /usr/bin cat > /usr/lib/systemd/system/kube-apiserver.service << EOF [Unit] Description=Kubernetes API Server Documentation=https://github.com/GoogleCloudPlatform/kubernetes After=network.target After=etcd.service [Service] EnvironmentFile=-/etc/kubernetes/apiserver User=kube ExecStart=/usr/bin/kube-apiserver \ \$KUBE_ETCD_SERVERS \ \$KUBE_API_ADDRESS \ \$KUBE_SERVICE_ADDRESSES \ \$KUBE_ADMISSION_CONTROL \ \$KUBE_API_ARGS Restart=on-failure Type=notify LimitNOFILE=65536 [Install] WantedBy=multi-user.target EOF if [ ! -e /etc/kubernetes ]; then mkdir /etc/kubernetes fi cat > /etc/kubernetes/apiserver << EOF KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0 --insecure-port=8080" KUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379" KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16" KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota" KUBE_API_ARGS="--service-node-port-range=1-65535" EOF systemctl daemon-reload systemctl start kube-apiserver systemctl enable kube-apiserver systemctl is-active kube-apiserver ``` 启动参数: 1). --insecure-bind-address:apiserver绑定主机的非安全ip地址,0.0.0.0表示绑定所有ip地址 2). --insecure-port=8080:apiserver绑定的非安全端口,默认8080 3). --etcd-servers:etcd服务的地址 4). --service-cluster-ip-range:apiserver分配给集群中service的虚拟IP的网段,不能与物理机的IP地址段重合 5). --admission-control:集群中准入控制,详细的见官网 6). --service-node-port-range:端口映射物理机的范围,默认为30000-32767 > 其他的启动参数详见官方网站 - kube-controller-manager服务 ``` # cat install-controller-manager.sh #!/bin/bash IPADDR=`ifconfig ens32 | grep '\binet\b' | awk '{print $2}'` cp kubernetes/server/bin/kube-controller-manager /usr/bin cat > /usr/lib/systemd/system/kube-controller-manager.service << EOF [Unit] Description=Kubernetes Controller Manager Documentation=https://github.com/GoogleCloudPlatform/kubernetes After=kube-apiserver.service Requires=kube-apiserver.service [Service] EnvironmentFile=-/etc/kubernetes/controller-manager ExecStart=/usr/bin/kube-controller-manager \$KUBE_CONTROLLER_MANAGER_ARGS Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target EOF cat > /etc/kubernetes/controller-manager << EOF KUBE_CONTROLLER_MANAGER_ARGS="--master=http://$IPADDR:8080" EOF systemctl daemon-reload systemctl start kube-controller-manager systemctl enable kube-controller-manager ``` - kube-scheduler服务 ``` # cat install-scheduler.sh #!/bin/bash IPADDR=`ifconfig ens32 | grep '\binet\b' | awk '{print $2}'` cp kubernetes/server/bin/kubectl /usr/bin cp kubernetes/server/bin/kube-scheduler /usr/bin cat > /usr/lib/systemd/system/kube-scheduler.service << EOF [Unit] Description=Kubernetes Scheduler Plugin Documentation=https://github.com/GoogleCloudPlatform/kubernetes After=kube-apiserver.service Requires=kube-apiserver.service [Service] EnvironmentFile=-/etc/kubernetes/scheduler ExecStart=/usr/bin/kube-scheduler \$KUBE_SCHEDULER_ARGS Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target EOF cat > /etc/kubernetes/scheduler << EOF KUBE_SCHEDULER_ARGS="--master=http://$IPADDR:8080 --logtostderr=false" EOF systemctl daemon-reload systemctl start kube-scheduler systemctl enable kube-scheduler ``` 至此master必须的服务已经安装完成,接下来的操作是在node节点安装`kubelet`和`kube-proxy`,如果你想把master节点也当做node的话,那就在master节点上也安装该服务。 - kubelet安装:kubelet服务依赖docker,请先安装好docker。 ``` cp kubernetes/server/bin/kubelet /usr/bin if [ ! -e /etc/kubernetes/config ]; then mkdir /etc/kubernetes/config fi if [ ! -e /var/lib/kubelet ]; then mkdir /var/lib/kubelet fi cat > /usr/lib/systemd/system/kubelet.service << EOF [Unit] Description=Kubernetes Kubelet Server Documentation=https://github.com/GoogleCloudPlatform/kubernetes After=docker.service Requires=docker.service [Service] WorkingDirectory=/var/lib/kubelet EnvironmentFile=-/etc/kubernetes/config EnvironmentFile=-/etc/kubernetes/kubelet ExecStart=/usr/bin/kubelet \ \$KUBELET_API_SERVER \ \$KUBELET_ADDRESS \ \$KUBELET_HOSTNAME \ \$KUBELET_POD_INFRA_CONTAINER \ \$KUBELET_ARGS Restart=on-failure [Install] WantedBy=multi-user.target EOF cat > /etc/kubernetes/kubelet << EOF KUBELET_ADDRESS="--address=0.0.0.0" KUBELET_HOSTNAME="--hostname-override=192.168.26.11" KUBELET_API_SERVER="--api-servers=http://192.168.26.11:8080" KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest" KUBELET_ARGS="" EOF systemctl daemon-reload systemctl start kubelet systemctl enable kubelet ``` - kube-proxy安装 ``` # cat install-kube-proxy.sh #!/bin/bash cp kubernetes/server/bin/kube-proxy /usr/bin if [ ! -e /etc/kubernetes/config ]; then mkdir /etc/kubernetes/config fi cat > /usr/lib/systemd/system/kube-proxy.service << EOF [Unit] Description=Kubernetes Kube-Proxy Server Documentation=https://github.com/GoogleCloudPlatform/kubernetes After=network.target [Service] EnvironmentFile=-/etc/kubernetes/config EnvironmentFile=-/etc/kubernetes/proxy ExecStart=/usr/bin/kube-proxy \$KUBE_PROXY_ARGS Restart=on-failure LimitNOFILE=65536 [Install] WantedBy=multi-user.target EOF cat > /etc/kubernetes/proxy << EOF KUBE_PROXY_ARGS="--master=http://192.168.26.11:8080 --logtostderr=false" EOF systemctl daemon-reload systemctl start kube-proxy systemctl enable kube-proxy ``` 在node节点上安装kubelet和kube-proxy的时候注意master节点的地址即可。 > 现在一个单节点的环境安装完成: ``` # kubectl get node NAME STATUS AGE 192.168.26.11 Ready 2s ``` 到此,一个kubernetes集群安装完成。在之后的练习中如果发现错误,可参考文章:https://steemit.com/kubernetes/@pmliang/pod |
| json metadata | {"tags":["kubernetes","docker","pod","shell"],"links":["https://steemit.com/kubernetes/@pmliang/pod"],"app":"steemit/0.1","format":"markdown"} |
| Transaction Info | Block #22995660/Trx 025a03e72786c265513e84667fc51000270ec7c5 |
View Raw JSON Data
{
"trx_id": "025a03e72786c265513e84667fc51000270ec7c5",
"block": 22995660,
"trx_in_block": 60,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-03T10:12:03",
"op": [
"comment",
{
"parent_author": "",
"parent_permlink": "kubernetes",
"author": "pmliang",
"permlink": "kubernetes",
"title": "kubernetes集群安装",
"body": "## `kubernetes`集群手工安装\n\n> 这里以一台`master`节点和一台`node`节点为例,其中我将`master`也用作`node`\n\n#### 一、master节点\n\n> 先关闭防火墙:\n```\n# systemctl stop firewalld\n# systemctl disable firewalld\n```\n\n- 安装`etcd`\n首先需要在GitHub上下载`etcd`的二进制文件包,这里以`etcd-v3.1.15-linux-amd64.tar.gz`为例\n\n我写了个简单的安装etcd的脚本,可以参考一下\n```\n# cat install-etcd.sh \n#!/bin/bash\ntar xzf etcd-v3.1.15-linux-amd64.tar.gz\ncp etcd-v3.1.15-linux-amd64/etcd etcd-v3.1.15-linux-amd64/etcdctl /usr/bin\nif [ ! -e /var/lib/etcd ]; then\nmkdir /var/lib/etcd\nfi\n\ncat > /usr/lib/systemd/system/etcd.service << EOF\n[Unit]\nDescription=Etcd Server\nAfter=network.target\n\n[Service]\nType=simple\nWorkingDirectory=/var/lib/etcd/\nEnvironmentFile=-/etc/etcd/etcd.conf\nExecStart=/usr/bin/etcd\nRestart=on-failure\n\n[Install]\nWantedBy=multi-user.target\nEOF\n\nif [ ! -e /etc/etcd ]; then\nmkdir /etc/etcd\nfi\ncat > /etc/etcd/etcd.conf << EOF\nETCD_DATA_DIR=\"/var/lib/etcd/default.etcd\"\nETCD_LISTEN_CLIENT_URLS=\"http://127.0.0.1:2379\"\nETCD_NAME=\"default\"\nETCD_ADVERTISE_CLIENT_URLS=\"http://127.0.0.1:2379\"\nEOF\n\nsystemctl daemon-reload\nsystemctl start etcd.service\nsystemctl enable etcd.service\netcdctl cluster-health\n```\n步骤为:1.将etcd和etcdctl二进制文件复制到`/usr/bin`目录下,或者其他`PATH`路径下,只需要在service文件中写正确即可。2.设置服务文件。3.编辑配置文件(详细的参数可以参考官网)\n\n至此,etcd服务安装完成。\n\n- `kube-apiserver`服务,首先在GitHub上下载kubernetes的二进制包,这里以1.3.0版本的`kubernetes.tar.gz`为例\n\n这里也通过脚本来说明:\n```\n# cat install-apiserver.sh\ntar xzf kubernetes.tar.gz\ntar xzf kubernetes/server/kubernetes-server-linux-amd64.tar.gz\ncp -a kubernetes/server/bin/kube-apiserver /usr/bin\n\ncat > /usr/lib/systemd/system/kube-apiserver.service << EOF\n[Unit]\nDescription=Kubernetes API Server\nDocumentation=https://github.com/GoogleCloudPlatform/kubernetes\nAfter=network.target\nAfter=etcd.service\n\n[Service]\nEnvironmentFile=-/etc/kubernetes/apiserver\nUser=kube\nExecStart=/usr/bin/kube-apiserver \\\n\t \\$KUBE_ETCD_SERVERS \\\n\t \\$KUBE_API_ADDRESS \\\n\t \\$KUBE_SERVICE_ADDRESSES \\\n\t \\$KUBE_ADMISSION_CONTROL \\\n\t \\$KUBE_API_ARGS\nRestart=on-failure\nType=notify\nLimitNOFILE=65536\n\n[Install]\nWantedBy=multi-user.target\nEOF\n\nif [ ! -e /etc/kubernetes ]; then\nmkdir /etc/kubernetes\nfi\n\ncat > /etc/kubernetes/apiserver << EOF\nKUBE_API_ADDRESS=\"--insecure-bind-address=0.0.0.0 --insecure-port=8080\"\nKUBE_ETCD_SERVERS=\"--etcd-servers=http://127.0.0.1:2379\"\nKUBE_SERVICE_ADDRESSES=\"--service-cluster-ip-range=10.254.0.0/16\"\nKUBE_ADMISSION_CONTROL=\"--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota\"\nKUBE_API_ARGS=\"--service-node-port-range=1-65535\"\nEOF\n\nsystemctl daemon-reload\nsystemctl start kube-apiserver\nsystemctl enable kube-apiserver\nsystemctl is-active kube-apiserver\n```\n\n启动参数:\n1). --insecure-bind-address:apiserver绑定主机的非安全ip地址,0.0.0.0表示绑定所有ip地址\n2). --insecure-port=8080:apiserver绑定的非安全端口,默认8080\n3). --etcd-servers:etcd服务的地址\n4). --service-cluster-ip-range:apiserver分配给集群中service的虚拟IP的网段,不能与物理机的IP地址段重合\n5). --admission-control:集群中准入控制,详细的见官网\n6). --service-node-port-range:端口映射物理机的范围,默认为30000-32767\n\n> 其他的启动参数详见官方网站\n\n- kube-controller-manager服务\n\n```\n# cat install-controller-manager.sh \n#!/bin/bash\nIPADDR=`ifconfig ens32 | grep '\\binet\\b' | awk '{print $2}'`\ncp kubernetes/server/bin/kube-controller-manager /usr/bin\ncat > /usr/lib/systemd/system/kube-controller-manager.service << EOF\n[Unit]\nDescription=Kubernetes Controller Manager\nDocumentation=https://github.com/GoogleCloudPlatform/kubernetes\nAfter=kube-apiserver.service\nRequires=kube-apiserver.service\n\n[Service]\nEnvironmentFile=-/etc/kubernetes/controller-manager\nExecStart=/usr/bin/kube-controller-manager \\$KUBE_CONTROLLER_MANAGER_ARGS\nRestart=on-failure\nLimitNOFILE=65536\n\n[Install]\nWantedBy=multi-user.target\nEOF\n\ncat > /etc/kubernetes/controller-manager << EOF\nKUBE_CONTROLLER_MANAGER_ARGS=\"--master=http://$IPADDR:8080\"\nEOF\n\nsystemctl daemon-reload\nsystemctl start kube-controller-manager\nsystemctl enable kube-controller-manager\n```\n\n- kube-scheduler服务\n```\n# cat install-scheduler.sh \n#!/bin/bash\nIPADDR=`ifconfig ens32 | grep '\\binet\\b' | awk '{print $2}'`\ncp kubernetes/server/bin/kubectl /usr/bin\ncp kubernetes/server/bin/kube-scheduler /usr/bin\n\ncat > /usr/lib/systemd/system/kube-scheduler.service << EOF\n[Unit]\nDescription=Kubernetes Scheduler Plugin\nDocumentation=https://github.com/GoogleCloudPlatform/kubernetes\nAfter=kube-apiserver.service\nRequires=kube-apiserver.service\n\n[Service]\nEnvironmentFile=-/etc/kubernetes/scheduler\nExecStart=/usr/bin/kube-scheduler \\$KUBE_SCHEDULER_ARGS\nRestart=on-failure\nLimitNOFILE=65536\n\n[Install]\nWantedBy=multi-user.target\nEOF\n\ncat > /etc/kubernetes/scheduler << EOF\nKUBE_SCHEDULER_ARGS=\"--master=http://$IPADDR:8080 --logtostderr=false\"\nEOF\n\nsystemctl daemon-reload\nsystemctl start kube-scheduler\nsystemctl enable kube-scheduler\n```\n\n至此master必须的服务已经安装完成,接下来的操作是在node节点安装`kubelet`和`kube-proxy`,如果你想把master节点也当做node的话,那就在master节点上也安装该服务。\n\n- kubelet安装:kubelet服务依赖docker,请先安装好docker。\n```\ncp kubernetes/server/bin/kubelet /usr/bin\nif [ ! -e /etc/kubernetes/config ]; then\nmkdir /etc/kubernetes/config\nfi\nif [ ! -e /var/lib/kubelet ]; then\nmkdir /var/lib/kubelet\nfi\n\ncat > /usr/lib/systemd/system/kubelet.service << EOF\n[Unit]\nDescription=Kubernetes Kubelet Server\nDocumentation=https://github.com/GoogleCloudPlatform/kubernetes\nAfter=docker.service\nRequires=docker.service\n\n[Service]\nWorkingDirectory=/var/lib/kubelet\nEnvironmentFile=-/etc/kubernetes/config\nEnvironmentFile=-/etc/kubernetes/kubelet\nExecStart=/usr/bin/kubelet \\\n\t \\$KUBELET_API_SERVER \\\n\t \\$KUBELET_ADDRESS \\\n\t \\$KUBELET_HOSTNAME \\\n\t \\$KUBELET_POD_INFRA_CONTAINER \\\n\t \\$KUBELET_ARGS\nRestart=on-failure\n\n[Install]\nWantedBy=multi-user.target\nEOF\n\ncat > /etc/kubernetes/kubelet << EOF\nKUBELET_ADDRESS=\"--address=0.0.0.0\"\nKUBELET_HOSTNAME=\"--hostname-override=192.168.26.11\"\nKUBELET_API_SERVER=\"--api-servers=http://192.168.26.11:8080\"\nKUBELET_POD_INFRA_CONTAINER=\"--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest\"\nKUBELET_ARGS=\"\"\nEOF\n\nsystemctl daemon-reload\nsystemctl start kubelet\nsystemctl enable kubelet\n```\n\n- kube-proxy安装\n```\n# cat install-kube-proxy.sh \n#!/bin/bash\ncp kubernetes/server/bin/kube-proxy /usr/bin\nif [ ! -e /etc/kubernetes/config ]; then\nmkdir /etc/kubernetes/config\nfi\n\ncat > /usr/lib/systemd/system/kube-proxy.service << EOF\n[Unit]\nDescription=Kubernetes Kube-Proxy Server\nDocumentation=https://github.com/GoogleCloudPlatform/kubernetes\nAfter=network.target\n\n[Service]\nEnvironmentFile=-/etc/kubernetes/config\nEnvironmentFile=-/etc/kubernetes/proxy\nExecStart=/usr/bin/kube-proxy \\$KUBE_PROXY_ARGS\nRestart=on-failure\nLimitNOFILE=65536\n\n[Install]\nWantedBy=multi-user.target\nEOF\n\ncat > /etc/kubernetes/proxy << EOF\nKUBE_PROXY_ARGS=\"--master=http://192.168.26.11:8080 --logtostderr=false\"\nEOF\n\nsystemctl daemon-reload\nsystemctl start kube-proxy\nsystemctl enable kube-proxy\n```\n\n在node节点上安装kubelet和kube-proxy的时候注意master节点的地址即可。\n\n> 现在一个单节点的环境安装完成:\n```\n# kubectl get node\nNAME STATUS AGE\n192.168.26.11 Ready 2s\n```\n\n到此,一个kubernetes集群安装完成。在之后的练习中如果发现错误,可参考文章:https://steemit.com/kubernetes/@pmliang/pod",
"json_metadata": "{\"tags\":[\"kubernetes\",\"docker\",\"pod\",\"shell\"],\"links\":[\"https://steemit.com/kubernetes/@pmliang/pod\"],\"app\":\"steemit/0.1\",\"format\":\"markdown\"}"
}
]
}pmliangpublished a new post: kubernetes-limitrange2018/06/02 08:45:30
pmliangpublished a new post: kubernetes-limitrange
2018/06/02 08:45:30
| parent author | |
| parent permlink | kubernetes |
| author | pmliang |
| permlink | kubernetes-limitrange |
| title | kubernetes中LimitRange的理解 |
| body | ## kubernetes中LimitRange的理解 今天学习了`LimitRange`,大概总结一下`LimitRange`的用法,`LimitRange`是在`pod`和`container`级别的资源限制,先看以下的例子: ``` apiVersion: v1 kind: LimitRange metadata: name: mylimits spec: limits: - max: cpu: "4" memory: 2Gi min: cpu: 200m memory: 6Mi maxLimitRequestRatio: cpu: 3 memory: 2 type: Pod - default: cpu: 300m memory: 200Mi defaultRequest: cpu: 200m memory: 100Mi max: cpu: "2" memory: 1Gi min: cpu: 100m memory: 3Mi maxLimitRequestRatio: cpu: 5 memory: 4 type: Container ``` - `pod`部分: 1. `max`表示`pod`中所有容器资源的`Limit`值和的上限,也就是整个`pod`资源的最大`Limit`,如果`pod`定义中的`Limit`值大于`LimitRange`中的值,则`pod`无法成功创建。 2. `min`表示`pod`中所有容器资源请求总和的下限,也就是所有容器`request`的资源总和不能小于`min`中的值,否则`pod`无法成功创建。 3. `maxLimitRequestRatio`表示`pod`中所有容器资源请求的`Limit`值和`request`值比值的上限,例如该`pod`中`cpu`的`Limit`值为3,而`request`为0.5,此时比值为6,创建`pod`将会失败。 - `container`部分 1. 在`container`的部分,`max`、`min`和`maxLimitRequestRatio`的含义和`pod`中的类似,只不过是针对单个的容器而言。下面说明几个情况: > 如果`container`设置了`max`, `pod`中的容器必须设置`limit`,如果未设置,则使用`defaultlimt`的值,如果`defaultlimit`也没有设置,则无法成功创建 > 如果设置了`container`的`min`,创建容器的时候必须设置`request`的值,如果没有设置,则使用`defaultrequest`,如果没有`defaultrequest`,则默认等于容器的`limit`值,如果`limit`也没有,启动就会报错 2. `defaultrequest`和`defaultlimit`则是默认值,注意:`pod`级别没有这两项设置 将`limitrange`应用于`namespace`就生效了,例如: ``` kubectl create -f limitrange-example.yaml --namespace=namespace-example |
| json metadata | {"tags":["kubernetes","docker","pod","shell"],"app":"steemit/0.1","format":"markdown"} |
| Transaction Info | Block #22965143/Trx 686604ffdf9126f3a003b9d907c8f4dbcc70d510 |
View Raw JSON Data
{
"trx_id": "686604ffdf9126f3a003b9d907c8f4dbcc70d510",
"block": 22965143,
"trx_in_block": 15,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-02T08:45:30",
"op": [
"comment",
{
"parent_author": "",
"parent_permlink": "kubernetes",
"author": "pmliang",
"permlink": "kubernetes-limitrange",
"title": "kubernetes中LimitRange的理解",
"body": "## kubernetes中LimitRange的理解\n今天学习了`LimitRange`,大概总结一下`LimitRange`的用法,`LimitRange`是在`pod`和`container`级别的资源限制,先看以下的例子:\n```\napiVersion: v1\nkind: LimitRange\nmetadata:\n name: mylimits\nspec:\n limits:\n - max:\n cpu: \"4\"\n memory: 2Gi\n min:\n cpu: 200m\n memory: 6Mi\n maxLimitRequestRatio:\n cpu: 3\n memory: 2\n type: Pod\n - default:\n cpu: 300m\n memory: 200Mi\n defaultRequest:\n cpu: 200m\n memory: 100Mi\n max:\n cpu: \"2\"\n memory: 1Gi\n min:\n cpu: 100m\n memory: 3Mi\n maxLimitRequestRatio:\n cpu: 5\n memory: 4\n type: Container\n```\n- `pod`部分:\n1. `max`表示`pod`中所有容器资源的`Limit`值和的上限,也就是整个`pod`资源的最大`Limit`,如果`pod`定义中的`Limit`值大于`LimitRange`中的值,则`pod`无法成功创建。\n2. `min`表示`pod`中所有容器资源请求总和的下限,也就是所有容器`request`的资源总和不能小于`min`中的值,否则`pod`无法成功创建。\n3. `maxLimitRequestRatio`表示`pod`中所有容器资源请求的`Limit`值和`request`值比值的上限,例如该`pod`中`cpu`的`Limit`值为3,而`request`为0.5,此时比值为6,创建`pod`将会失败。\n- `container`部分\n1. 在`container`的部分,`max`、`min`和`maxLimitRequestRatio`的含义和`pod`中的类似,只不过是针对单个的容器而言。下面说明几个情况:\n\n> 如果`container`设置了`max`, `pod`中的容器必须设置`limit`,如果未设置,则使用`defaultlimt`的值,如果`defaultlimit`也没有设置,则无法成功创建\n\n> 如果设置了`container`的`min`,创建容器的时候必须设置`request`的值,如果没有设置,则使用`defaultrequest`,如果没有`defaultrequest`,则默认等于容器的`limit`值,如果`limit`也没有,启动就会报错\n\n2. `defaultrequest`和`defaultlimit`则是默认值,注意:`pod`级别没有这两项设置\n\n\n将`limitrange`应用于`namespace`就生效了,例如:\n```\nkubectl create -f limitrange-example.yaml --namespace=namespace-example",
"json_metadata": "{\"tags\":[\"kubernetes\",\"docker\",\"pod\",\"shell\"],\"app\":\"steemit/0.1\",\"format\":\"markdown\"}"
}
]
}arcangereplied to @pmliang / re-flannel-20180602t055405000z2018/06/02 03:54:03
arcangereplied to @pmliang / re-flannel-20180602t055405000z
2018/06/02 03:54:03
| parent author | pmliang |
| parent permlink | flannel |
| author | arcange |
| permlink | re-flannel-20180602t055405000z |
| title | |
| body | **WARNING** - The message you received from @bdbalok is a **CONFIRMED SCAM!** **DO NOT FOLLOW** any instruction and **DO NOT CLICK** on any link in the comment! For more information, read this post: https://steemit.com/steemit/@arcange/phishing-site-reported-steemituper If you find my work to protect you and the community valuable, please consider to upvote this warning or to [vote for my witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=arcange&approve=1). |
| json metadata | {"image":["http://i.cubeupload.com/d1Dr28.png"]} |
| Transaction Info | Block #22959318/Trx 83456323ad4e7920ec24bef4e449d2042f3fb10c |
View Raw JSON Data
{
"trx_id": "83456323ad4e7920ec24bef4e449d2042f3fb10c",
"block": 22959318,
"trx_in_block": 29,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-06-02T03:54:03",
"op": [
"comment",
{
"parent_author": "pmliang",
"parent_permlink": "flannel",
"author": "arcange",
"permlink": "re-flannel-20180602t055405000z",
"title": "",
"body": "**WARNING** - The message you received from @bdbalok is a **CONFIRMED SCAM!**\n**DO NOT FOLLOW** any instruction and **DO NOT CLICK** on any link in the comment!\n\nFor more information, read this post: \nhttps://steemit.com/steemit/@arcange/phishing-site-reported-steemituper\n\nIf you find my work to protect you and the community valuable, please consider to upvote this warning or to [vote for my witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=arcange&approve=1).",
"json_metadata": "{\"image\":[\"http://i.cubeupload.com/d1Dr28.png\"]}"
}
]
}2018/05/29 07:48:00
2018/05/29 07:48:00
| voter | swagger |
| author | pmliang |
| permlink | flannel |
| weight | 3 (0.03%) |
| Transaction Info | Block #22848828/Trx 66168674eeb9ba912819f9cc5ec20311c94c662c |
View Raw JSON Data
{
"trx_id": "66168674eeb9ba912819f9cc5ec20311c94c662c",
"block": 22848828,
"trx_in_block": 8,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-29T07:48:00",
"op": [
"vote",
{
"voter": "swagger",
"author": "pmliang",
"permlink": "flannel",
"weight": 3
}
]
}2018/05/29 07:35:39
2018/05/29 07:35:39
| parent author | bdbalok |
| parent permlink | re-pmliang-flannel-20180529t072723835z |
| author | pmliang |
| permlink | re-bdbalok-re-pmliang-flannel-20180529t073518469z |
| title | |
| body | thanks |
| json metadata | {"tags":["kubernetes"],"app":"steemit/0.1"} |
| Transaction Info | Block #22848581/Trx 601cfaf962c7e3c765f4974c8b90168476b5956b |
View Raw JSON Data
{
"trx_id": "601cfaf962c7e3c765f4974c8b90168476b5956b",
"block": 22848581,
"trx_in_block": 8,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-29T07:35:39",
"op": [
"comment",
{
"parent_author": "bdbalok",
"parent_permlink": "re-pmliang-flannel-20180529t072723835z",
"author": "pmliang",
"permlink": "re-bdbalok-re-pmliang-flannel-20180529t073518469z",
"title": "",
"body": "thanks",
"json_metadata": "{\"tags\":[\"kubernetes\"],\"app\":\"steemit/0.1\"}"
}
]
}2018/05/29 07:32:33
2018/05/29 07:32:33
| voter | pmliang |
| author | pmliang |
| permlink | flannel |
| weight | 10000 (100.00%) |
| Transaction Info | Block #22848519/Trx 43410bad604870d77a8de060c00999a8fed38a5e |
View Raw JSON Data
{
"trx_id": "43410bad604870d77a8de060c00999a8fed38a5e",
"block": 22848519,
"trx_in_block": 43,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-29T07:32:33",
"op": [
"vote",
{
"voter": "pmliang",
"author": "pmliang",
"permlink": "flannel",
"weight": 10000
}
]
}bdbalokreplied to @pmliang / re-pmliang-flannel-20180529t072723835z2018/05/29 07:28:21
bdbalokreplied to @pmliang / re-pmliang-flannel-20180529t072723835z
2018/05/29 07:28:21
| parent author | pmliang |
| parent permlink | flannel |
| author | bdbalok |
| permlink | re-pmliang-flannel-20180529t072723835z |
| title | |
| body | Get your post resteemed over 90000+ followers and get upto $21+ SBD value Upvote. Your post will skyrocket and give you maximum exposer. ## << EXCLUSIVE OFFER >> WE are giving 20 UPVOTS WORTH 1 SBD AND 10 FOLLOWERS. [Click HERE FOR GET THE OFFER](https://t.co/QpANywe3HS) |
| json metadata | {"tags":["kubernetes"],"links":["https://t.co/QpANywe3HS"],"app":"steemit/0.1"} |
| Transaction Info | Block #22848435/Trx f6390973afee7b6795d403d5ffef59b71b7e8bec |
View Raw JSON Data
{
"trx_id": "f6390973afee7b6795d403d5ffef59b71b7e8bec",
"block": 22848435,
"trx_in_block": 6,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-29T07:28:21",
"op": [
"comment",
{
"parent_author": "pmliang",
"parent_permlink": "flannel",
"author": "bdbalok",
"permlink": "re-pmliang-flannel-20180529t072723835z",
"title": "",
"body": "Get your post resteemed over 90000+ followers and get upto $21+ SBD value Upvote. \nYour post will skyrocket and give you maximum exposer. \n## << EXCLUSIVE OFFER >> \nWE are giving 20 UPVOTS WORTH 1 SBD AND 10 FOLLOWERS.\n\n[Click HERE FOR GET THE OFFER](https://t.co/QpANywe3HS)",
"json_metadata": "{\"tags\":[\"kubernetes\"],\"links\":[\"https://t.co/QpANywe3HS\"],\"app\":\"steemit/0.1\"}"
}
]
}2018/05/29 07:27:57
2018/05/29 07:27:57
| parent author | |
| parent permlink | kubernetes |
| author | pmliang |
| permlink | flannel |
| title | flannel网络的安装 |
| body | ## `flannel`网络的安装配置 今天在做`kubernetes`集群中`flannel`网络的配置时遇到的问题,记录下来 #### 一、安装`etcd`: 如果搭建好了`kubernetes`集群,应该是已经安装配置好了`etcd`,这里简单说一下: 为什么需要`etcd`,是因为`flannel`使用`etcd`作为数据库,保存集群中分配的网络信息,从而保证了集群中的pod网络是同一个网段,并且不会重复。 使用`yum install etcd`来安装,或者使用源码进行安装,详见[这里](https:/github.com/coreos/etcd/releases/)。 安装好了之后修改一下`etcd`的配置文件`/etc/etcd/etcd.conf` 修改以下两个参数: ``` ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379" ``` 我这里修改为了监听所有网卡,你可以按需要进行修改,然后重启`etcd`服务: ``` systemctl restart etcd ``` #### 二、安装flannel 同样我这里使用`yum install flannel -y`的方式进行安装,你也可以去`github`下载对应的包进行安装,解压之后将二进制文件`flannel`和`nk-docker-opts.sh`拷贝到`/usr/bin`目录下完成安装。 #### 三、配置flannel 如果是手动拷贝二进制文件安装,可以参考`yum`安装之后的配置文件进行配置,这里只修改`flannel`的配置文件,编辑配置文件`/etc/sysconfig/flannel`,按照以下参数配置: ``` FLANNEL_ETCD_ENDPOINTS="http://192.168.26.250:2379" FLANNEL_ETCD_PREFIX="/coreos.com/network" ``` 设置为你的`etcd`的地址即可,在启动`flannel`之前,需要添加一条网络配置记录,用于`flannel`分配给每个`docker0`的网络: ``` etcdctl set /coreos.com/network/config '{ "Network": "10.1.0.0/16" }' ``` > 由于启动`flannel`时将会覆盖`docker0`的网络,因此在启动flannel之前需要将docker服务停掉。 #### 四、启动flannel ``` systemctl restart flanneld ``` 接下来就是重启docker服务了,如果是手动安装flannel,可能需要配置docker0网络的地址,使用以下命令: ``` mk-docker-opts.sh -i source /run/flannel/subnet.env ifconfig docker0 ${FLANNEL_SUBNET} ``` #### 五、重启docker ``` systemctl restart docker ``` 查看网络配置: ``` # ip a 4: flannel0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1472 qdisc pfifo_fast state UNKNOWN qlen 500 link/none inet 10.1.13.0/16 scope global flannel0 valid_lft forever preferred_lft forever 5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN link/ether 02:42:da:9c:59:22 brd ff:ff:ff:ff:ff:ff inet 10.1.13.1/24 scope global docker0 valid_lft forever preferred_lft forever ``` 可以发现配置的网络已经生效,我这里是flannel自动分配的网段 > 我本人在重启docker的时候发现了如下报错: ``` -- Unit docker.service has begun starting up. 5月 29 13:56:44 master.kube.com dockerd-current[13290]: time="2018-05-29T13:56:44.717023320+08:00" level=warning msg="could not change group /var/run/docker.sock to do 5月 29 13:56:44 master.kube.com dockerd-current[13290]: time="2018-05-29T13:56:44.720843794+08:00" level=info msg="libcontainerd: new containerd process, pid: 13295" 5月 29 13:56:46 master.kube.com dockerd-current[13290]: Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel. Either boot into 5月 29 13:56:46 master.kube.com systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE 5月 29 13:56:46 master.kube.com systemd[1]: Failed to start Docker Application Container Engine. -- Subject: Unit docker.service has failed ``` 原因是因为在当前的内核上`selinux`不支持`overlay`的网络,解决办法是升级内核或者修改docker的配置文件的`/etc/sysconfig/docker`的参数为`--selinux-enabled=false` > 按照相同的方式配置另一台机器 #### 六、验证网络 可以通过ping另一台机器的docker0来验证网络的连通性 使用以下命令查看每台机器上的flannel0和docker0的网络信息和对应物理机的地址: ``` [root@master ~]# etcdctl ls /coreos.com/network/subnets /coreos.com/network/subnets/10.1.13.0-24 /coreos.com/network/subnets/10.1.50.0-24 [root@master ~]# etcdctl get /coreos.com/network/subnets/10.1.13.0-24 {"PublicIP":"192.168.26.250"} [root@master ~]# etcdctl get /coreos.com/network/subnets/10.1.50.0-24 {"PublicIP":"192.168.26.240"} ``` 至此,flannel网络配置完成。 |
| json metadata | {"tags":["kubernetes","docker","pod","flannel"],"links":["https:/github.com/coreos/etcd/releases/"],"app":"steemit/0.1","format":"markdown"} |
| Transaction Info | Block #22848427/Trx 6293961160c2fac6f85208ec5f9f65b1954f1d89 |
View Raw JSON Data
{
"trx_id": "6293961160c2fac6f85208ec5f9f65b1954f1d89",
"block": 22848427,
"trx_in_block": 1,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-29T07:27:57",
"op": [
"comment",
{
"parent_author": "",
"parent_permlink": "kubernetes",
"author": "pmliang",
"permlink": "flannel",
"title": "flannel网络的安装",
"body": "## `flannel`网络的安装配置\n\n今天在做`kubernetes`集群中`flannel`网络的配置时遇到的问题,记录下来\n\n#### 一、安装`etcd`:\n如果搭建好了`kubernetes`集群,应该是已经安装配置好了`etcd`,这里简单说一下:\n为什么需要`etcd`,是因为`flannel`使用`etcd`作为数据库,保存集群中分配的网络信息,从而保证了集群中的pod网络是同一个网段,并且不会重复。\n使用`yum install etcd`来安装,或者使用源码进行安装,详见[这里](https:/github.com/coreos/etcd/releases/)。\n安装好了之后修改一下`etcd`的配置文件`/etc/etcd/etcd.conf`\n修改以下两个参数:\n```\nETCD_LISTEN_CLIENT_URLS=\"http://0.0.0.0:2379\"\nETCD_ADVERTISE_CLIENT_URLS=\"http://0.0.0.0:2379\"\n```\n我这里修改为了监听所有网卡,你可以按需要进行修改,然后重启`etcd`服务:\n```\nsystemctl restart etcd\n```\n\n#### 二、安装flannel\n同样我这里使用`yum install flannel -y`的方式进行安装,你也可以去`github`下载对应的包进行安装,解压之后将二进制文件`flannel`和`nk-docker-opts.sh`拷贝到`/usr/bin`目录下完成安装。\n\n#### 三、配置flannel\n如果是手动拷贝二进制文件安装,可以参考`yum`安装之后的配置文件进行配置,这里只修改`flannel`的配置文件,编辑配置文件`/etc/sysconfig/flannel`,按照以下参数配置:\n```\nFLANNEL_ETCD_ENDPOINTS=\"http://192.168.26.250:2379\"\nFLANNEL_ETCD_PREFIX=\"/coreos.com/network\"\n```\n设置为你的`etcd`的地址即可,在启动`flannel`之前,需要添加一条网络配置记录,用于`flannel`分配给每个`docker0`的网络:\n```\netcdctl set /coreos.com/network/config '{ \"Network\": \"10.1.0.0/16\" }'\n```\n\n> 由于启动`flannel`时将会覆盖`docker0`的网络,因此在启动flannel之前需要将docker服务停掉。\n\n#### 四、启动flannel\n```\nsystemctl restart flanneld\n```\n接下来就是重启docker服务了,如果是手动安装flannel,可能需要配置docker0网络的地址,使用以下命令:\n```\nmk-docker-opts.sh -i\nsource /run/flannel/subnet.env\nifconfig docker0 ${FLANNEL_SUBNET}\n```\n\n#### 五、重启docker\n```\nsystemctl restart docker\n```\n查看网络配置:\n```\n# ip a\n4: flannel0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1472 qdisc pfifo_fast state UNKNOWN qlen 500\n link/none \n inet 10.1.13.0/16 scope global flannel0\n valid_lft forever preferred_lft forever\n5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN \n link/ether 02:42:da:9c:59:22 brd ff:ff:ff:ff:ff:ff\n inet 10.1.13.1/24 scope global docker0\n valid_lft forever preferred_lft forever\n```\n可以发现配置的网络已经生效,我这里是flannel自动分配的网段\n\n> 我本人在重启docker的时候发现了如下报错:\n\n```\n-- Unit docker.service has begun starting up.\n5月 29 13:56:44 master.kube.com dockerd-current[13290]: time=\"2018-05-29T13:56:44.717023320+08:00\" level=warning msg=\"could not change group /var/run/docker.sock to do\n5月 29 13:56:44 master.kube.com dockerd-current[13290]: time=\"2018-05-29T13:56:44.720843794+08:00\" level=info msg=\"libcontainerd: new containerd process, pid: 13295\"\n5月 29 13:56:46 master.kube.com dockerd-current[13290]: Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel. Either boot into\n5月 29 13:56:46 master.kube.com systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE\n5月 29 13:56:46 master.kube.com systemd[1]: Failed to start Docker Application Container Engine.\n-- Subject: Unit docker.service has failed\n```\n原因是因为在当前的内核上`selinux`不支持`overlay`的网络,解决办法是升级内核或者修改docker的配置文件的`/etc/sysconfig/docker`的参数为`--selinux-enabled=false`\n\n> 按照相同的方式配置另一台机器\n\n#### 六、验证网络\n可以通过ping另一台机器的docker0来验证网络的连通性\n\n使用以下命令查看每台机器上的flannel0和docker0的网络信息和对应物理机的地址:\n```\n[root@master ~]# etcdctl ls /coreos.com/network/subnets\n/coreos.com/network/subnets/10.1.13.0-24\n/coreos.com/network/subnets/10.1.50.0-24\n[root@master ~]# etcdctl get /coreos.com/network/subnets/10.1.13.0-24\n{\"PublicIP\":\"192.168.26.250\"}\n[root@master ~]# etcdctl get /coreos.com/network/subnets/10.1.50.0-24\n{\"PublicIP\":\"192.168.26.240\"}\n```\n\n\n至此,flannel网络配置完成。",
"json_metadata": "{\"tags\":[\"kubernetes\",\"docker\",\"pod\",\"flannel\"],\"links\":[\"https:/github.com/coreos/etcd/releases/\"],\"app\":\"steemit/0.1\",\"format\":\"markdown\"}"
}
]
}2018/05/29 04:01:51
2018/05/29 04:01:51
| voter | pmliang |
| author | pmliang |
| permlink | pod |
| weight | 10000 (100.00%) |
| Transaction Info | Block #22844306/Trx ec9708c703ba9faf862563376eabbc6a3d7253d7 |
View Raw JSON Data
{
"trx_id": "ec9708c703ba9faf862563376eabbc6a3d7253d7",
"block": 22844306,
"trx_in_block": 51,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-29T04:01:51",
"op": [
"vote",
{
"voter": "pmliang",
"author": "pmliang",
"permlink": "pod",
"weight": 10000
}
]
}2018/05/29 00:07:18
2018/05/29 00:07:18
| parent author | |
| parent permlink | kubernetes |
| author | pmliang |
| permlink | pod |
| title | pod启动失败解决办法 |
| body | 在《kubernetes权威指南》入门的一个例子中,发现pod一直处于`ContainerCreating`的状态,用`kubectl describe pod mysql`的时候发现如下报错: ``` Events: FirstSeen LastSeen Count From SubObjectPath Type Reason Message --------- -------- ----- ---- ------------- -------- ------ ------- 1h 24m 17 {kubelet 127.0.0.1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request. details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)" 1h 19m 291 {kubelet 127.0.0.1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ImagePullBackOff: "Back-off pulling image \"registry.access.redhat.com/rhel7/pod-infrastructure:latest\"" 15m 15m 1 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy. 15m 15m 1 {kubelet 127.0.0.1} spec.containers{mysql} Normal Pulling pulling image "mysql" 7m 7m 1 {kubelet 127.0.0.1} Warning MissingClusterDNS kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy. 7m 7m 1 {kubelet 127.0.0.1} spec.containers{mysql} Normal Pulling pulling image "mysql" ``` 问题是比较明显的,就是没有`/etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt`文件,用`ls -l`查看之后发现是一个软链接,链接到`/etc/rhsm/ca/redhat-uep.pem`,但是这个文件不存在,使用`yum search *rhsm*`命令: - 安装`python-rhsm-certificates`包: ``` # yum install python-rhsm-certificates -y ``` 这里又出现问题了: ``` python-rhsm-certificates <= 1.20.3-1 被 (已安裝) subscription-manager-rhsm-certificates-1.20.11-1.el7.centos.x86_64 取代 ``` 那么怎么办呢,我们直接卸载掉`subscription-manager-rhsm-certificates`包,使用`yum remove subscription-manager-rhsm-certificates -y`命令,然后下载`python-rhsm-certificates`包: ``` # wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm ``` 然后手动安装该rpm包: ``` # rpm -ivh python-rhsm-certificates ``` 这时发现`/etc/rhsm/ca/redhat-uep.pem`文件已存在。 - 使用`docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest`命令下载镜像,但是可能会很慢,可以到https://dashboard.daocloud.io网站上注册账号,然后点击加速器,然后复制代码执行,之后重启docker就会进行加速,如果重启docker服务的时候无法启动,使用`systemctl status docker`: ``` # systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since 一 2018-05-28 22:13:37 CST; 13s ago Docs: http://docs.docker.com Process: 79849 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --init-path=/usr/libexec/docker/docker-init-current --seccomp-profile=/etc/docker/seccomp.json $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=1/FAILURE) Main PID: 79849 (code=exited, status=1/FAILURE) 5月 28 22:13:37 kube.example.com systemd[1]: Starting Docker Application Container Engine... 5月 28 22:13:37 kube.example.com dockerd-current[79849]: unable to configure the Docker daemon with file /etc/docker/daemon.json: invalid character '}' loo...y string 5月 28 22:13:37 kube.example.com systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE 5月 28 22:13:37 kube.example.com systemd[1]: Failed to start Docker Application Container Engine. 5月 28 22:13:37 kube.example.com systemd[1]: Unit docker.service entered failed state. 5月 28 22:13:37 kube.example.com systemd[1]: docker.service failed. Hint: Some lines were ellipsized, use -l to show in full ``` 这时将`/etc/docker/seccomp.json`删除,再次重启即可 - 这时将之前创建的rc、svc和pod全部删除重新创建,过一会就会发现pod启动成功 > 原因猜想:根据报错信息,pod启动需要`registry.access.redhat.com/rhel7/pod-infrastructure:latest`镜像,需要去红帽仓库里下载,但是没有证书,安装证书之后就可以了 |
| json metadata | {"tags":["kubernetes","docker","pod","shell"],"links":["https://dashboard.daocloud.io"],"app":"steemit/0.1","format":"markdown"} |
| Transaction Info | Block #22839615/Trx ca00783dfb24a2b3e9ddf060e74ba53b59faf9b8 |
View Raw JSON Data
{
"trx_id": "ca00783dfb24a2b3e9ddf060e74ba53b59faf9b8",
"block": 22839615,
"trx_in_block": 13,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-29T00:07:18",
"op": [
"comment",
{
"parent_author": "",
"parent_permlink": "kubernetes",
"author": "pmliang",
"permlink": "pod",
"title": "pod启动失败解决办法",
"body": "在《kubernetes权威指南》入门的一个例子中,发现pod一直处于`ContainerCreating`的状态,用`kubectl describe pod mysql`的时候发现如下报错:\n```\nEvents:\n FirstSeen\tLastSeen\tCount\tFrom\t\t\tSubObjectPath\tType\t\tReason\t\tMessage\n ---------\t--------\t-----\t----\t\t\t-------------\t--------\t------\t\t-------\n 1h\t\t24m\t\t17\t{kubelet 127.0.0.1}\t\t\tWarning\t\tFailedSync\tError syncing pod, skipping: failed to \"StartContainer\" for \"POD\" with ErrImagePull: \"image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request. details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)\"\n\n 1h\t19m\t291\t{kubelet 127.0.0.1}\t\tWarning\tFailedSync\tError syncing pod, skipping: failed to \"StartContainer\" for \"POD\" with ImagePullBackOff: \"Back-off pulling image \\\"registry.access.redhat.com/rhel7/pod-infrastructure:latest\\\"\"\n\n 15m\t15m\t1\t{kubelet 127.0.0.1}\t\t\t\tWarning\tMissingClusterDNS\tkubelet does not have ClusterDNS IP configured and cannot create Pod using \"ClusterFirst\" policy. Falling back to DNSDefault policy.\n 15m\t15m\t1\t{kubelet 127.0.0.1}\tspec.containers{mysql}\tNormal\tPulling\t\t\tpulling image \"mysql\"\n 7m\t7m\t1\t{kubelet 127.0.0.1}\t\t\t\tWarning\tMissingClusterDNS\tkubelet does not have ClusterDNS IP configured and cannot create Pod using \"ClusterFirst\" policy. Falling back to DNSDefault policy.\n 7m\t7m\t1\t{kubelet 127.0.0.1}\tspec.containers{mysql}\tNormal\tPulling\t\t\tpulling image \"mysql\"\n```\n问题是比较明显的,就是没有`/etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt`文件,用`ls -l`查看之后发现是一个软链接,链接到`/etc/rhsm/ca/redhat-uep.pem`,但是这个文件不存在,使用`yum search *rhsm*`命令:\n- 安装`python-rhsm-certificates`包:\n```\n# yum install python-rhsm-certificates -y\n```\n这里又出现问题了:\n```\npython-rhsm-certificates <= 1.20.3-1 被 (已安裝) subscription-manager-rhsm-certificates-1.20.11-1.el7.centos.x86_64 取代\n```\n那么怎么办呢,我们直接卸载掉`subscription-manager-rhsm-certificates`包,使用`yum remove subscription-manager-rhsm-certificates -y`命令,然后下载`python-rhsm-certificates`包:\n```\n# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm\n```\n然后手动安装该rpm包:\n```\n# rpm -ivh python-rhsm-certificates\n```\n这时发现`/etc/rhsm/ca/redhat-uep.pem`文件已存在。\n- 使用`docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest`命令下载镜像,但是可能会很慢,可以到https://dashboard.daocloud.io网站上注册账号,然后点击加速器,然后复制代码执行,之后重启docker就会进行加速,如果重启docker服务的时候无法启动,使用`systemctl status docker`:\n```\n# systemctl status docker\n● docker.service - Docker Application Container Engine\n Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)\n Active: failed (Result: exit-code) since 一 2018-05-28 22:13:37 CST; 13s ago\n Docs: http://docs.docker.com\n Process: 79849 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --init-path=/usr/libexec/docker/docker-init-current --seccomp-profile=/etc/docker/seccomp.json $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=1/FAILURE)\n Main PID: 79849 (code=exited, status=1/FAILURE)\n\n5月 28 22:13:37 kube.example.com systemd[1]: Starting Docker Application Container Engine...\n5月 28 22:13:37 kube.example.com dockerd-current[79849]: unable to configure the Docker daemon with file /etc/docker/daemon.json: invalid character '}' loo...y string\n5月 28 22:13:37 kube.example.com systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE\n5月 28 22:13:37 kube.example.com systemd[1]: Failed to start Docker Application Container Engine.\n5月 28 22:13:37 kube.example.com systemd[1]: Unit docker.service entered failed state.\n5月 28 22:13:37 kube.example.com systemd[1]: docker.service failed.\nHint: Some lines were ellipsized, use -l to show in full\n```\n这时将`/etc/docker/seccomp.json`删除,再次重启即可\n\n- 这时将之前创建的rc、svc和pod全部删除重新创建,过一会就会发现pod启动成功\n\n\n\n> 原因猜想:根据报错信息,pod启动需要`registry.access.redhat.com/rhel7/pod-infrastructure:latest`镜像,需要去红帽仓库里下载,但是没有证书,安装证书之后就可以了",
"json_metadata": "{\"tags\":[\"kubernetes\",\"docker\",\"pod\",\"shell\"],\"links\":[\"https://dashboard.daocloud.io\"],\"app\":\"steemit/0.1\",\"format\":\"markdown\"}"
}
]
}2018/05/27 05:13:27
2018/05/27 05:13:27
| voter | pmliang |
| author | pmliang |
| permlink | linux |
| weight | 10000 (100.00%) |
| Transaction Info | Block #22788146/Trx 20dca9b6dbcc9e5d73427da7ca1df48a709aa9af |
View Raw JSON Data
{
"trx_id": "20dca9b6dbcc9e5d73427da7ca1df48a709aa9af",
"block": 22788146,
"trx_in_block": 29,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-27T05:13:27",
"op": [
"vote",
{
"voter": "pmliang",
"author": "pmliang",
"permlink": "linux",
"weight": 10000
}
]
}2018/05/27 05:08:33
2018/05/27 05:08:33
| parent author | |
| parent permlink | linux |
| author | pmliang |
| permlink | linux |
| title | Linux特殊权限介绍 |
| body | ## `Linux`特殊权限介绍 一、`s`权限: - 当`s`权限位于可执行命令所有者的位置时,其他用户执行时将具有所有者的权限 ``` # ll $(which passwd) -rwsr-xr-x. 1 root root 27832 1月 30 2014 /usr/bin/passwd # ll /etc/shadow ----------. 1 root root 1447 5月 17 20:58 /etc/shadow ``` 可以看到,用户没有任何对`/etc/shadow`文件的权限,但是其他用户可以修改密码,为什么呢?就是因为`passwd`命令所有者的位置上有`s`权限 > 看一个例子你就明白了: ``` # touch /opt/test.txt # ll /opt/test.txt -rw-r--r--. 1 root root 0 5月 27 12:26 /opt/test.txt ``` 用root用户在`/opt`下创建一个`test.txt`文件,此时除了root用户其他用户没有写权限。 接下来我们给`vim`命令的所有者位置增加一个`s`权限: ``` # chmod u+s $(which vim) # ll $(which vim) -rwsr-xr-x. 1 root root 2289600 1月 30 2014 /usr/bin/vim ``` 此时用其他用户可以使用`vim`往`/opt/test.txt`写内容。 了解了这个例子,也就能理解`s`位于可执行命令所有者位置时的特殊权限了。 - `s`位于目录的所属组位置时,不管哪个用户在该目录下创建文件或目录,都会继承该目录的所属组: ``` # mkdir /opt/test # chgrp tom /opt/test # chmod g+s /opt/test # ls -ld /opt/test drwxr-srwx. 2 root tom 6 5月 27 12:37 /opt/test ``` 然后分别用`root`和`bob`用户在该目录下创建文件: ``` # touch /opt/test/test_root # ll /opt/test/test_root -rw-r--r--. 1 root tom 0 5月 27 12:40 /opt/test/test_root $ touch /opt/test/test_bob $ ll /opt/test/test_bob -rw-rw-r--. 1 bob tom 0 5月 27 12:42 /opt/test/test_bob # mkdir /opt/test/root1 # ls -ld /opt/test/root1 drwxr-sr-x. 2 root tom 6 5月 27 12:42 /opt/test/root1 ``` 看懂了这个例子,就能理解`s`位于所属组位置的权限问题了 ## `t`权限 - `t`位于目录的`other`的位置时,这时除了所有者和`root`之外,其他的用户即使有权限,也无法删除该目录下的文件: ``` [root@www ~]# mkdir /opt/test2 [root@www ~]# chmod 777 /opt/test2 [root@www ~]# touch /opt/test2/test [root@www ~]# chmod 777 /opt/test2/test [tom@www ~]$ rm -rf /opt/test2/test [root@www ~]# chmod o+t /opt/test2 [root@www ~]# touch /opt/test2/test [root@www ~]# chmod 777 /opt/test2/test [tom@www ~]$ rm -rf /opt/test2/test rm: 无法删除"/opt/test2/test": 不允许的操作 ``` 通过这个例子,就能理解`t`位于目录`other`位置的权限了。 > `chmod 7777 file` 后面三个权限是原本的权限,前面的7代表的是: ``` u+s --------> 4 g+s --------> 2 o+t --------> 1 ``` ## 三、特殊权限 使用`lsattr`命令查看特殊权限. - 特殊权限`a`,意味着只能增加不能减小,对目录和文件都生效: ``` [root@www ~]# touch /tmp/test [root@www ~]# lsattr /tmp/test ---------------- /tmp/test [root@www ~]# echo xxxxxxxx > /tmp/test [root@www ~]# chattr +a /tmp/test [root@www ~]# lsattr /tmp/test -----a---------- /tmp/test [root@www ~]# echo yyyyyyyyyyy > /tmp/test -bash: /tmp/test: 不允许的操作 [root@www ~]# echo yyyyyyyyyyy >> /tmp/test ``` > 注:>表示先清空,再写入 - 特殊权限`i`,文件和目录的内容不能发生改变: ``` [root@www ~]# chattr -a /tmp/test [root@www ~]# chattr +i /tmp/test [root@www ~]# cat /tmp/test xxxxxxxx yyyyyyyyyyy [root@www ~]# lsattr /tmp/test ----i----------- /tmp/test [root@www ~]# echo hahahhahah >> /tmp/test -bash: /tmp/test: 权限不够 ``` > 以上就是今天要讲的特殊权限 |
| json metadata | {"tags":["linux","shell"],"app":"steemit/0.1","format":"markdown"} |
| Transaction Info | Block #22788048/Trx 4a01c9c764779e90ef53574e42a978dd75c0af30 |
View Raw JSON Data
{
"trx_id": "4a01c9c764779e90ef53574e42a978dd75c0af30",
"block": 22788048,
"trx_in_block": 30,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-27T05:08:33",
"op": [
"comment",
{
"parent_author": "",
"parent_permlink": "linux",
"author": "pmliang",
"permlink": "linux",
"title": "Linux特殊权限介绍",
"body": "## `Linux`特殊权限介绍\n一、`s`权限:\n- 当`s`权限位于可执行命令所有者的位置时,其他用户执行时将具有所有者的权限\n```\n# ll $(which passwd)\n-rwsr-xr-x. 1 root root 27832 1月 30 2014 /usr/bin/passwd\n# ll /etc/shadow\n----------. 1 root root 1447 5月 17 20:58 /etc/shadow\n```\n可以看到,用户没有任何对`/etc/shadow`文件的权限,但是其他用户可以修改密码,为什么呢?就是因为`passwd`命令所有者的位置上有`s`权限\n\n> 看一个例子你就明白了:\n\n```\n# touch /opt/test.txt\n# ll /opt/test.txt\n-rw-r--r--. 1 root root 0 5月 27 12:26 /opt/test.txt\n```\n用root用户在`/opt`下创建一个`test.txt`文件,此时除了root用户其他用户没有写权限。\n接下来我们给`vim`命令的所有者位置增加一个`s`权限:\n```\n# chmod u+s $(which vim)\n# ll $(which vim)\n-rwsr-xr-x. 1 root root 2289600 1月 30 2014 /usr/bin/vim\n```\n此时用其他用户可以使用`vim`往`/opt/test.txt`写内容。\n\n了解了这个例子,也就能理解`s`位于可执行命令所有者位置时的特殊权限了。\n\n- `s`位于目录的所属组位置时,不管哪个用户在该目录下创建文件或目录,都会继承该目录的所属组:\n```\n# mkdir /opt/test\n# chgrp tom /opt/test\n# chmod g+s /opt/test\n# ls -ld /opt/test\ndrwxr-srwx. 2 root tom 6 5月 27 12:37 /opt/test\n```\n然后分别用`root`和`bob`用户在该目录下创建文件:\n```\n# touch /opt/test/test_root\n# ll /opt/test/test_root\n-rw-r--r--. 1 root tom 0 5月 27 12:40 /opt/test/test_root\n$ touch /opt/test/test_bob\n$ ll /opt/test/test_bob\n-rw-rw-r--. 1 bob tom 0 5月 27 12:42 /opt/test/test_bob\n# mkdir /opt/test/root1\n# ls -ld /opt/test/root1\ndrwxr-sr-x. 2 root tom 6 5月 27 12:42 /opt/test/root1\n```\n看懂了这个例子,就能理解`s`位于所属组位置的权限问题了\n\n## `t`权限\n\n- `t`位于目录的`other`的位置时,这时除了所有者和`root`之外,其他的用户即使有权限,也无法删除该目录下的文件:\n```\n[root@www ~]# mkdir /opt/test2\n[root@www ~]# chmod 777 /opt/test2\n[root@www ~]# touch /opt/test2/test\n[root@www ~]# chmod 777 /opt/test2/test\n[tom@www ~]$ rm -rf /opt/test2/test\n\n[root@www ~]# chmod o+t /opt/test2\n[root@www ~]# touch /opt/test2/test\n[root@www ~]# chmod 777 /opt/test2/test\n[tom@www ~]$ rm -rf /opt/test2/test \nrm: 无法删除\"/opt/test2/test\": 不允许的操作\n```\n通过这个例子,就能理解`t`位于目录`other`位置的权限了。\n\n> `chmod 7777 file`\n后面三个权限是原本的权限,前面的7代表的是:\n```\nu+s --------> 4\ng+s --------> 2\no+t --------> 1\n```\n\n## 三、特殊权限\n\n使用`lsattr`命令查看特殊权限.\n\n- 特殊权限`a`,意味着只能增加不能减小,对目录和文件都生效:\n```\n[root@www ~]# touch /tmp/test\n[root@www ~]# lsattr /tmp/test\n---------------- /tmp/test\n[root@www ~]# echo xxxxxxxx > /tmp/test\n[root@www ~]# chattr +a /tmp/test\n[root@www ~]# lsattr /tmp/test\n-----a---------- /tmp/test\n[root@www ~]# echo yyyyyyyyyyy > /tmp/test\n-bash: /tmp/test: 不允许的操作\n[root@www ~]# echo yyyyyyyyyyy >> /tmp/test\n```\n> 注:>表示先清空,再写入\n\n- 特殊权限`i`,文件和目录的内容不能发生改变:\n```\n[root@www ~]# chattr -a /tmp/test\n[root@www ~]# chattr +i /tmp/test\n[root@www ~]# cat /tmp/test\nxxxxxxxx\nyyyyyyyyyyy\n[root@www ~]# lsattr /tmp/test\n----i----------- /tmp/test\n[root@www ~]# echo hahahhahah >> /tmp/test\n-bash: /tmp/test: 权限不够\n```\n\n> 以上就是今天要讲的特殊权限",
"json_metadata": "{\"tags\":[\"linux\",\"shell\"],\"app\":\"steemit/0.1\",\"format\":\"markdown\"}"
}
]
}pmliangupvoted (100.00%) @pmliang / sqlalchemy2018/05/25 13:19:42
pmliangupvoted (100.00%) @pmliang / sqlalchemy
2018/05/25 13:19:42
| voter | pmliang |
| author | pmliang |
| permlink | sqlalchemy |
| weight | 10000 (100.00%) |
| Transaction Info | Block #22740280/Trx ecf89721e60a5e4b71355a1581f2caa77d487264 |
View Raw JSON Data
{
"trx_id": "ecf89721e60a5e4b71355a1581f2caa77d487264",
"block": 22740280,
"trx_in_block": 47,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-25T13:19:42",
"op": [
"vote",
{
"voter": "pmliang",
"author": "pmliang",
"permlink": "sqlalchemy",
"weight": 10000
}
]
}pmliangpublished a new post: sqlalchemy2018/05/25 06:35:12
pmliangpublished a new post: sqlalchemy
2018/05/25 06:35:12
| parent author | |
| parent permlink | python |
| author | pmliang |
| permlink | sqlalchemy |
| title | sqlalchemy用法 |
| body | ``` from sqlalchemy import Column, String, create_engine from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base ``` - 连接 ``` Base = declarative_base() engine = create_engine('postgresql://midwaredata:[email protected]:5433/qhinfo', echo=True) ``` echo为True的时候,会显示每一条执行的sql语句 >`create_engine`用来初始化数据库连接,`sqlalchemy`用一个字符串表示连接信息: '数据库类型+数据库驱动://用户名:密码@机器地址:端口/数据库名' ``` DBSession = sessionmaker(bind=engine) session = DBSession() ``` - 声明映像 使用`Declarative`方法定义的映射类依据一个基类,这个基类是维系类和数据表关系的目录,在一个普通的模块入口中,应用通常只需要一个`base`的实例。通过`declarative_base()`创建一个基类: ``` from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() ``` 有了这个`base`,就可以依据这个`base`定义任意数量的映射类,每一个类对应一张数据库表,一个简单的`user`类: ``` from sqlclchemy import Column, Integer, String class User(Base): __table__ = 'users' id = Column(Integer, primary_key=True) name = Column(String) ``` >用`Declarative`构造的一个类至少需要一个`__tablename__`属性,一个主键行。 - 创建映射类的实例(数据表中的一行): ``` new_user = User(id=3, name='zhul') ``` - 创建会话 现在准备和数据库开始会话,ORM通过Session与数据库建立连接,当应用第一次载入时,我们定义一个Session类(声明create_engine()的同时): ``` from sqlalchemy.orm import sessionmaker DBSession = sessionmaker(bind=engine) ``` 这个定制的DBSession类会创建绑定到数据库的DBSession对象,如果需要和数据库建立连接,只需要实例化一个DBSession: ``` session = DBSession() ``` 虽然上面的DBSession已经和数据库引擎engine关联,但是还没有打开任何连接。当它第一次被使用时,就会从engine维护的一个连接池中检索是否存在连接,如果存在便会保持连接直到我们提交所有更改或者关闭session对象。 - 添加新对象 ``` session.add(new_user) ``` 至此,我们可以认为,新添加的这个对象实例仍在等待中,new_user对象现在并不代表数据库中的一行数据,直到使用flush进程,session才会让SQL保持连接,如果查询这条数据的话,所有等待信息会被第一时间刷新,查询结果也会立即发出。 ``` session.commit() ``` 使用commit方法将所有更改提交到数据库。 - 回滚 ``` session.rollback() ``` - 查询 通过session的query()方法创建一个查询对象,这个函数的参数数量是可变的,参数可以是任何类或者是类的描述的集合,下面是迭代输出User类的例子: ``` for instance in session.query(User).order_by(User.id): print instance.name ``` Query也支持ORM描述作为参数。任何时候,多个类的实体或者是基于列的实体表达都可以作为query()函数的参数,返回类型是元组: ``` for id, name in session.query(User.id, User.name): print id, name ``` Query返回的元组被命名为KeyedTuple类的实例元组。并且可以把它当做一个普通的Python数据类操作,元组的名字就相当于属性的属性名,类的类名一样。 ``` for row in session.query(User, User.name).all(): ``` 查询条件筛选`filter` - 等值筛选 ``` session.query(User).filter(User.id == 1) ``` - 模糊查询 ``` for i in session.query(User).filter(User.name.like('%zhul%')): print i.id, i.name ``` - 范围条件(in/not in) ``` for i in session.query(User).filter(User.id.in_([1, 2, 3])): print i.name for i in session.query(User).filter(~User.id.in_([1, 2, 3])): print i.name ``` - 空值条件 ``` session.query(User).filter(User.name == None) session.query(User).filter(User.name.is_(None)) session.query(User).filter(User.name != None) session.query(User).filter(User.name.isnot(None)) ``` - 并且条件(AND) ``` from sqlalchemy import and_ session.query(User).filter(User.name=='tom').filter(User.id==1) session.query(User).filter(User.name=='tom', User.id==1) session.query(User).filter(and_(User.name=='tom', User.id==1)) ``` - 或者条件(OR) ``` session.query(User).filter(or_(User.name=='tom', User.id==1)) ``` - sql语句查询 ``` from sqlalchemy import text session.query(User).from_statement( test('select * from users where name=:name and id=:id')).params(name='tom', id=1).all() ``` |
| json metadata | {"tags":["python","sqlalchemy","db"],"app":"steemit/0.1","format":"markdown"} |
| Transaction Info | Block #22732193/Trx 70c00bf91e3633697b75a4ee68a2ce648c6f3114 |
View Raw JSON Data
{
"trx_id": "70c00bf91e3633697b75a4ee68a2ce648c6f3114",
"block": 22732193,
"trx_in_block": 27,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-25T06:35:12",
"op": [
"comment",
{
"parent_author": "",
"parent_permlink": "python",
"author": "pmliang",
"permlink": "sqlalchemy",
"title": "sqlalchemy用法",
"body": "```\nfrom sqlalchemy import Column, String, create_engine\nfrom sqlalchemy.orm import sessionmaker\nfrom sqlalchemy.ext.declarative import declarative_base\n```\n\n- 连接\n\n```\nBase = declarative_base()\nengine = create_engine('postgresql://midwaredata:[email protected]:5433/qhinfo', echo=True)\n```\necho为True的时候,会显示每一条执行的sql语句\n\n>`create_engine`用来初始化数据库连接,`sqlalchemy`用一个字符串表示连接信息:\n'数据库类型+数据库驱动://用户名:密码@机器地址:端口/数据库名'\n\n```\nDBSession = sessionmaker(bind=engine)\nsession = DBSession()\n```\n- 声明映像\n\n使用`Declarative`方法定义的映射类依据一个基类,这个基类是维系类和数据表关系的目录,在一个普通的模块入口中,应用通常只需要一个`base`的实例。通过`declarative_base()`创建一个基类:\n```\nfrom sqlalchemy.ext.declarative import declarative_base\nBase = declarative_base()\n```\n\n有了这个`base`,就可以依据这个`base`定义任意数量的映射类,每一个类对应一张数据库表,一个简单的`user`类:\n```\nfrom sqlclchemy import Column, Integer, String\nclass User(Base):\n __table__ = 'users'\n id = Column(Integer, primary_key=True)\n name = Column(String)\n```\n>用`Declarative`构造的一个类至少需要一个`__tablename__`属性,一个主键行。\n\n- 创建映射类的实例(数据表中的一行):\n\n```\nnew_user = User(id=3, name='zhul')\n```\n- 创建会话\n\n现在准备和数据库开始会话,ORM通过Session与数据库建立连接,当应用第一次载入时,我们定义一个Session类(声明create_engine()的同时):\n```\nfrom sqlalchemy.orm import sessionmaker\nDBSession = sessionmaker(bind=engine)\n```\n这个定制的DBSession类会创建绑定到数据库的DBSession对象,如果需要和数据库建立连接,只需要实例化一个DBSession:\n```\nsession = DBSession()\n```\n虽然上面的DBSession已经和数据库引擎engine关联,但是还没有打开任何连接。当它第一次被使用时,就会从engine维护的一个连接池中检索是否存在连接,如果存在便会保持连接直到我们提交所有更改或者关闭session对象。\n\n- 添加新对象\n```\nsession.add(new_user)\n```\n至此,我们可以认为,新添加的这个对象实例仍在等待中,new_user对象现在并不代表数据库中的一行数据,直到使用flush进程,session才会让SQL保持连接,如果查询这条数据的话,所有等待信息会被第一时间刷新,查询结果也会立即发出。\n```\nsession.commit()\n```\n使用commit方法将所有更改提交到数据库。\n\n- 回滚\n```\nsession.rollback()\n```\n\n- 查询\n\n通过session的query()方法创建一个查询对象,这个函数的参数数量是可变的,参数可以是任何类或者是类的描述的集合,下面是迭代输出User类的例子:\n```\nfor instance in session.query(User).order_by(User.id):\n print instance.name\n```\n\nQuery也支持ORM描述作为参数。任何时候,多个类的实体或者是基于列的实体表达都可以作为query()函数的参数,返回类型是元组:\n\n```\nfor id, name in session.query(User.id, User.name):\n print id, name\n```\n\nQuery返回的元组被命名为KeyedTuple类的实例元组。并且可以把它当做一个普通的Python数据类操作,元组的名字就相当于属性的属性名,类的类名一样。\n```\nfor row in session.query(User, User.name).all():\n \n```\n\n查询条件筛选`filter`\n- 等值筛选\n```\nsession.query(User).filter(User.id == 1)\n```\n- 模糊查询\n```\nfor i in session.query(User).filter(User.name.like('%zhul%')):\n print i.id, i.name\n```\n- 范围条件(in/not in)\n```\nfor i in session.query(User).filter(User.id.in_([1, 2, 3])):\n print i.name\n \nfor i in session.query(User).filter(~User.id.in_([1, 2, 3])):\n print i.name\n```\n\n- 空值条件\n```\nsession.query(User).filter(User.name == None)\nsession.query(User).filter(User.name.is_(None))\n\nsession.query(User).filter(User.name != None)\nsession.query(User).filter(User.name.isnot(None))\n```\n- 并且条件(AND)\n```\nfrom sqlalchemy import and_\nsession.query(User).filter(User.name=='tom').filter(User.id==1)\nsession.query(User).filter(User.name=='tom', User.id==1)\nsession.query(User).filter(and_(User.name=='tom', User.id==1))\n```\n- 或者条件(OR)\n```\nsession.query(User).filter(or_(User.name=='tom', User.id==1))\n```\n- sql语句查询\n```\nfrom sqlalchemy import text\nsession.query(User).from_statement(\ntest('select * from users where name=:name and id=:id')).params(name='tom', id=1).all()\n```",
"json_metadata": "{\"tags\":[\"python\",\"sqlalchemy\",\"db\"],\"app\":\"steemit/0.1\",\"format\":\"markdown\"}"
}
]
}2018/05/25 06:25:39
2018/05/25 06:25:39
| parent author | |
| parent permlink | python |
| author | pmliang |
| permlink | flashtext |
| title | 大规模数据清洗利器FlashText用法示例 |
| body | ### 大规模数据清洗利器FlashText用法示例 安装 ``` pip install flashtext ``` 1. ***提取关键字*** ``` >>> from flashtext import KeywordProcessor >>> keyword_processor = KeywordProcess() >>> # keyword_processor.add_keyword(<unclean name>, <standardised name>) >>> keyword_processor.add_keyword('Big Apple', 'New York') >>> keyword_processor.add_keyword('Bay Area') >>> keywords_found = keyword_processor.extract_keywords('I love Big Apple and Bay Area.') >>> keywords_found >>> # ['New York', 'Bay Area'] ``` 2. ***替换关键字*** ``` >>> keyword_processor.add_keyword('New Delhi', 'NCR region') >>> new_sentence = keyword_processor.replace_keywords('I love Big Apple and new delhi.') >>> new_sentence >>> # 'I love New York and NCR region.' ``` 3. ***关键字区分大小写*** ``` >>> from flashtext import KeywordProcessor >>> keyword_processor = KeywordProcessor(case_sensitive=True) >>> keyword_processor.add_keyword('Big Apple', 'New York') >>> keyword_processor.add_keyword('Bay Area') >>> keywords_found = keyword_processor.extract_keywords('I love big Apple and Bay Area.') >>> keywords_found >>> # ['Bay Area'] ``` 4. ***提取关键字的范围*** ``` >>> from flashtext import KeywordProcessor >>> keyword_processor = KeywordProcessor() >>> keyword_processor.add_keyword('Big Apple', 'New York') >>> keyword_processor.add_keyword('Bay Area') >>> keywords_found = keyword_processor.extract_keywords('I love big Apple and Bay Area.', span_info=True) >>> keywords_found >>> # [('New York', 7, 16), ('Bay Area', 21, 29)] ``` 5. ***获取关键字提取的额外信息*** ``` >>> from flashtext import KeywordProcessor >>> kp = KeywordProcessor() >>> kp.add_keyword('Taj Mahal', ('Monument', 'Taj Mahal')) >>> kp.add_keyword('Delhi', ('Location', 'Delhi')) >>> kp.extract_keywords('Taj Mahal is in Delhi.') >>> # [('Monument', 'Taj Mahal'), ('Location', 'Delhi')] >>> # NOTE: replace_keywords feature won't work with this. ``` 6. ***No clean name for Keywords*** ``` >>> from flashtext import KeywordProcessor >>> keyword_processor = KeywordProcessor() >>> keyword_processor.add_keyword('Big Apple') >>> keyword_processor.add_keyword('Bay Area') >>> keywords_found = keyword_processor.extract_keywords('I love big Apple and Bay Area.') >>> keywords_found >>> # ['Big Apple', 'Bay Area'] ``` 7. ***同时添加多个关键字*** ``` >>> from flashtext import KeywordProcessor >>> keyword_processor = KeywordProcessor() >>> keyword_dict = { >>> "java": ["java_2e", "java programing"], >>> "product management": ["PM", "product manager"] >>> } >>> # {'clean_name': ['list of unclean names']} >>> keyword_processor.add_keywords_from_dict(keyword_dict) >>> # Or add keywords from a list: >>> keyword_processor.add_keywords_from_list(["java", "python"]) >>> keyword_processor.extract_keywords('I am a product manager for a java_2e platform') >>> # output ['product management', 'java'] ``` 8. ***移除关键字*** ``` >>> from flashtext import KeywordProcessor >>> keyword_processor = KeywordProcessor() >>> keyword_dict = { >>> "java": ["java_2e", "java programing"], >>> "product management": ["PM", "product manager"] >>> } >>> keyword_processor.add_keywords_from_dict(keyword_dict) >>> print(keyword_processor.extract_keywords('I am a product manager for a java_2e platform')) >>> # output ['product management', 'java'] >>> keyword_processor.remove_keyword('java_2e') >>> # you can also remove keywords from a list/ dictionary >>> keyword_processor.remove_keywords_from_dict({"product management": ["PM"]}) >>> keyword_processor.remove_keywords_from_list(["java programing"]) >>> keyword_processor.extract_keywords('I am a product manager for a java_2e platform') >>> # output ['product management'] ``` 9. ***检查KeywordProcessor的大小*** ``` >>> from flashtext import KeywordProcessor >>> keyword_processor = KeywordProcessor() >>> keyword_dict = { >>> "java": ["java_2e", "java programing"], >>> "product management": ["PM", "product manager"] >>> } >>> keyword_processor.add_keywords_from_dict(keyword_dict) >>> print(len(keyword_processor)) >>> # output 4 ``` 10. ***检查是否存在某个关键字*** ``` >>> from flashtext import KeywordProcessor >>> keyword_processor = KeywordProcessor() >>> keyword_processor.add_keyword('j2ee', 'Java') >>> 'j2ee' in keyword_processor >>> # output: True >>> keyword_processor.get_keyword('j2ee') >>> # output: Java >>> keyword_processor['colour'] = 'color' >>> keyword_processor['colour'] >>> # output: color ``` 11. ***获取所有的关键字*** ``` >>> from flashtext import KeywordProcessor >>> keyword_processor = KeywordProcessor() >>> keyword_processor.add_keyword('j2ee', 'Java') >>> keyword_processor.add_keyword('colour', 'color') >>> keyword_processor.get_all_keywords() >>> # output: {'colour': 'color', 'j2ee': 'Java'} ``` 12. ***设置或添加字符作为单词字符的一部分*** ``` >>> from flashtext import KeywordProcessor >>> keyword_processor = KeywordProcessor() >>> keyword_processor.add_keyword('Big Apple') >>> print(keyword_processor.extract_keywords('I love Big Apple/Bay Area.')) >>> # ['Big Apple'] >>> keyword_processor.add_non_word_boundary('/') >>> print(keyword_processor.extract_keywords('I love Big Apple/Bay Area.')) >>> # [] ``` |
| json metadata | {"tags":["python","flsahtext"],"app":"steemit/0.1","format":"markdown"} |
| Transaction Info | Block #22732002/Trx aeba205aeaa0a0d322e3f3d0c767a24dcc8dc625 |
View Raw JSON Data
{
"trx_id": "aeba205aeaa0a0d322e3f3d0c767a24dcc8dc625",
"block": 22732002,
"trx_in_block": 7,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-25T06:25:39",
"op": [
"comment",
{
"parent_author": "",
"parent_permlink": "python",
"author": "pmliang",
"permlink": "flashtext",
"title": "大规模数据清洗利器FlashText用法示例",
"body": "### 大规模数据清洗利器FlashText用法示例\n\n安装\n```\npip install flashtext\n```\n\n\n1. ***提取关键字***\n\n```\n>>> from flashtext import KeywordProcessor\n>>> keyword_processor = KeywordProcess()\n>>> # keyword_processor.add_keyword(<unclean name>, <standardised name>)\n>>> keyword_processor.add_keyword('Big Apple', 'New York')\n>>> keyword_processor.add_keyword('Bay Area')\n>>> keywords_found = keyword_processor.extract_keywords('I love Big Apple and Bay Area.')\n>>> keywords_found\n>>> # ['New York', 'Bay Area']\n```\n\n2. ***替换关键字***\n\n```\n>>> keyword_processor.add_keyword('New Delhi', 'NCR region')\n>>> new_sentence = keyword_processor.replace_keywords('I love Big Apple and new delhi.')\n>>> new_sentence\n>>> # 'I love New York and NCR region.'\n```\n3. ***关键字区分大小写***\n\n```\n>>> from flashtext import KeywordProcessor\n>>> keyword_processor = KeywordProcessor(case_sensitive=True)\n>>> keyword_processor.add_keyword('Big Apple', 'New York')\n>>> keyword_processor.add_keyword('Bay Area')\n>>> keywords_found = keyword_processor.extract_keywords('I love big Apple and Bay Area.')\n>>> keywords_found\n>>> # ['Bay Area']\n```\n\n4. ***提取关键字的范围***\n\n```\n>>> from flashtext import KeywordProcessor\n>>> keyword_processor = KeywordProcessor()\n>>> keyword_processor.add_keyword('Big Apple', 'New York')\n>>> keyword_processor.add_keyword('Bay Area')\n>>> keywords_found = keyword_processor.extract_keywords('I love big Apple and Bay Area.', span_info=True)\n>>> keywords_found\n>>> # [('New York', 7, 16), ('Bay Area', 21, 29)]\n```\n\n5. ***获取关键字提取的额外信息***\n\n```\n>>> from flashtext import KeywordProcessor\n>>> kp = KeywordProcessor()\n>>> kp.add_keyword('Taj Mahal', ('Monument', 'Taj Mahal'))\n>>> kp.add_keyword('Delhi', ('Location', 'Delhi'))\n>>> kp.extract_keywords('Taj Mahal is in Delhi.')\n>>> # [('Monument', 'Taj Mahal'), ('Location', 'Delhi')]\n>>> # NOTE: replace_keywords feature won't work with this.\n```\n\n6. ***No clean name for Keywords***\n\n```\n>>> from flashtext import KeywordProcessor\n>>> keyword_processor = KeywordProcessor()\n>>> keyword_processor.add_keyword('Big Apple')\n>>> keyword_processor.add_keyword('Bay Area')\n>>> keywords_found = keyword_processor.extract_keywords('I love big Apple and Bay Area.')\n>>> keywords_found\n>>> # ['Big Apple', 'Bay Area']\n```\n\n7. ***同时添加多个关键字***\n```\n>>> from flashtext import KeywordProcessor\n>>> keyword_processor = KeywordProcessor()\n>>> keyword_dict = {\n>>> \"java\": [\"java_2e\", \"java programing\"],\n>>> \"product management\": [\"PM\", \"product manager\"]\n>>> }\n>>> # {'clean_name': ['list of unclean names']}\n>>> keyword_processor.add_keywords_from_dict(keyword_dict)\n>>> # Or add keywords from a list:\n>>> keyword_processor.add_keywords_from_list([\"java\", \"python\"])\n>>> keyword_processor.extract_keywords('I am a product manager for a java_2e platform')\n>>> # output ['product management', 'java']\n```\n\n8. ***移除关键字***\n```\n>>> from flashtext import KeywordProcessor\n>>> keyword_processor = KeywordProcessor()\n>>> keyword_dict = {\n>>> \"java\": [\"java_2e\", \"java programing\"],\n>>> \"product management\": [\"PM\", \"product manager\"]\n>>> }\n>>> keyword_processor.add_keywords_from_dict(keyword_dict)\n>>> print(keyword_processor.extract_keywords('I am a product manager for a java_2e platform'))\n>>> # output ['product management', 'java']\n>>> keyword_processor.remove_keyword('java_2e')\n>>> # you can also remove keywords from a list/ dictionary\n>>> keyword_processor.remove_keywords_from_dict({\"product management\": [\"PM\"]})\n>>> keyword_processor.remove_keywords_from_list([\"java programing\"])\n>>> keyword_processor.extract_keywords('I am a product manager for a java_2e platform')\n>>> # output ['product management']\n```\n\n9. ***检查KeywordProcessor的大小***\n\n```\n>>> from flashtext import KeywordProcessor\n>>> keyword_processor = KeywordProcessor()\n>>> keyword_dict = {\n>>> \"java\": [\"java_2e\", \"java programing\"],\n>>> \"product management\": [\"PM\", \"product manager\"]\n>>> }\n>>> keyword_processor.add_keywords_from_dict(keyword_dict)\n>>> print(len(keyword_processor))\n>>> # output 4\n```\n\n10. ***检查是否存在某个关键字***\n```\n>>> from flashtext import KeywordProcessor\n>>> keyword_processor = KeywordProcessor()\n>>> keyword_processor.add_keyword('j2ee', 'Java')\n>>> 'j2ee' in keyword_processor\n>>> # output: True\n>>> keyword_processor.get_keyword('j2ee')\n>>> # output: Java\n>>> keyword_processor['colour'] = 'color'\n>>> keyword_processor['colour']\n>>> # output: color\n```\n\n11. ***获取所有的关键字***\n```\n>>> from flashtext import KeywordProcessor\n>>> keyword_processor = KeywordProcessor()\n>>> keyword_processor.add_keyword('j2ee', 'Java')\n>>> keyword_processor.add_keyword('colour', 'color')\n>>> keyword_processor.get_all_keywords()\n>>> # output: {'colour': 'color', 'j2ee': 'Java'}\n```\n\n12. ***设置或添加字符作为单词字符的一部分***\n```\n>>> from flashtext import KeywordProcessor\n>>> keyword_processor = KeywordProcessor()\n>>> keyword_processor.add_keyword('Big Apple')\n>>> print(keyword_processor.extract_keywords('I love Big Apple/Bay Area.'))\n>>> # ['Big Apple']\n>>> keyword_processor.add_non_word_boundary('/')\n>>> print(keyword_processor.extract_keywords('I love Big Apple/Bay Area.'))\n>>> # []\n```",
"json_metadata": "{\"tags\":[\"python\",\"flsahtext\"],\"app\":\"steemit/0.1\",\"format\":\"markdown\"}"
}
]
}thetroublenotesupvoted (2.00%) @pmliang / 6dupga-awk2018/05/22 14:29:09
thetroublenotesupvoted (2.00%) @pmliang / 6dupga-awk
2018/05/22 14:29:09
| voter | thetroublenotes |
| author | pmliang |
| permlink | 6dupga-awk |
| weight | 200 (2.00%) |
| Transaction Info | Block #22655656/Trx 38ed0a9eef2538d85b7ff7f8e53a023d6328a637 |
View Raw JSON Data
{
"trx_id": "38ed0a9eef2538d85b7ff7f8e53a023d6328a637",
"block": 22655656,
"trx_in_block": 0,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-22T14:29:09",
"op": [
"vote",
{
"voter": "thetroublenotes",
"author": "pmliang",
"permlink": "6dupga-awk",
"weight": 200
}
]
}ubgupvoted (1.00%) @pmliang / 6dupga-awk2018/05/22 14:07:30
ubgupvoted (1.00%) @pmliang / 6dupga-awk
2018/05/22 14:07:30
| voter | ubg |
| author | pmliang |
| permlink | 6dupga-awk |
| weight | 100 (1.00%) |
| Transaction Info | Block #22655223/Trx 77feae7543808f68be04b5e8d03c595de59c0fbf |
View Raw JSON Data
{
"trx_id": "77feae7543808f68be04b5e8d03c595de59c0fbf",
"block": 22655223,
"trx_in_block": 13,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-22T14:07:30",
"op": [
"vote",
{
"voter": "ubg",
"author": "pmliang",
"permlink": "6dupga-awk",
"weight": 100
}
]
}pmliangupvoted (100.00%) @pmliang / 6dupga-awk2018/05/22 13:59:39
pmliangupvoted (100.00%) @pmliang / 6dupga-awk
2018/05/22 13:59:39
| voter | pmliang |
| author | pmliang |
| permlink | 6dupga-awk |
| weight | 10000 (100.00%) |
| Transaction Info | Block #22655066/Trx 9b24c6cfc0cfc21f9b5a45a20322e89dae1c9f8a |
View Raw JSON Data
{
"trx_id": "9b24c6cfc0cfc21f9b5a45a20322e89dae1c9f8a",
"block": 22655066,
"trx_in_block": 15,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-22T13:59:39",
"op": [
"vote",
{
"voter": "pmliang",
"author": "pmliang",
"permlink": "6dupga-awk",
"weight": 10000
}
]
}pmliangpublished a new post: 6dupga-awk2018/05/22 13:59:00
pmliangpublished a new post: 6dupga-awk
2018/05/22 13:59:00
| parent author | |
| parent permlink | linux |
| author | pmliang |
| permlink | 6dupga-awk |
| title | AWK常见用法(二) |
| body | ## AWK实例演示 > 当出现合并文件的需求时,可以考虑使用数组 1. 合并两个文件,a1和a2: ``` # cat a1 1 苹果 水果 2 梨子 水果 3 草莓 水果 4 土豆 蔬菜 5 恐龙 动物 # cat a2 01,苹果 水果 02,梨子 水果 03,香蕉 水果 04,土豆 蔬菜 05,香肠 食品 # awk -F"[ ,]" 'NR==FNR{a[$2]=$1}NR!=FNR{print $0,a[$2]}' a1 a2 01,苹果 1 02,梨子 2 03,香蕉 04,土豆 4 05,香肠 ``` ``` # cat b1 tom:1000 bob:1001 mary:1002 # cat b2 1000:a.txt 1000:b.txt 1001:c.txt 1001:d.txt 1002:e.txt 1002:f.txt # awk -F: 'NR==FNR{a[$2]=$0}NR!=FNR{print a[$1]":"$2}' b1 b2 tom:1000:a.txt tom:1000:b.txt bob:1001:c.txt bob:1001:d.txt mary:1002:e.txt mary:1002:f.txt ``` > 通过这两个例子,我们可以看出,在使用数组的时候尽量已相同的部分作为数组的下标 2. 将相同行合并为一行 ``` # cat a1 1 苹果 1 水果 2 梨子 2 水果 3 草莓 3 水果 4 土豆 4 蔬菜 5 恐龙 5 动物 # awk 'NR==1{printf "%s",$0;x=$1}NR!=1{if($1==x){printf " %s",$2}else printf "\n%s",$0;x=$1}END{printf "\n"}' a1 1 苹果 水果 2 梨子 水果 3 草莓 水果 4 土豆 蔬菜 5 恐龙 动物 ``` 3. 求交集 ``` # cat a1 10/11111111,11/22222222,12/33333333,13/44444444 14/55555555,15/66666666,16/77777777,17/88888888 # cat a2 11111111 66666666 56567778 98987654 # awk -F[/,] 'NR==FNR{a[$1]}NR!=FNR{if($2 in a){print $0}}' a2 a1 10/11111111,11/22222222,12/33333333,13/44444444 ``` 4. 统计次数 ``` # cat a1 tom tom bob mary zhangsan lisi bob mary tom # awk '{sum+=NF}END{print sum}' a1 9 # awk '{for(i=1;i<=NF;i++){a[$i]++}}END{for(x in a){print x"出现了"a[x]"次"}}' a1 mary出现了2次 zhangsan出现了1次 tom出现了3次 lisi出现了1次 bob出现了2次 ``` 5. 求和 ``` # cat /proc/1/smaps | awk '/Shared_Clean/{AA+=$2}/Shared_Dirty/{BB+=$2}END{print "干净页:"AA"KB";print "脏页:"BB"KB"}' 干净页:2672KB 脏页:0KB ``` |
| json metadata | {"tags":["linux","awk","shell"],"app":"steemit/0.1","format":"markdown"} |
| Transaction Info | Block #22655053/Trx b34fdccf850d67fe0817c20dfcb712d7312f9356 |
View Raw JSON Data
{
"trx_id": "b34fdccf850d67fe0817c20dfcb712d7312f9356",
"block": 22655053,
"trx_in_block": 45,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-22T13:59:00",
"op": [
"comment",
{
"parent_author": "",
"parent_permlink": "linux",
"author": "pmliang",
"permlink": "6dupga-awk",
"title": "AWK常见用法(二)",
"body": "## AWK实例演示\n> 当出现合并文件的需求时,可以考虑使用数组\n\n1. 合并两个文件,a1和a2:\n```\n# cat a1\n1 苹果 水果\n2 梨子 水果\n3 草莓 水果\n4 土豆 蔬菜\n5 恐龙 动物\n# cat a2\n01,苹果 水果\n02,梨子 水果\n03,香蕉 水果\n04,土豆 蔬菜\n05,香肠 食品\n# awk -F\"[ ,]\" 'NR==FNR{a[$2]=$1}NR!=FNR{print $0,a[$2]}' a1 a2\n01,苹果 1\n02,梨子 2\n03,香蕉 \n04,土豆 4\n05,香肠\n```\n\n```\n# cat b1\ntom:1000\nbob:1001\nmary:1002\n# cat b2\n1000:a.txt\n1000:b.txt\n1001:c.txt\n1001:d.txt\n1002:e.txt\n1002:f.txt\n# awk -F: 'NR==FNR{a[$2]=$0}NR!=FNR{print a[$1]\":\"$2}' b1 b2\ntom:1000:a.txt\ntom:1000:b.txt\nbob:1001:c.txt\nbob:1001:d.txt\nmary:1002:e.txt\nmary:1002:f.txt\n```\n> 通过这两个例子,我们可以看出,在使用数组的时候尽量已相同的部分作为数组的下标\n\n2. 将相同行合并为一行\n```\n# cat a1\n1 苹果\n1 水果\n2 梨子\n2 水果\n3 草莓\n3 水果\n4 土豆\n4 蔬菜\n5 恐龙\n5 动物\n# awk 'NR==1{printf \"%s\",$0;x=$1}NR!=1{if($1==x){printf \" %s\",$2}else printf \"\\n%s\",$0;x=$1}END{printf \"\\n\"}' a1\n1 苹果 水果\n2 梨子 水果\n3 草莓 水果\n4 土豆 蔬菜\n5 恐龙 动物\n```\n3. 求交集\n```\n# cat a1\n10/11111111,11/22222222,12/33333333,13/44444444\n14/55555555,15/66666666,16/77777777,17/88888888\n# cat a2\n11111111\n66666666\n56567778\n98987654\n# awk -F[/,] 'NR==FNR{a[$1]}NR!=FNR{if($2 in a){print $0}}' a2 a1\n10/11111111,11/22222222,12/33333333,13/44444444\n```\n4. 统计次数\n```\n# cat a1\ntom tom bob mary\nzhangsan lisi\nbob mary tom\n# awk '{sum+=NF}END{print sum}' a1\n9\n# awk '{for(i=1;i<=NF;i++){a[$i]++}}END{for(x in a){print x\"出现了\"a[x]\"次\"}}' a1\nmary出现了2次\nzhangsan出现了1次\ntom出现了3次\nlisi出现了1次\nbob出现了2次\n```\n5. 求和\n```\n# cat /proc/1/smaps | awk '/Shared_Clean/{AA+=$2}/Shared_Dirty/{BB+=$2}END{print \"干净页:\"AA\"KB\";print \"脏页:\"BB\"KB\"}'\n干净页:2672KB\n脏页:0KB\n```",
"json_metadata": "{\"tags\":[\"linux\",\"awk\",\"shell\"],\"app\":\"steemit/0.1\",\"format\":\"markdown\"}"
}
]
}pmliangupvoted (100.00%) @pleasestop / introducing-pleasestop-here-to-reduce-comment-spam2018/05/20 13:40:57
pmliangupvoted (100.00%) @pleasestop / introducing-pleasestop-here-to-reduce-comment-spam
2018/05/20 13:40:57
| voter | pmliang |
| author | pleasestop |
| permlink | introducing-pleasestop-here-to-reduce-comment-spam |
| weight | 10000 (100.00%) |
| Transaction Info | Block #22597101/Trx f39fbd60aadcf8e22749a0d0109c9fe9043414a0 |
View Raw JSON Data
{
"trx_id": "f39fbd60aadcf8e22749a0d0109c9fe9043414a0",
"block": 22597101,
"trx_in_block": 6,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-20T13:40:57",
"op": [
"vote",
{
"voter": "pmliang",
"author": "pleasestop",
"permlink": "introducing-pleasestop-here-to-reduce-comment-spam",
"weight": 10000
}
]
}2018/05/20 13:40:12
2018/05/20 13:40:12
| parent author | introduce.bot |
| parent permlink | introduce-bot-re-pmliangawk |
| author | pmliang |
| permlink | re-introducebot-introduce-bot-re-pmliangawk-20180520t133954604z |
| title | |
| body | thank you |
| json metadata | {"tags":["linux"],"app":"steemit/0.1"} |
| Transaction Info | Block #22597086/Trx 13c3480a547e9f73c9ebda308408014d9937c867 |
View Raw JSON Data
{
"trx_id": "13c3480a547e9f73c9ebda308408014d9937c867",
"block": 22597086,
"trx_in_block": 11,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-20T13:40:12",
"op": [
"comment",
{
"parent_author": "introduce.bot",
"parent_permlink": "introduce-bot-re-pmliangawk",
"author": "pmliang",
"permlink": "re-introducebot-introduce-bot-re-pmliangawk-20180520t133954604z",
"title": "",
"body": "thank you",
"json_metadata": "{\"tags\":[\"linux\"],\"app\":\"steemit/0.1\"}"
}
]
}2018/05/20 13:38:51
2018/05/20 13:38:51
| voter | pmliang |
| author | pmliang |
| permlink | awk |
| weight | 10000 (100.00%) |
| Transaction Info | Block #22597059/Trx e0a4cf2ee123743d5f20c291923a67c47e1170f6 |
View Raw JSON Data
{
"trx_id": "e0a4cf2ee123743d5f20c291923a67c47e1170f6",
"block": 22597059,
"trx_in_block": 18,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-20T13:38:51",
"op": [
"vote",
{
"voter": "pmliang",
"author": "pmliang",
"permlink": "awk",
"weight": 10000
}
]
}pmliangupvoted (100.00%) @introduce.bot / introduce-bot-re-pmliangawk2018/05/20 13:38:42
pmliangupvoted (100.00%) @introduce.bot / introduce-bot-re-pmliangawk
2018/05/20 13:38:42
| voter | pmliang |
| author | introduce.bot |
| permlink | introduce-bot-re-pmliangawk |
| weight | 10000 (100.00%) |
| Transaction Info | Block #22597056/Trx b3a1733e5cea4b8f9f24f8205f4a04d9a8a3f61f |
View Raw JSON Data
{
"trx_id": "b3a1733e5cea4b8f9f24f8205f4a04d9a8a3f61f",
"block": 22597056,
"trx_in_block": 41,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-20T13:38:42",
"op": [
"vote",
{
"voter": "pmliang",
"author": "introduce.bot",
"permlink": "introduce-bot-re-pmliangawk",
"weight": 10000
}
]
}pmliangupvoted (100.00%) @maishunheng / today--my-friends-and-i-got-up--2018-4-0-20-43-52018/05/20 12:45:03
pmliangupvoted (100.00%) @maishunheng / today--my-friends-and-i-got-up--2018-4-0-20-43-5
2018/05/20 12:45:03
| voter | pmliang |
| author | maishunheng |
| permlink | today--my-friends-and-i-got-up--2018-4-0-20-43-5 |
| weight | 10000 (100.00%) |
| Transaction Info | Block #22595984/Trx 9f2739d898fd7b37b13fd23bd8b4c4ba1cc1819f |
View Raw JSON Data
{
"trx_id": "9f2739d898fd7b37b13fd23bd8b4c4ba1cc1819f",
"block": 22595984,
"trx_in_block": 8,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-20T12:45:03",
"op": [
"vote",
{
"voter": "pmliang",
"author": "maishunheng",
"permlink": "today--my-friends-and-i-got-up--2018-4-0-20-43-5",
"weight": 10000
}
]
}2018/05/20 12:44:18
2018/05/20 12:44:18
| voter | ax3 |
| author | pmliang |
| permlink | awk |
| weight | 100 (1.00%) |
| Transaction Info | Block #22595969/Trx ba59cb233c31e8f6d94b691dfacded02be9a7d56 |
View Raw JSON Data
{
"trx_id": "ba59cb233c31e8f6d94b691dfacded02be9a7d56",
"block": 22595969,
"trx_in_block": 21,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-20T12:44:18",
"op": [
"vote",
{
"voter": "ax3",
"author": "pmliang",
"permlink": "awk",
"weight": 100
}
]
}introduce.botreplied to @pmliang / introduce-bot-re-pmliangawk2018/05/20 12:44:15
introduce.botreplied to @pmliang / introduce-bot-re-pmliangawk
2018/05/20 12:44:15
| parent author | pmliang |
| parent permlink | awk |
| author | introduce.bot |
| permlink | introduce-bot-re-pmliangawk |
| title | |
| body | ✅ @pmliang, I gave you an upvote on your first post! **Please give me a follow** and I will give you a follow in return!<br><br>Please also take a moment to read [this post](https://steemit.com/spam/@pleasestop/introducing-pleasestop-here-to-reduce-comment-spam) regarding bad behavior on Steemit. |
| json metadata | |
| Transaction Info | Block #22595968/Trx 1efbcb65346d14bc1a17aa6e8a4025577bfe591a |
View Raw JSON Data
{
"trx_id": "1efbcb65346d14bc1a17aa6e8a4025577bfe591a",
"block": 22595968,
"trx_in_block": 58,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-20T12:44:15",
"op": [
"comment",
{
"parent_author": "pmliang",
"parent_permlink": "awk",
"author": "introduce.bot",
"permlink": "introduce-bot-re-pmliangawk",
"title": "",
"body": "✅ @pmliang, I gave you an upvote on your first post! **Please give me a follow** and I will give you a follow in return!<br><br>Please also take a moment to read [this post](https://steemit.com/spam/@pleasestop/introducing-pleasestop-here-to-reduce-comment-spam) regarding bad behavior on Steemit.",
"json_metadata": ""
}
]
}introduce.botupvoted (0.58%) @pmliang / awk2018/05/20 12:44:15
introduce.botupvoted (0.58%) @pmliang / awk
2018/05/20 12:44:15
| voter | introduce.bot |
| author | pmliang |
| permlink | awk |
| weight | 58 (0.58%) |
| Transaction Info | Block #22595968/Trx 469a5f2b8693bc6c16871fadd099ce97280e72ae |
View Raw JSON Data
{
"trx_id": "469a5f2b8693bc6c16871fadd099ce97280e72ae",
"block": 22595968,
"trx_in_block": 36,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-20T12:44:15",
"op": [
"vote",
{
"voter": "introduce.bot",
"author": "pmliang",
"permlink": "awk",
"weight": 58
}
]
}2018/05/20 12:44:09
2018/05/20 12:44:09
| parent author | |
| parent permlink | linux |
| author | pmliang |
| permlink | awk |
| title | AWK常见用法(一) |
| body | ## 一、初识AWK `AWK`有其他的衍生版本,比如`nawk`和`gawk`,在Linux发行版里,默认使用的是`gawk`: ``` # ls -l `which awk` lrwxrwxrwx. 1 root root 4 5月 9 20:25 /usr/bin/awk -> gawk ``` ## 二、AWK的工作流程 - `AWK`是按行处理文本,将行按照某一分隔符进行分割,其中分割之后的第一部分为`$1`,第二部分为`$2`,依次类推,其中`$0`表示整行,超过10的要将数字用括号括起来,比如`$(10)` - `AWK`默认的分隔符是空格和`tab`,其中操作命令必须写在{}里面,语法: ``` awk '/模式/{print $1}' file //模式支持正则表达式,只对含有该模式的行进行操作 ``` - 可以使用`-F`选项指定分隔符: ``` awk -F: '/模式/{print $1}' file ``` ## 三、常见操作符的使用(例子中passwd文件使用/etc/passwd文件的前6行) 常见的操作符有:`~`、`!~`、`==`、`!=`、`>`、`<`、`++`、`--`等 1. `~`和`!~`表示包含和不包含: ``` # awk -F: '$1~/ro/{print $0}' passwd root:x:0:0:root:/root:/bin/bash ``` 2. `==`和`!=`表示严格的等于和不等于: ``` # awk -F: '$3==1{print $0}' passwd bin:x:1:1:bin:/bin:/sbin/nologin ``` ``` # awk -F: '{$3++;print $3}' passwd 1 2 3 4 5 6 ``` 3. 其他的一些操作符同理,两个以上的条件需要使用连接符`&&`或`||` ## 四、AWK中 BEGIN 和 NED 的用法 1. `BEGIN`中的命令是在AWK读取文本的第一行之前进行操作: ``` # awk -F: 'BEGIN{print "用户名"}{print $1}' passwd 用户名 root bin daemon adm lp sync ``` 2. `END`中的命令是在读取完最后一行之后进行的操作: ``` # awk -F: '{print $1}END{print "结束"}' passwd root bin daemon adm lp sync 结束 ``` 3. BEGIN和END可以同时出现,也可以单独出现,BEGIN中可以定义变量: ``` # awk -F: 'BEGIN{a=1}{print a}' passwd 1 1 1 1 1 1 ``` 如何没有预先定义变量的话,在后面也是可以引用的,只不过这个变量的值为空。引用变量的时候不加`$` `END`中也可以进行最终的计算: ``` # awk -F: 'BEGIN{sum=0}{sum+=$3}END{print "所有UID的和为:"sum}' passwd 所有UID的和为:15 ``` 或者不预先定义变量: ``` # awk -F: '{sum+=$3}END{print "所有UID的和为:"sum}' passwd 所有UID的和为:15 ``` ## 五、AWK中常见内置变量的用法 1. `FS`代表分隔符: ``` # awk 'BEGIN{FS=":"}{print $1}' passwd root bin daemon adm lp sync ``` 2. `OFS`为打印输出的分隔符,默认的是空格: ``` # awk 'BEGIN{FS=":";OFS="---"}{print $1,$2}' passwd root---x bin---x daemon---x adm---x lp---x sync---x ``` 3. `NF`的值表示将每一行按照`FS`指定的分隔符分为多少段: ``` # awk 'BEGIN{FS=":"}{print NF}' passwd 7 7 7 7 7 7 ``` 如果要打印每一行的最后一段,可以使用以下用法: ``` # awk 'BEGIN{FS=":"}{print $NF}' passwd /bin/bash /sbin/nologin /sbin/nologin /sbin/nologin /sbin/nologin /bin/sync ``` 4. 前面提到过,AWK是将文件按行进行处理,那么AWK是如何分别每一行的呢?使用的就是`RS`的值,默认为`\n`: ``` # cat test.txt 1,张三:经理 2,李四:职员 3,王五:老板 # awk -F[:,] 'BEGIN{RS=" "}{print $2,$3}' test.txt 张三 经理 李四 职员 王五 老板 ``` 5. `ORS`变量的值决定输出行的分隔符,默认的为`\n`: ``` # awk 'BEGIN{ORS="---"}{print $0}' passwd root:x:0:0:root:/root:/bin/bash---bin:x:1:1:bin:/bin:/sbin/nologin---daemon:x:2:2:daemon:/sbin:/sbin/nologin---adm:x:3:4:adm:/var/adm:/sbin/nologin---lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin---sync:x:5:0:sync:/sbin:/bin/sync--- ``` 6. `FILENAME`变量的值为当前操作文件的文件名: ``` # awk -F: '{print FILENAME}' passwd passwd passwd passwd passwd passwd passwd ``` 7. `NR`变量的值表示当前正在操作的行号: ``` # awk -F: '{print NR}' passwd 1 2 3 4 5 6 ``` 如果这里将行分隔符`RS`赋值为`-`,验证`NR`的值: ``` # awk 'BEGIN{RS="-"}{print NR}' passwd 1 ``` 8. `FNR`也表示当前操作的行号,不同的是,当对一个文件进行操作的时候`FNR`和`NR`的值是一样的。当对两个文件进行操作时,`FNR`和`NR`的值是不一样的: ``` # awk -F: '{print NR,$1,FNR}' passwd shadow 1 root 1 2 bin 2 3 daemon 3 4 adm 4 5 lp 5 6 sync 6 7 root 1 8 bin 2 9 daemon 3 10 adm 4 11 lp 5 12 sync 6 ``` ## 六、判断和循坏语句 1. `if`语句: 语法,如果语句没有使用{},则要使用;分隔 ``` if(判断1){语句1}else if(判断2){语句2}else{语句3} if(判断1)语句1;else if(判断2)语句2;else语句3 ``` ``` # awk -F: '{if($3==0){print $1"是root"}else if($3>=1000){print $1"是普通用户"}else{print $1"是系统用户"}}' passwd root是root bin是系统用户 daemon是系统用户 adm是系统用户 lp是系统用户 sync是系统用户 ``` 2. `for`循坏语句: ``` awk -F: '{for(i=1;i<=NF-5;i++){print $i}}' passwd root x bin x daemon x ``` 3. `while`循坏语句: ``` # awk -F: '{print "------------";i=1;while(i<=NF){print $i;i++}}' passwd ------------ root x 0 0 root /root /bin/bash ------------ bin x 1 1 bin /bin /sbin/nologin ------------ daemon x 2 2 daemon /sbin /sbin/nologin ``` 4. 循坏控制语句`break`: break只能用在循环语句中,作用是跳出当前循环,继续下一循环 ``` # echo -e "1 2 3 4 1\n5 6 7" | awk '{for(i=1;i<=NF;i++){if($i>=2){break}print $i}}' 1 ``` 5. 循环控制语句`continue`:如果遇到continue,continue后面的语句不再执行,继续下一个循环 ``` # echo -e "1 2 3 4 1\n5 6 7" | awk '{for(i=1;i<=NF;i++){if($i>=2){continue}print $i}}' 1 1 ``` 6. 循环控制语句`next`:遇到next,跳出循环,继续下移循环,在循环语句中next和break语句效果一样。区别在于,break和continue语句只能用于循环语句,next语句还可以用于其他语句,以下例子用于判断语句 ``` # echo -e "1 2 3 4 1\n5 6 7 1" | awk '{if($2<=2){next}print $0}' 5 6 7 1 ``` ``` # awk -F: 'NR==FNR{print NR,FILENAME,FNR;next}{print NR,FILENAME,FNR}' passwd shadow 1 passwd 1 2 passwd 2 3 passwd 3 4 shadow 1 5 shadow 2 6 shadow 3 ``` ## 七、AWK中数组的使用 1. 手动定义数组 ``` # echo '' | awk '{aa[1]=1;aa[2]=2;aa["b"]="b";print aa[1]}' 1 ``` 2. 读取文件 ``` # awk -F: '{for(i=1;i<=NF;i++){a[i]=$i;print a[1];break}}' passwd root bin daemon ``` ``` # cat c1 01 北京 02 上海 03 广州 04 深圳 # cat c2 01 beijing 02 shanghai 03 guangzhou 04 shenzhen # awk 'NR==FNR{a[$1]=$0}NR!=FNR{print a[$1],$2}' c1 c2 01 北京 beijing 02 上海 shanghai 03 广州 guangzhou 04 深圳 shenzhen ``` ## 八、AWK中常见函数的使用 1. `sub`和`gsub`函数:用来替换 ``` # cat test.txt tom bob mary tom bob tom mary tom # awk '{sub("tom","TOM");print}' test.txt TOM bob mary tom bob TOM mary tom ``` 但是只替换了每行的第一个,要想替换所有的,使用`gsub`函数: ``` # awk '{gsub("tom","TOM");print}' test.txt TOM bob mary TOM bob TOM mary TOM ``` 只替换最后一个: ``` # awk '{gsub("tom","TOM",$NF);print}' test.txt tom bob mary TOM bob tom mary TOM ``` 2. `length`函数用来计算字符串长度 ``` # awk -F: '{print $1,length($1)}' passwd root 4 bin 3 daemon 6 ``` 3. `substr`函数用来截取一段数据 ``` # awk -F: '{print substr($1,2)}' passwd oot in aemon # awk -F: '{print substr($1,2,2)}' passwd oo in ae ``` 4. `match`函数的使用,从字符串中匹配满足某种格式的位置 ``` # awk -F: '{xx=match($1,"oo");print xx}' passwd 2 0 0 ``` `match`中有两个变量,`RSTART`可以获取到`match`得到的值,`RLENGTH`表示的是`match`中满足格式的字符创的长度,一般会结合substr截取我们所需要的数据: ``` # awk -F: '{xx=match($1,"oo");print xx,RSTART,RLENGTH}' passwd 2 2 2 0 0 -1 0 0 -1 ``` 5. `split`函数的使用:split("原始字符串",数组名,<分隔符>) ``` # echo '' | awk '{split("2018-05-20",xx,"-");print xx[1],xx[2],xx[3]}' 2018 05 20 # awk '{split($0,xx,":");print xx[1]}' passwd root bin daemon ``` 6. `getline`函数可以让我们使用操作系统命令,也可以读取另一个文件内容 ``` # awk '{getline;print $0}' c1 02 上海 04 深圳 ``` 可以看到`getline`将本文件的下一行赋值给当前的`$0` ``` # awk '{getline xx;print $0,xx}' c1 01 北京 02 上海 03 广州 04 深圳 ``` 在这里将下一行的值赋值给了getline后的变量xx,并没有影响当前的`$0` `getline < file`:该用法读取file文件的一行赋值给当前的`$0` `getline xx < file`:该用法读取file文件的一行赋值给变量xx ``` # awk '{getline xx< "c2";print xx,$2}' c1 01 beijing 北京 02 shanghai 上海 03 guangzhou 广州 04 shenzhen 深圳 ``` ``` # echo '' | awk '{"date"|getline xx;print xx}' 2018年 05月 20日 星期日 19:57:04 CST # echo '' | awk '{while("ls /boot"|getline xx) print xx}' config-3.10.0-327.el7.x86_64 grub2 initramfs-0-rescue-ba7506401e184ceea617517542f6b7c7.img initramfs-3.10.0-327.el7.x86_64.img initrd-plymouth.img symvers-3.10.0-327.el7.x86_64.gz System.map-3.10.0-327.el7.x86_64 vmlinuz-0-rescue-ba7506401e184ceea617517542f6b7c7 vmlinuz-3.10.0-327.el7.x86_64 # echo '' | awk '{print "请输入:";getline name<"/dev/tty";print "你好:" name}' 请输入: tom 你好:tom ``` ## 九、AWK的格式化输出 1. `printf`不带换行符 ``` # awk -F: '{printf "%-8s|%-5d\n",$1,$3}' passwd root |0 bin |1 daemon |2 ``` 其中`%-8s`中的-8表示显示宽度为8个字符,`-`表示左对齐,`+`号表示右对齐 `%d`显示的整数 `%f`显示的是浮点数,`%10.5f`表示总共显示十位。小数点后显示5位 `%e`用科学计数法显示 ``` # echo '' | awk '{printf "%d\n",3*3.5}' 10 # echo '' | awk '{printf "%f\n",3*3.5}' 10.500000 # echo '' | awk '{printf "%-.10f\n",10/3}' 3.3333333333 # echo '' | awk '{printf "%e\n",3*3.5}' 1.050000e+01 ``` |
| json metadata | {"tags":["linux","awk"],"app":"steemit/0.1","format":"markdown"} |
| Transaction Info | Block #22595966/Trx 455bbc6a830cd07a9d098fe09afe04a835323343 |
View Raw JSON Data
{
"trx_id": "455bbc6a830cd07a9d098fe09afe04a835323343",
"block": 22595966,
"trx_in_block": 0,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-05-20T12:44:09",
"op": [
"comment",
{
"parent_author": "",
"parent_permlink": "linux",
"author": "pmliang",
"permlink": "awk",
"title": "AWK常见用法(一)",
"body": "## 一、初识AWK\n`AWK`有其他的衍生版本,比如`nawk`和`gawk`,在Linux发行版里,默认使用的是`gawk`:\n```\n# ls -l `which awk`\nlrwxrwxrwx. 1 root root 4 5月 9 20:25 /usr/bin/awk -> gawk\n```\n## 二、AWK的工作流程\n- `AWK`是按行处理文本,将行按照某一分隔符进行分割,其中分割之后的第一部分为`$1`,第二部分为`$2`,依次类推,其中`$0`表示整行,超过10的要将数字用括号括起来,比如`$(10)`\n- `AWK`默认的分隔符是空格和`tab`,其中操作命令必须写在{}里面,语法:\n```\nawk '/模式/{print $1}' file //模式支持正则表达式,只对含有该模式的行进行操作\n```\n- 可以使用`-F`选项指定分隔符:\n```\nawk -F: '/模式/{print $1}' file\n```\n\n## 三、常见操作符的使用(例子中passwd文件使用/etc/passwd文件的前6行)\n常见的操作符有:`~`、`!~`、`==`、`!=`、`>`、`<`、`++`、`--`等\n1. `~`和`!~`表示包含和不包含:\n```\n# awk -F: '$1~/ro/{print $0}' passwd \nroot:x:0:0:root:/root:/bin/bash\n```\n2. `==`和`!=`表示严格的等于和不等于:\n```\n# awk -F: '$3==1{print $0}' passwd \nbin:x:1:1:bin:/bin:/sbin/nologin\n```\n```\n# awk -F: '{$3++;print $3}' passwd \n1\n2\n3\n4\n5\n6\n```\n3. 其他的一些操作符同理,两个以上的条件需要使用连接符`&&`或`||`\n\n## 四、AWK中 BEGIN 和 NED 的用法\n\n1. `BEGIN`中的命令是在AWK读取文本的第一行之前进行操作:\n```\n# awk -F: 'BEGIN{print \"用户名\"}{print $1}' passwd \n用户名\nroot\nbin\ndaemon\nadm\nlp\nsync\n```\n2. `END`中的命令是在读取完最后一行之后进行的操作:\n```\n# awk -F: '{print $1}END{print \"结束\"}' passwd \nroot\nbin\ndaemon\nadm\nlp\nsync\n结束\n```\n3. BEGIN和END可以同时出现,也可以单独出现,BEGIN中可以定义变量:\n```\n# awk -F: 'BEGIN{a=1}{print a}' passwd \n1\n1\n1\n1\n1\n1\n```\n如何没有预先定义变量的话,在后面也是可以引用的,只不过这个变量的值为空。引用变量的时候不加`$`\n`END`中也可以进行最终的计算:\n```\n# awk -F: 'BEGIN{sum=0}{sum+=$3}END{print \"所有UID的和为:\"sum}' passwd \n所有UID的和为:15\n```\n或者不预先定义变量:\n```\n# awk -F: '{sum+=$3}END{print \"所有UID的和为:\"sum}' passwd \n所有UID的和为:15\n```\n\n## 五、AWK中常见内置变量的用法\n1. `FS`代表分隔符:\n```\n# awk 'BEGIN{FS=\":\"}{print $1}' passwd \nroot\nbin\ndaemon\nadm\nlp\nsync\n```\n2. `OFS`为打印输出的分隔符,默认的是空格:\n```\n# awk 'BEGIN{FS=\":\";OFS=\"---\"}{print $1,$2}' passwd \nroot---x\nbin---x\ndaemon---x\nadm---x\nlp---x\nsync---x\n```\n3. `NF`的值表示将每一行按照`FS`指定的分隔符分为多少段:\n```\n# awk 'BEGIN{FS=\":\"}{print NF}' passwd \n7\n7\n7\n7\n7\n7\n```\n如果要打印每一行的最后一段,可以使用以下用法:\n```\n# awk 'BEGIN{FS=\":\"}{print $NF}' passwd \n/bin/bash\n/sbin/nologin\n/sbin/nologin\n/sbin/nologin\n/sbin/nologin\n/bin/sync\n```\n4. 前面提到过,AWK是将文件按行进行处理,那么AWK是如何分别每一行的呢?使用的就是`RS`的值,默认为`\\n`:\n```\n# cat test.txt \n1,张三:经理 2,李四:职员 3,王五:老板\n# awk -F[:,] 'BEGIN{RS=\" \"}{print $2,$3}' test.txt \n张三 经理\n李四 职员\n王五 老板\n```\n5. `ORS`变量的值决定输出行的分隔符,默认的为`\\n`:\n```\n# awk 'BEGIN{ORS=\"---\"}{print $0}' passwd \nroot:x:0:0:root:/root:/bin/bash---bin:x:1:1:bin:/bin:/sbin/nologin---daemon:x:2:2:daemon:/sbin:/sbin/nologin---adm:x:3:4:adm:/var/adm:/sbin/nologin---lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin---sync:x:5:0:sync:/sbin:/bin/sync---\n```\n6. `FILENAME`变量的值为当前操作文件的文件名:\n```\n# awk -F: '{print FILENAME}' passwd \npasswd\npasswd\npasswd\npasswd\npasswd\npasswd\n```\n7. `NR`变量的值表示当前正在操作的行号:\n```\n# awk -F: '{print NR}' passwd \n1\n2\n3\n4\n5\n6\n```\n如果这里将行分隔符`RS`赋值为`-`,验证`NR`的值:\n```\n# awk 'BEGIN{RS=\"-\"}{print NR}' passwd \n1\n```\n8. `FNR`也表示当前操作的行号,不同的是,当对一个文件进行操作的时候`FNR`和`NR`的值是一样的。当对两个文件进行操作时,`FNR`和`NR`的值是不一样的:\n```\n# awk -F: '{print NR,$1,FNR}' passwd shadow \n1 root 1\n2 bin 2\n3 daemon 3\n4 adm 4\n5 lp 5\n6 sync 6\n7 root 1\n8 bin 2\n9 daemon 3\n10 adm 4\n11 lp 5\n12 sync 6\n```\n\n## 六、判断和循坏语句\n1. `if`语句:\n语法,如果语句没有使用{},则要使用;分隔\n```\nif(判断1){语句1}else if(判断2){语句2}else{语句3}\nif(判断1)语句1;else if(判断2)语句2;else语句3\n```\n\n```\n# awk -F: '{if($3==0){print $1\"是root\"}else if($3>=1000){print $1\"是普通用户\"}else{print $1\"是系统用户\"}}' passwd \nroot是root\nbin是系统用户\ndaemon是系统用户\nadm是系统用户\nlp是系统用户\nsync是系统用户\n```\n2. `for`循坏语句:\n```\nawk -F: '{for(i=1;i<=NF-5;i++){print $i}}' passwd \nroot\nx\nbin\nx\ndaemon\nx\n```\n3. `while`循坏语句:\n```\n# awk -F: '{print \"------------\";i=1;while(i<=NF){print $i;i++}}' passwd \n------------\nroot\nx\n0\n0\nroot\n/root\n/bin/bash\n------------\nbin\nx\n1\n1\nbin\n/bin\n/sbin/nologin\n------------\ndaemon\nx\n2\n2\ndaemon\n/sbin\n/sbin/nologin\n```\n4. 循坏控制语句`break`:\nbreak只能用在循环语句中,作用是跳出当前循环,继续下一循环\n```\n# echo -e \"1 2 3 4 1\\n5 6 7\" | awk '{for(i=1;i<=NF;i++){if($i>=2){break}print $i}}'\n1\n```\n5. 循环控制语句`continue`:如果遇到continue,continue后面的语句不再执行,继续下一个循环\n```\n# echo -e \"1 2 3 4 1\\n5 6 7\" | awk '{for(i=1;i<=NF;i++){if($i>=2){continue}print $i}}'\n1\n1\n```\n6. 循环控制语句`next`:遇到next,跳出循环,继续下移循环,在循环语句中next和break语句效果一样。区别在于,break和continue语句只能用于循环语句,next语句还可以用于其他语句,以下例子用于判断语句\n```\n# echo -e \"1 2 3 4 1\\n5 6 7 1\" | awk '{if($2<=2){next}print $0}'\n5 6 7 1\n```\n```\n# awk -F: 'NR==FNR{print NR,FILENAME,FNR;next}{print NR,FILENAME,FNR}' passwd shadow \n1 passwd 1\n2 passwd 2\n3 passwd 3\n4 shadow 1\n5 shadow 2\n6 shadow 3\n```\n\n## 七、AWK中数组的使用\n1. 手动定义数组\n```\n# echo '' | awk '{aa[1]=1;aa[2]=2;aa[\"b\"]=\"b\";print aa[1]}'\n1\n```\n2. 读取文件\n```\n# awk -F: '{for(i=1;i<=NF;i++){a[i]=$i;print a[1];break}}' passwd \nroot\nbin\ndaemon\n```\n\n```\n# cat c1\n01 北京\n02 上海\n03 广州\n04 深圳\n# cat c2\n01 beijing\n02 shanghai\n03 guangzhou\n04 shenzhen\n# awk 'NR==FNR{a[$1]=$0}NR!=FNR{print a[$1],$2}' c1 c2\n01 北京 beijing\n02 上海 shanghai\n03 广州 guangzhou\n04 深圳 shenzhen\n```\n\n## 八、AWK中常见函数的使用\n1. `sub`和`gsub`函数:用来替换\n```\n# cat test.txt \ntom bob mary tom\nbob tom mary tom\n# awk '{sub(\"tom\",\"TOM\");print}' test.txt \nTOM bob mary tom\nbob TOM mary tom\n```\n但是只替换了每行的第一个,要想替换所有的,使用`gsub`函数:\n```\n# awk '{gsub(\"tom\",\"TOM\");print}' test.txt \nTOM bob mary TOM\nbob TOM mary TOM\n```\n只替换最后一个:\n```\n# awk '{gsub(\"tom\",\"TOM\",$NF);print}' test.txt \ntom bob mary TOM\nbob tom mary TOM\n```\n2. `length`函数用来计算字符串长度\n```\n# awk -F: '{print $1,length($1)}' passwd \nroot 4\nbin 3\ndaemon 6\n```\n3. `substr`函数用来截取一段数据\n```\n# awk -F: '{print substr($1,2)}' passwd \noot\nin\naemon\n# awk -F: '{print substr($1,2,2)}' passwd \noo\nin\nae\n```\n4. `match`函数的使用,从字符串中匹配满足某种格式的位置\n```\n# awk -F: '{xx=match($1,\"oo\");print xx}' passwd \n2\n0\n0\n```\n`match`中有两个变量,`RSTART`可以获取到`match`得到的值,`RLENGTH`表示的是`match`中满足格式的字符创的长度,一般会结合substr截取我们所需要的数据:\n```\n# awk -F: '{xx=match($1,\"oo\");print xx,RSTART,RLENGTH}' passwd \n2 2 2\n0 0 -1\n0 0 -1\n```\n5. `split`函数的使用:split(\"原始字符串\",数组名,<分隔符>)\n```\n# echo '' | awk '{split(\"2018-05-20\",xx,\"-\");print xx[1],xx[2],xx[3]}'\n2018 05 20\n# awk '{split($0,xx,\":\");print xx[1]}' passwd \nroot\nbin\ndaemon\n```\n6. `getline`函数可以让我们使用操作系统命令,也可以读取另一个文件内容\n```\n# awk '{getline;print $0}' c1\n02 上海\n04 深圳\n```\n可以看到`getline`将本文件的下一行赋值给当前的`$0`\n```\n# awk '{getline xx;print $0,xx}' c1\n01 北京 02 上海\n03 广州 04 深圳\n```\n在这里将下一行的值赋值给了getline后的变量xx,并没有影响当前的`$0`\n\n`getline < file`:该用法读取file文件的一行赋值给当前的`$0`\n`getline xx < file`:该用法读取file文件的一行赋值给变量xx\n```\n# awk '{getline xx< \"c2\";print xx,$2}' c1\n01 beijing 北京\n02 shanghai 上海\n03 guangzhou 广州\n04 shenzhen 深圳\n```\n\n```\n# echo '' | awk '{\"date\"|getline xx;print xx}'\n2018年 05月 20日 星期日 19:57:04 CST\n# echo '' | awk '{while(\"ls /boot\"|getline xx) print xx}'\nconfig-3.10.0-327.el7.x86_64\ngrub2\ninitramfs-0-rescue-ba7506401e184ceea617517542f6b7c7.img\ninitramfs-3.10.0-327.el7.x86_64.img\ninitrd-plymouth.img\nsymvers-3.10.0-327.el7.x86_64.gz\nSystem.map-3.10.0-327.el7.x86_64\nvmlinuz-0-rescue-ba7506401e184ceea617517542f6b7c7\nvmlinuz-3.10.0-327.el7.x86_64\n\n# echo '' | awk '{print \"请输入:\";getline name<\"/dev/tty\";print \"你好:\" name}'\n请输入:\ntom\n你好:tom\n```\n\n## 九、AWK的格式化输出\n1. `printf`不带换行符\n```\n# awk -F: '{printf \"%-8s|%-5d\\n\",$1,$3}' passwd \nroot |0 \nbin |1 \ndaemon |2\n```\n其中`%-8s`中的-8表示显示宽度为8个字符,`-`表示左对齐,`+`号表示右对齐\n`%d`显示的整数\n`%f`显示的是浮点数,`%10.5f`表示总共显示十位。小数点后显示5位\n`%e`用科学计数法显示\n```\n# echo '' | awk '{printf \"%d\\n\",3*3.5}'\n10\n# echo '' | awk '{printf \"%f\\n\",3*3.5}'\n10.500000\n# echo '' | awk '{printf \"%-.10f\\n\",10/3}'\n3.3333333333\n# echo '' | awk '{printf \"%e\\n\",3*3.5}'\n1.050000e+01\n```",
"json_metadata": "{\"tags\":[\"linux\",\"awk\"],\"app\":\"steemit/0.1\",\"format\":\"markdown\"}"
}
]
}pmliangupvoted (100.00%) @cloudman6 / chart-kubernetes-512018/04/08 06:44:00
pmliangupvoted (100.00%) @cloudman6 / chart-kubernetes-51
2018/04/08 06:44:00
| voter | pmliang |
| author | cloudman6 |
| permlink | chart-kubernetes-51 |
| weight | 10000 (100.00%) |
| Transaction Info | Block #21380028/Trx d83a05b51891002acb044fbc7fa35127777c4d62 |
View Raw JSON Data
{
"trx_id": "d83a05b51891002acb044fbc7fa35127777c4d62",
"block": 21380028,
"trx_in_block": 29,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-04-08T06:44:00",
"op": [
"vote",
{
"voter": "pmliang",
"author": "cloudman6",
"permlink": "chart-kubernetes-51",
"weight": 10000
}
]
}pmliangupvoted (100.00%) @cloudman6 / helm-kubernetes-502018/04/08 06:34:33
pmliangupvoted (100.00%) @cloudman6 / helm-kubernetes-50
2018/04/08 06:34:33
| voter | pmliang |
| author | cloudman6 |
| permlink | helm-kubernetes-50 |
| weight | 10000 (100.00%) |
| Transaction Info | Block #21379839/Trx ace39ca47e62cd8da39f8a0a21eb1a7fd76c05d0 |
View Raw JSON Data
{
"trx_id": "ace39ca47e62cd8da39f8a0a21eb1a7fd76c05d0",
"block": 21379839,
"trx_in_block": 0,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-04-08T06:34:33",
"op": [
"vote",
{
"voter": "pmliang",
"author": "cloudman6",
"permlink": "helm-kubernetes-50",
"weight": 10000
}
]
}pmliangupvoted (100.00%) @cloudman6 / helm-kubernetes-482018/04/08 06:22:33
pmliangupvoted (100.00%) @cloudman6 / helm-kubernetes-48
2018/04/08 06:22:33
| voter | pmliang |
| author | cloudman6 |
| permlink | helm-kubernetes-48 |
| weight | 10000 (100.00%) |
| Transaction Info | Block #21379599/Trx 593a1ad43a3fc90940ca81b93da67dd32170ef4c |
View Raw JSON Data
{
"trx_id": "593a1ad43a3fc90940ca81b93da67dd32170ef4c",
"block": 21379599,
"trx_in_block": 36,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-04-08T06:22:33",
"op": [
"vote",
{
"voter": "pmliang",
"author": "cloudman6",
"permlink": "helm-kubernetes-48",
"weight": 10000
}
]
}2018/04/02 11:39:18
2018/04/02 11:39:18
| delegator | steem |
| delegatee | pmliang |
| vesting shares | 30389.310118 VESTS |
| Transaction Info | Block #21213155/Trx 1e3de90934912bbfcae8aa0c240864eb391535be |
View Raw JSON Data
{
"trx_id": "1e3de90934912bbfcae8aa0c240864eb391535be",
"block": 21213155,
"trx_in_block": 52,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-04-02T11:39:18",
"op": [
"delegate_vesting_shares",
{
"delegator": "steem",
"delegatee": "pmliang",
"vesting_shares": "30389.310118 VESTS"
}
]
}pmliangupvoted (100.00%) @chbartist / construyendo-el-camino-al-exito-capitulo-22018/04/02 09:43:36
pmliangupvoted (100.00%) @chbartist / construyendo-el-camino-al-exito-capitulo-2
2018/04/02 09:43:36
| voter | pmliang |
| author | chbartist |
| permlink | construyendo-el-camino-al-exito-capitulo-2 |
| weight | 10000 (100.00%) |
| Transaction Info | Block #21210841/Trx 2e27fa1a907ceae6c44e3528fb840b1d1bf1f12a |
View Raw JSON Data
{
"trx_id": "2e27fa1a907ceae6c44e3528fb840b1d1bf1f12a",
"block": 21210841,
"trx_in_block": 2,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-04-02T09:43:36",
"op": [
"vote",
{
"voter": "pmliang",
"author": "chbartist",
"permlink": "construyendo-el-camino-al-exito-capitulo-2",
"weight": 10000
}
]
}pmliangupvoted (100.00%) @cloudman6 / helm-kubernetes-492018/04/02 09:40:21
pmliangupvoted (100.00%) @cloudman6 / helm-kubernetes-49
2018/04/02 09:40:21
| voter | pmliang |
| author | cloudman6 |
| permlink | helm-kubernetes-49 |
| weight | 10000 (100.00%) |
| Transaction Info | Block #21210776/Trx c1f7b18e6bd66df732667f61bbc155951367d1e0 |
View Raw JSON Data
{
"trx_id": "c1f7b18e6bd66df732667f61bbc155951367d1e0",
"block": 21210776,
"trx_in_block": 19,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-04-02T09:40:21",
"op": [
"vote",
{
"voter": "pmliang",
"author": "cloudman6",
"permlink": "helm-kubernetes-49",
"weight": 10000
}
]
}2018/04/02 09:39:06
2018/04/02 09:39:06
| fee | 0.100 STEEM |
| delegation | 30690.000000 VESTS |
| creator | steem |
| new account name | pmliang |
| owner | {"weight_threshold":1,"account_auths":[],"key_auths":[["STM6ZzrmyJLMBDgYPL5HPNndbT1CJYPd2Beey7Aa3TFiPsrsNRtqS",1]]} |
| active | {"weight_threshold":1,"account_auths":[],"key_auths":[["STM6uQRsiZUTHmyrfP8R1ZxX8XuUdmpYBktZky74Si5MYq2ARS86V",1]]} |
| posting | {"weight_threshold":1,"account_auths":[],"key_auths":[["STM7xtH1TVHGoM7ycSbf5awcwH1aFuWdSE7b5k1MZUJhk1toWNCDX",1]]} |
| memo key | STM6Ghf4hVZcPgcwME28XHiSGvXYEF6Mdbrdu5Ji1kryuBdas2YWx |
| json metadata | {} |
| extensions | [] |
| Transaction Info | Block #21210751/Trx 253c4674dbf91b37991dd97d68733599e2f38a74 |
View Raw JSON Data
{
"trx_id": "253c4674dbf91b37991dd97d68733599e2f38a74",
"block": 21210751,
"trx_in_block": 22,
"op_in_trx": 0,
"virtual_op": 0,
"timestamp": "2018-04-02T09:39:06",
"op": [
"account_create_with_delegation",
{
"fee": "0.100 STEEM",
"delegation": "30690.000000 VESTS",
"creator": "steem",
"new_account_name": "pmliang",
"owner": {
"weight_threshold": 1,
"account_auths": [],
"key_auths": [
[
"STM6ZzrmyJLMBDgYPL5HPNndbT1CJYPd2Beey7Aa3TFiPsrsNRtqS",
1
]
]
},
"active": {
"weight_threshold": 1,
"account_auths": [],
"key_auths": [
[
"STM6uQRsiZUTHmyrfP8R1ZxX8XuUdmpYBktZky74Si5MYq2ARS86V",
1
]
]
},
"posting": {
"weight_threshold": 1,
"account_auths": [],
"key_auths": [
[
"STM7xtH1TVHGoM7ycSbf5awcwH1aFuWdSE7b5k1MZUJhk1toWNCDX",
1
]
]
},
"memo_key": "STM6Ghf4hVZcPgcwME28XHiSGvXYEF6Mdbrdu5Ji1kryuBdas2YWx",
"json_metadata": "{}",
"extensions": []
}
]
}Manabar
Voting Power100.00%
Downvote Power100.00%
Resource Credits100.00%
Reputation Progress0.00%
{
"voting_manabar": {
"current_mana": "8143659806",
"last_update_time": 1779080985
},
"downvote_manabar": {
"current_mana": 2035914951,
"last_update_time": 1779080985
},
"rc_account": {
"account": "pmliang",
"rc_manabar": {
"current_mana": "10164408779",
"last_update_time": 1779080985
},
"max_rc_creation_adjustment": {
"amount": "2020748973",
"precision": 6,
"nai": "@@000000037"
},
"max_rc": "10164408779"
}
}Account Metadata
| POSTING JSON METADATA | |
| None | |
| JSON METADATA | |
| None |
{
"posting_json_metadata": {},
"json_metadata": {}
}Auth Keys
Owner
Single Signature
Public Keys
STM6ZzrmyJLMBDgYPL5HPNndbT1CJYPd2Beey7Aa3TFiPsrsNRtqS1/1
Active
Single Signature
Public Keys
STM6uQRsiZUTHmyrfP8R1ZxX8XuUdmpYBktZky74Si5MYq2ARS86V1/1
Posting
Single Signature
Public Keys
STM7xtH1TVHGoM7ycSbf5awcwH1aFuWdSE7b5k1MZUJhk1toWNCDX1/1
Memo
STM6Ghf4hVZcPgcwME28XHiSGvXYEF6Mdbrdu5Ji1kryuBdas2YWx
{
"owner": {
"weight_threshold": 1,
"account_auths": [],
"key_auths": [
[
"STM6ZzrmyJLMBDgYPL5HPNndbT1CJYPd2Beey7Aa3TFiPsrsNRtqS",
1
]
]
},
"active": {
"weight_threshold": 1,
"account_auths": [],
"key_auths": [
[
"STM6uQRsiZUTHmyrfP8R1ZxX8XuUdmpYBktZky74Si5MYq2ARS86V",
1
]
]
},
"posting": {
"weight_threshold": 1,
"account_auths": [],
"key_auths": [
[
"STM7xtH1TVHGoM7ycSbf5awcwH1aFuWdSE7b5k1MZUJhk1toWNCDX",
1
]
]
},
"memo": "STM6Ghf4hVZcPgcwME28XHiSGvXYEF6Mdbrdu5Ji1kryuBdas2YWx"
}Witness Votes
0 / 30
No active witness votes.
[]