最近的这几个VirtualBox版本(6.1.4、6.1.6、6.1.8)比以前多了一些变化,主要体现在Guest Additions上。

在6.1.4、6.1.6的版本里,曾经遇到过虚拟机和宿主机(Guest and Host)之间不能共享粘贴板(Clipboard)的bug,以及Windows 7、Debian10的Guest机器无法全屏的Bug。

之前的解决方法是,在 VirtualBox官网上下载Virtualbox 6.1.2版本的Guest Additions ISO,挂载并且安装ISO镜像中的VBoxLinuxAdditions.run文件后,即可解决这些问题。

但在今天的6.1.8版本的Release Changelog中,提到已经解决了多个这样的Bug,于是试试运气,结果遇到这样的问题:

1
VboxClient: The parent session seems to be non-X11. Exiting...

这里分享我在Windows 10 Host,Debian 10.0 Guest上的解决方法:

先注销当前用户:

再在登录的时候选择X11选项:

即可解决。

0x00 前言

Rails 6.0 发布已经有一段时间了,之前没有什么项目可以练手,最近总算遇到可以使用Rails 6开发的场景了。Rails 6中新增了一些功能和特性,有一些内容官方文档里并没有写的很具体,所以在摸索的过程中也遇到了一些坑点。这里以一个新工程从头到尾的构建,来简单记录在Rails6中使用jQuery和Bootstrap的过程。希望能够给新来的同学做个参考。

编程和码字的水平有限,如有错漏敬请指教,也请多包涵!下面就开始吧。

0x01 环境准备

  • 操作系统: Debian 10 ( 4.19.0-8-amd64 )
  • Ruby版本: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
  • Rails版本: Rails 6.0.2.1
1
2
3
4
5
6
7
test@debian:~$uname -a
Linux debian 4.19.0-8-amd64 #1 SMP Debian 4.19.98-1 (2020-01-26) x86_64 GNU/Linux
test@debian:~$ruby -v
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
test@debian:~$rails -v
Rails 6.0.2.1

0x02 创建项目

这里新建一个项目“TestApp”,并在其中建立控制器“Test”和测试方法“test”:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
test@debian:~$rails new TestApp
create
create README.md
create Rakefile
create .ruby-version
create config.ru
create .gitignore
create Gemfile
...
├─ [email protected]
├─ [email protected]
└─ [email protected]
Done in 59.74s.
Webpacker successfully installed 🎉 🍰
test@debian:~/TestApp$rails g controller Test test --no-stylesheets
Running via Spring preloader in process 22413
create app/controllers/test_controller.rb
route get 'test/test'
invoke erb
create app/views/test
create app/views/test/test.html.erb
invoke test_unit
create test/controllers/test_controller_test.rb
invoke helper
create app/helpers/test_helper.rb
invoke test_unit
invoke assets
invoke scss
test@debian:~$

创建好之后,修改test页面,添加一个表单和按钮,用于稍后测试Bootstrap。(在执行创建控制器和方法的命令后,Rails已经为我们自动添加了到Test控制器test方法的路由,所以不需要我们再新增路由。)

app/views/test/test.html.erb 代码:

1
2
3
4
5
6
7
<h1>Test#test</h1>
<p>Find me in app/views/test/test.html.erb</p>

<form>
<input id="test" type="text"/>
<button id="test_btn">点我</button>
</form>

启动Rails服务,访问http://localhost:3000/test/test:

1
2
3
4
5
6
7
8
9
10
11
test@debian:~/TestApp$rails s
=> Booting Puma
=> Rails 6.0.2.1 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 4.3.1 (ruby 2.6.5-p114), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000
Use Ctrl-C to stop

此时应用已经创建成功。

0x03 添加jQuery和Bootstrap库

这里采用yarn作为Javascript包管理器。在TestApp目录中运行bin/yarn,如果出现以下内容,说明yarn没有安装:

1
2
3
test@debian:~/TestApp$bin/yarn
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install

安装方法在这里, 以当前使用的Debian 10为例,安装的方法是:

1
2
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

安装好yarn之后,就可以用yarn添加jQuery包和Bootstrap包:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
test@debian:~/TestApp$yarn add jquery 
yarn add v1.21.1
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > [email protected]" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^4.0.0".
[4/4] Building fresh packages...

success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
└─ [email protected]
info All dependencies
└─ [email protected]
Done in 9.98s.
test@debian:~/TestApp$yarn add bootstrap
yarn add v1.21.1
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > [email protected]" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^4.0.0".
warning " > [email protected]" has unmet peer dependency "popper.js@^1.16.0".
[4/4] Building fresh packages...

success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
└─ [email protected]
info All dependencies
└─ [email protected]
Done in 13.33s.

由于Bootstrap还需要基于popper.js,不装的话会报依赖错误,所以安装一下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
test@debian:~/TestApp$yarn add popper.js
yarn add v1.21.1
[1/4] Resolving packages...
warning [email protected]: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1
[2/4] Fetching packages...
info [email protected]: The platform "linux" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > [email protected]" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0".
warning "webpack-dev-server > [email protected]" has unmet peer dependency "webpack@^4.0.0".
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
└─ [email protected]
info All dependencies
└─ [email protected]
Done in 11.78s.

安装的执行结果:

因为众所周知的原因,网速慢的同学就尴尬了,这里可能要等很久,所以你需要选一个科学一点的方式。

此时查看TestApp/node_modules目录,所需的前端库已经添加好了:

1
2
3
4
5
6
7
test@debian:~/TestApp$ls node_modules/jquery/
AUTHORS.txt bower.json dist external LICENSE.txt package.json README.md src
test@debian:~/TestApp$ls node_modules/bootstrap/
dist js LICENSE package.json README.md scss
test@debian:~/TestApp$ls node_modules/popper.js/
dist index.d.ts index.js.flow package.json README.md src
test@debian:~/TestApp$

0x04 使用Bootstrap

跟Rails5有所不同的是,Rails6采用webpack打包的方式,把需要打包的资源统一放在一个文件里(Rails6之前是采用Gemfile的方式引入第三方库,再通过Asset Pipeline汇聚)。

于是在安装好所需的前端库之后,就需要在app/javascript/packs/application.js中先引用它:

以Bootstrap为例,在其中添加import 'bootstrap'引入语句:

与此同时还需要在application.scss中引入Bootstrap的CSS样式表:

app/assets/stylesheets/application.scss文件中添加@import "bootstrap/dist/css/bootstrap";


2020/05/28 Patch

纠个错,如果想要通过@import "bootstrap/dist/css/bootstrap";的方式引用bootstrap相关的CSS,需要把app/assets/stylesheets/application.css文件重命名为app/assets/stylesheets/application.scss
如果直接使用app/assets/stylesheets/application.css的话,那么采用如下方式来引用:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
* File: app/assets/stylesheets/application.css
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
* vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require bootstrap/dist/css/bootstrap
*= require_tree .
*= require_self
*/

Ending Patch


接着继续修改app/views/test/test.html.erb文件中的代码,添加相应的CSS类来测试Bootstrap是否已经引入成功:

1
2
3
4
5
6
7
8
9
<h1>Test#test</h1>
<p>Find me in app/views/test/test.html.erb</p>

<form>
<div class="form-group">
<input id="test" type="text" class="form-control"/>
<button id="test_btn" class="btn btn-success">点我</button>
</div>
</form>

启动应用,再次访问测试页面:

虽然界面有点丑,但是从渲染效果来看,Bootstrap已经成功引入了。

0x05 使用jQuery

继续修改app/javascript/packs/application.js,添加用于测试jQuery的代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.

require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")


// Uncomment to copy all static images under ../images to the output folder and reference
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
// or the `imagePath` JavaScript helper below.
//
// const images = require.context('../images', true)
// const imagePath = (name) => images(name, true)

import 'bootstrap'

$(document).on('turbolinks:load', function(){
$("#test_btn").click(function(){
alert($("#test").val());
});
});

保存并运行,刷新https://localhost:3000/test/test页面,发现添加的代码无法执行,控制台中有报错:

1
2
ReferenceError: $ is not defined 
application.js:21

这是因为jQuery库也需要引入一下,但是引入的方式有些不同,并不是在页面中直接引入,而是需要在config/webpack/environment.js中添加以下引入代码:

1
2
3
4
5
6
var webpack = require('webpack');
environment.plugins.append( 'Provide',
new webpack.ProvidePlugin({
$: 'jquery',
})
)

通过声明一个全局的导出,就可以在全局的JS代码文件中使用”$”符号了。

刷新并再次访问,代码能够运行,控制台也没有再报错,说明jQuery已经成功集成:

另一种方法

还有一种方法是通过在JS文件按中使用import $ from 'jquery'来使”$”符生效,但是这样比较繁琐,需要在每个JS文件中出现,所以不再介绍了,当然,也提供一下详细的代码参考

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.

require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")


// Uncomment to copy all static images under ../images to the output folder and reference
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
// or the `imagePath` JavaScript helper below.
//
// const images = require.context('../images', true)
// const imagePath = (name) => images(name, true)

import 'bootstrap'
import $ from 'jquery' // 在每个JS文件中加上这一行,也可以替代声明全局变量。

$(document).on('turbolinks:load', function(){
$("#test_btn").click(function(){
alert($("#test").val());
});
});

0x06 总结

在网上主要参考了这篇文章。Rails 6中的变化还是挺大的,不知道webpack会不会真的成为Rails的未来,感觉之前使用coffee script来写JS的同学不是很多,但是我倒是已经非常习惯于使用它来开发前端功能了。

但是想必Rails的先驱们有着他们更成熟的考虑吧,那就一起继续探索好了。

物物而不物于物,则胡可得而累邪!

《庄子·外篇·山木第二十》

庚子年这倒霉病毒的事儿,就不多言了。受此影响,正月里,神州大地的人民,都在家中宅着,用最简单的方式为祖国做着贡献。我自然也不例外,只不过我是个闲不下来的人。虽然平日里我就比较宅,但是按照计划,正月我至少也是要走动走动的。其实若是完全依我自己,我肯定宁愿在家宅着,毕竟守寂淡泊才是我的志趣所在,走亲访友这根本不是我的爱好。只是要考虑家人感受,所以不得不应付罢了。

在家我自然也不会闲着,一早就想要做的事情就是把自己的东西好好整理整理,苦于一直没有时间和思路。这次正好,有了新的思路,也正好有时间,于是在这里谈谈后续的收纳计划。

首先是为什么要收纳。原因很简单,一是家中置物空间有限,不得不收纳。二是,人要时常给自己减轻物质方面的负担,所以要时常扔东西,卖二手,或者是收纳。

我的杂物是很多的,大到健身设备,家电、小家具,小到二极管、电容这些零碎的电子元器件,所以收纳起来相当费事。而我又是一个比较极简和有强迫症的人,所以这就形成了非常鲜明的矛盾。对于不想看到的东西,我的原则就是甩锅。能扔的扔,不能扔的,父母今年正好开着小货车来我这里过年,于是把那些大件的杂物一股脑全让他们拖回到农村老家,老家的地下室、后院,尽可以随便放置,眼不见,则心不烦。但是很多的小物件,就得一一归纳,汇总打包了。

于是我问自己,有什么东西,是十年之内用不到,但又是我不想扔的。

这样一来,就清楚多了。这批物品中,包括到期的保险单、人生的第一枚鼠标,积攒的用来制作特斯拉线圈的铜线,还有用来制作电磁炮的铝管、智能小车上的18650电池组、嵌入式开发板。也许未来十年,我不会有时间去完成那些小制作和小梦想了,但是未来的某一天,希望我有时间,可以再拾起它们。对这些物品,我需要准备打包盒将他们封印,放在一个看不见的地方,等待下一次搬家。

当初在收集和购买它们的时候,对自己的时间,是有着满满的自信的。以为可以无忧无虑,废寝忘食地投入在爱好当中。而现实是,自己既没有无忧无虑的资格,又没有经得住废寝忘食的身体。普通人的精力是有限的,最近几年深深地意识到这一点,于是把自己的领域逐渐收窄,想必,这辈子大部分工作的时间和精力,会扑在软件和互联网领域了,这是我选择的方向。

庄子说,物物而不物于物。我的内心有着太多的物,却不能够物之,这是非常不应该的,也是我心累之根源。

相信在之后不久的日子里,我就要与这些杂物短暂地告别了,就让我将他们尘封在时光机里,在未来的某一个时候再见吧。

身外的杂物,终究是容易收拾的,而心里的杂念,整理还需要时间。什么时候,待我不再物于物,想必才能真的理解庄子。

最近有不少好剧,有时候网速不好追剧太累了,而且有的有广告。看了一下几个主流的视频网站,有不少都还是用的标准的hls协议,没有在此基础上做修改(所以容易导致影视资源泄漏)。用标准hls协议的好处就是我们可以基于hls协议很方便地将影视资源多线程快速下载到本地,既可以流畅观看又可以去广告(部分)。

于是写了一个多线程的m3u8的文件下载器,基于python3纯原生库,安全放心:

代码链接:

https://github.com/Chorder/m3u8_downloader

顺便说一句,m3u8文件挺有意思的,结合ffmepg的缺陷,曾经爆出过播放器任意文件读取漏洞 https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-1897 ,但是亲测在浏览器中m3u8文件其实还有更多妙用。感兴趣的童鞋可以进一步玩耍一下。

在PostgresSQL中如果尝试删除一个用户,可能会遇到这个报错:

1
2
ERROR:  role "XXX" cannot be dropped because some objects depend on it
DETAIL: privileges for table YYY

这是因为没有撤销该用户的权限所导致的。

具体以一个例子来说明。创建一张叫做“xxx”的表,再创建一个“test”用户,并将这张表的所有权限赋予“test”用户。

直接尝试删除这个用户,就会出现这个权限提示。

1
2
3
4
5
6
7
8
9
root=# CREATE TABLE xxx ( id SERIAL PRIMARY KEY , name CHAR(15) NOT NULL );
CREATE TABLE
root=# CREATE USER test PASSWORD 'test';
CREATE ROLE
root=# GRANT ALL ON xxx TO test;
GRANT
root=# DROP USER test;
ERROR: role "test" cannot be dropped because some objects depend on it
DETAIL: privileges for table xxx

可以通过下面这条语句查询PG中“test”用户的权限,并根据查询到的结果撤销之。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
root=# SELECT * FROM information_schema.table_privileges WHERE grantee='test';
grantor | grantee | table_catalog | table_schema | table_name | privilege_type | is_grantable | with_hierarchy
---------+---------+---------------+--------------+------------+----------------+--------------+----------------
root | test | root | public | xxx | INSERT | NO | NO
root | test | root | public | xxx | SELECT | NO | YES
root | test | root | public | xxx | UPDATE | NO | NO
root | test | root | public | xxx | DELETE | NO | NO
root | test | root | public | xxx | TRUNCATE | NO | NO
root | test | root | public | xxx | REFERENCES | NO | NO
root | test | root | public | xxx | TRIGGER | NO | NO
(7 rows)

root=# REVOKE ALL ON xxx FROM test;
REVOKE
root=# DROP USER test;
DROP ROLE
root=#

批量撤销用户在数据库中所有表的权限:

1
2
revoke all on database XX from test;
revoke all on all tables in schema public from test;

PG权限的基本操作

赋予权限的语句是

1
GRANT *privilege ON *obj TO *user

撤销权限的语句从语法上与之对应:

1
REVOKE *privilege ON *obj FROM *user
  • privilege − SELECT,INSERT,UPDATE,DELETE, RULE,ALL
  • obj − 要授予访问权限的对象名称,可以是 table, view,sequence
  • user可以是以下情况
    • PUBLIC − 所有用户
    • GROUP group − 用户组
    • username − 用户名 (PUBLIC 是代表所有用户的简短形式)

删除用户:

查看用户权限:

2019很快就要过去了,这一年似乎做了很多事,又似乎只做了一件事。

回顾这过去的一年,和过去的很多年,生活悄然发生着变化。

这些年过得并无什么遗憾,此时谈遗憾还为时甚早。生活偶尔让人一时兴起,似是来者可追。

心头最大的怀念是关于过去的时光,很多人相聚又离开,奔走为了生存。

如果可以,我希望能辟一方寒舍,偶尔能把这些家伙们聚在一起,灌几口老酒,寒暄中宽慰过往。

然而岁月不曾等待谁,故事总有结尾,尘埃终将落定。

就像今年,有些人的终身大事定了,有人不再同我来往,有人觉得自己老了,有人升官发财。

我想做一棵守在原点的大树,却无法不在风里晃荡枝桠,无奈又极端,命运的使然。

有了愿意靠在这棵树上的人,为了让她靠得更稳,就需要再向土里埋入长长的根。

平平淡淡,浮浮沉沉,一蓑烟雨,一湾江湖。

在每个沉默的白天,每个雨落的深夜,心头点点,汇在一起,便是如此。

SSH远程转发存在常见的三种使用方法,分别是-D/-L/-R。

-D

-D是动态转发,用例为

ssh root@REMOTE_HOST -D 8080

启用时会在SSH Client侧监听一个本地端口8080,在浏览器中配置该端口作为代理,SSH Client会将浏览器中的流量转发到SSH Server侧进行发出。

-L

-L俗称本地转发,用例为

ssh root@REMOTE_HOST -L FromPort:DestHost:DestPort

启用时,SSH Client侧会在本地监听FromPort端口,同时将流量转发到DestHost的DestPort端口。
此时的DestHost是相对于SSH Server侧REMOTE_HOST这台远程主机而言的目的主机。

-R

-R称之为远程转发,用例为

ssh root@REMOTE_HOST -R FromPort:DestHost:DestPort

启用时,SSH Server侧会监听FromPort端口,并将该端口的流量转发到SSH Client这边的DestHost主机的DestPort端口,实现从远程到本地的转发。此时的DestHost是相对于SSH Client侧的本地主机而言的目的主机。

准备工作

主机安装SSH服务,并开启证书登录。然后运行ssh-keygen命令,在 ~/.ssh/ 目录中生成 id_rsaid_rsa.pub 文件,并将id_rsa.pub内容拷贝到 ~/.ssh/authorized_key 中(如果没有就新建该文件),目的是能够开启主机到自身的ssh证书登录。

hadoop-3.1.2.tar.gzjdk-8u231-linux-x64.tar.gz拷贝到服务器中并解压,例如 /data/ 目录。

1
2
3
4
5
6
7
[root@localhost data]# ls jdk1.8.0_231/ 
bin include jre LICENSE README.html src.zip THIRDPARTYLICENSEREADME.txt
COPYRIGHT javafx-src.zip lib man release THIRDPARTYLICENSEREADME-JAVAFX.txt
[root@localhost data]# ls jdk1.8.0_231/
bin include jre LICENSE README.html src.zip THIRDPARTYLICENSEREADME.txt
COPYRIGHT javafx-src.zip lib man release THIRDPARTYLICENSEREADME-JAVAFX.txt
[root@localhost data]#

环境配置

  1. 编辑 /etc/profile 文件,在末尾追加以下环境信息:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
####大数据测试环境配置

# 全局路径
WORK_DIR=/data

# Java
export JAVA_HOME=$WORK_DIR/jdk1.8.0_231
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib

# Hadoop
export HADOOP_HOME=$WORK_DIR/hadoop-3.1.2
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib"

# Export PATH
export PATH=.:${JAVA_HOME}/bin:${HADOOP_HOME}/bin:$PATH
  1. 创建hadoop文件目录
1
2
3
4
5
6
mkdir  /data/hadoop  
mkdir /data/hadoop/tmp
mkdir /data/hadoop/var
mkdir /data/hadoop/dfs
mkdir /data/hadoop/dfs/name
mkdir /data/hadoop/dfs/data
  1. 编辑 hadoop-3.1.2/etc/hadoop/core-site.xml 文件,在 configuration 节中增加以下内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
<configuration>

<property>
<name>hadoop.tmp.dir</name>
<value>/data/hadoop/tmp</value>
<description>Abase for other temporary directories.</description>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
</property>

</configuration>
  1. 编辑 hadoop-3.1.2/etc/hadoop/hdfs-site.xml 文件,在 configuration 节中增加以下内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<configuration>

<property>
<name>dfs.name.dir</name>
<value>/data/hadoop/dfs/name</value>
<description>Path on the local filesystem where theNameNode stores the namespace and transactions logs persistently.</description>
</property>
<property>
<name>dfs.data.dir</name>
<value>/data/hadoop/dfs/data</value>
<description>Comma separated list of paths on the localfilesystem of a DataNode where it should store its blocks.</description>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<property>
<name>dfs.permissions</name>
<value>false</value>
<description>need not permissions</description>
</property>


</configuration>
  1. 编辑 hadoop-3.1.2/etc/hadoop/mapred-site.xml 文件,在 configuration 节中增加以下内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<configuration>

<property>
<name>mapred.job.tracker</name>
<value>localhost:9001</value>
</property>
<property>
<name>mapred.local.dir</name>
<value>/data/hadoop/var</value>
</property>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>

</configuration>

  1. 编辑 hadoop-3.1.2/etc/hadoop/hadoop-env.sh 文件,将其中 JAVA_HOME 路径改为以下内容:
1
export JAVA_HOME=/data/jdk1.8.0_231

额外选项

可能会遇到报错,抛出以下报错信息:

1
2
ERROR: Attempting to operate on hdfs namenode as root
ERROR: but there is no HDFS_NAMENODE_USER defined. Aborting operation.

解决办法:

修改 hadoop-3.1.2/sbin/start-dfs.shhadoop-3.1.2/sbin/stop-dfs.sh 文件,在脚本开始处添加以下内容:

1
2
3
4
HDFS_DATANODE_USER=root
HADOOP_SECURE_DN_USER=hdfs
HDFS_NAMENODE_USER=root
HDFS_SECONDARYNAMENODE_USER=root

修改 hadoop-3.1.2/sbin/start-yarn.shhadoop-3.1.2/sbin/stop-yarn.sh 文件,在脚本开始处添加以下内容:

1
2
3
YARN_RESOURCEMANAGER_USER=root
HADOOP_SECURE_DN_USER=yarn
YARN_NODEMANAGER_USER=root

运行

首先载入/etc/profile文件中的配置:

1
source /etc/profile

然后初始化hadoop namenode:

1
hadoop  namenode  -format

启动dfs:

1
/data/hadoop-3.1.2/sbin/start-dfs.sh

启动yarn:

1
/data/hadoop-3.1.2/sbin/start-yarn.sh

查看运行情况:

HADOOP_HOST是你的环境IP。

访问 http://HADOOP_HOST:8088/

访问 http://HADOOP_HOST:9870/

先介绍一下:

XVA是Citrix XenServer导出的虚拟机格式镜像

OVA是Virtualbox常见的开放虚拟映像

RAW是纯粹的磁盘映像文件

在多个虚拟化平台之间进行镜像转换时,思路是先将特定平台镜像转换成中间映像(RAW),再转换成目标平台的虚拟化格式。

从Citrix XenServer XVA文件转Virtualbox格式时,先将xva转换成raw,运行:

1
qemu-img convert -O raw target.xva output.raw

qemu-img包含在Debian系的qemu-utils软件包中,如果没有,安装即可:

1
apt-get install qemu-utils

转换完成后,得到output.raw,再使用Virtualbox的VBoxManage将raw转换成VHD,就可以在Virtualbox使用了(似乎也可以在Vmware中使用)。

1
2
"c:Program Files\Oracle\VirtualBox\VBoxManage.exe" convertfromraw output.raw output.vhd --format VHD

参考自:

https://bart.jakubowski.in/2013/10/21/xva-to-vhd/

XenServer默认是没有ISO镜像目录的,如果需要创建自定义镜像的虚拟机,需要先创建ISO光盘映像目录,再导入镜像。方法如下:

首先登录XenServer,运行如下命令,在/var/目录下创建存放ISO的目录(也可自定义成其他目录),使用xe命令创建镜像分区。

1
2
3
mkdir -p /var/iso_import

xe sr-create name-label=ISO type=iso device-config:location=/var/iso_import/ device-config:legacy_mode=true content-type=iso

后面只需要将镜像iso文件导入/var/iso_import目录中,在XenServer可视化控制台中刷新(rescan)即可看到镜像。创建虚拟机时即可从自定义的镜像启动。

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×