DBUS发送接收数据(上)

1、Server端
testdbus_s.c

#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/dbus.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

/**
 * Wait for signals on the bus and reply
 */
void receive()
{
  DBusMessage* msg;
  DBusMessageIter args;
  DBusConnection* conn;
  DBusError err;
  int ret;
  char* sigvalue;
  int loop=1;

  printf("Listening for signals\n");

  // initialise the errors
  dbus_error_init(&err);
  
  // connect to the bus and check for errors
  conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
  if (dbus_error_is_set(&err)) { 
     fprintf(stderr, "Connection Error (%s)\n", err.message);
     dbus_error_free(&err); 
  }
  if (NULL == conn) { 
     exit(1);
  }
  
  // request our name on the bus and check for errors
  ret = dbus_bus_request_name(conn, "neohope.dbus.signal.target", DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
  if (dbus_error_is_set(&err)) { 
     fprintf(stderr, "Name Error (%s)\n", err.message);
     dbus_error_free(&err); 
  }
  if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
     exit(1);
  }

  // add a rule for which messages we want to see
  dbus_bus_add_match(conn, "type='signal',interface='neohope.dbus.signal.Type'", &err); // see signals from the given interface
  dbus_connection_flush(conn);
  if (dbus_error_is_set(&err)) { 
     fprintf(stderr, "Match Error (%s)\n", err.message);
     exit(1); 
  }
  printf("Match rule sent\n");

  // loop listening for signals being emmitted
  while (loop) {

     // non blocking read of the next available message
     dbus_connection_read_write(conn, 0);
     msg = dbus_connection_pop_message(conn);

     // loop again if we haven't read a message
     if (NULL == msg) { 
        sleep(1);
        continue;
     }

     // check if the message is a signal from the correct interface and with the correct name
     if (dbus_message_is_signal(msg, "neohope.dbus.signal.Type", "TestSignal")) {
        
        // read the parameters
        if (!dbus_message_iter_init(msg, &args))
           fprintf(stderr, "Message Has No Parameters\n");
        else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
           fprintf(stderr, "Argument is not string!\n"); 
        else
           dbus_message_iter_get_basic(&args, &sigvalue);
        
        if(strcmp("Bye",sigvalue)==0) {
           loop = 0;
           printf("Bye......\n");
        }
        else {
          printf("Got Signal with value: %s\n", sigvalue);
        }
     }

     // free the message
     dbus_message_unref(msg);
  }
  // do not close the connection
  // dbus_connection_close(conn);
}

/**
 * Deal with remote method call 
 */
int reply_to_method_call(DBusMessage* msg, DBusConnection* conn)
{
  DBusMessage* reply;
  DBusMessageIter args;
  int stat = 1;
  int ret = 1;
  dbus_uint32_t level = 21614;
  dbus_uint32_t serial = 0;
  char* param = "";

  // read the arguments
  if (!dbus_message_iter_init(msg, &args))
     fprintf(stderr, "Message has no arguments!\n"); 
  else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) 
     fprintf(stderr, "Argument is not string!\n"); 
  else 
     dbus_message_iter_get_basic(&args, &param);

  if(strcmp("Bye",param)==0){
    ret = 0;
    printf ("Bye......\n");
  }
  else {
    printf("Method Invoked with value: %s\n", sigvalue);
  }

  // create a reply from the message
  reply = dbus_message_new_method_return(msg);

  // add the arguments to the reply
  dbus_message_iter_init_append(reply, &args);
  if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_BOOLEAN, &stat)) { 
     fprintf(stderr, "Out Of Memory!\n"); 
     exit(1);
  }
  if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_UINT32, &level)) { 
     fprintf(stderr, "Out Of Memory!\n"); 
     exit(1);
  }

  // send the reply && flush the connection
  if (!dbus_connection_send(conn, reply, &serial)) {
     fprintf(stderr, "Out Of Memory!\n"); 
     exit(1);
  }
  dbus_connection_flush(conn);

  // free the reply
  dbus_message_unref(reply);
  
  return ret;
}

/**
 * Server that exposes a method call and waits for it to be called
 */
void listen() 
{
  DBusMessage* msg;
  DBusMessage* reply;
  DBusMessageIter args;
  DBusConnection* conn;
  DBusError err;
  int loop = 1;
  int ret;
  char* param;

  printf("Listening for method calls\n");

  // initialise the error
  dbus_error_init(&err);
  
  // connect to the bus and check for errors
  conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
  if (dbus_error_is_set(&err)) { 
     fprintf(stderr, "Connection Error (%s)\n", err.message); 
     dbus_error_free(&err); 
  }
  if (NULL == conn) {
     fprintf(stderr, "Connection Null\n"); 
     exit(1); 
  }
  
  // request our name on the bus and check for errors
  ret = dbus_bus_request_name(conn, "neohope.dbus.method.provider", DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
  if (dbus_error_is_set(&err)) { 
     fprintf(stderr, "Name Error (%s)\n", err.message); 
     dbus_error_free(&err);
  }
  if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) { 
     fprintf(stderr, "Not Primary Owner (%d)\n", ret);
     exit(1); 
  }

  // loop, testing for new messages
  while (loop) {
     // non blocking read of the next available message
     dbus_connection_read_write(conn, 0);
     msg = dbus_connection_pop_message(conn);

     // loop again if we haven't got a message
     if (NULL == msg) { 
        sleep(1); 
        continue; 
     }
     
     // check this is a method call for the right interface & method
     if (dbus_message_is_method_call(msg, "neohope.dbus.method.Type", "TestMethod")) 
        loop = reply_to_method_call(msg, conn);

     // free the message
     dbus_message_unref(msg);
  }

  // do not close the connection
  // dbus_connection_close(conn);
}

int main(int argc, char** argv)
{
  if (2 > argc) {
     printf ("Syntax: testdbus_s [receive|listen] [<param>]\n");
     return 1;
  }
  char* param = "no param";
  if (3 >= argc && NULL != argv[2]) param = argv[2];

  if (0 == strcmp(argv[1], "receive"))
     receive();
  else if (0 == strcmp(argv[1], "listen"))
     listen();
  else {
     printf ("Syntax: testdbus_s [receive|listen] [<param>]\n");
     return 1;
  }
  return 0;
}

2、Client端
testdbus_c.c

#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/dbus.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

/**
 * Connect to the DBUS bus and send a broadcast signal
 */
void sendsignal(char* sigvalue)
{
  DBusMessage* msg;
  DBusMessageIter args;
  DBusConnection* conn;
  DBusError err;
  int ret;
  dbus_uint32_t serial = 0;

  printf("Sending signal with value: %s\n", sigvalue);

  // initialise the error value
  dbus_error_init(&err);

  // connect to the DBUS system bus, and check for errors
  conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
  if (dbus_error_is_set(&err)) { 
     fprintf(stderr, "Connection Error (%s)\n", err.message); 
     dbus_error_free(&err); 
  }
  if (NULL == conn) { 
     exit(1); 
  }

  // register our name on the bus, and check for errors
  ret = dbus_bus_request_name(conn, "neohope.dbus.signal.source", DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
  if (dbus_error_is_set(&err)) { 
     fprintf(stderr, "Name Error (%s)\n", err.message); 
     dbus_error_free(&err); 
  }
  if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) { 
     exit(1);
  }

  // create a signal & check for errors 
  msg = dbus_message_new_signal("/neohope/dbus/signal/Object", // object name of the signal
                                "neohope.dbus.signal.Type", // interface name of the signal
                                "TestSignal"); // name of the signal
  if (NULL == msg) 
  { 
     fprintf(stderr, "Message Null\n"); 
     exit(1); 
  }

  // append arguments onto signal
  dbus_message_iter_init_append(msg, &args);
  if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &sigvalue)) {
     fprintf(stderr, "Out Of Memory!\n"); 
     exit(1);
  }

  // send the message and flush the connection
  if (!dbus_connection_send(conn, msg, &serial)) {
     fprintf(stderr, "Out Of Memory!\n"); 
     exit(1);
  }
  dbus_connection_flush(conn);
  
  printf("Signal Sent\n");
  
  // free the message
  dbus_message_unref(msg);
  // do not close the connection
  // dbus_connection_close(conn);
}

/**
 * Call a method on a remote object
 */
void query(char* param) 
{
  DBusMessage* msg;
  DBusMessageIter args;
  DBusConnection* conn;
  DBusError err;
  DBusPendingCall* pending;
  int ret;
  int stat;
  dbus_uint32_t level;

  printf("Calling remote method with %s\n", param);

  // initialiset the errors
  dbus_error_init(&err);

  // connect to the system bus and check for errors
  conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
  if (dbus_error_is_set(&err)) { 
     fprintf(stderr, "Connection Error (%s)\n", err.message); 
     dbus_error_free(&err);
  }
  if (NULL == conn) { 
     exit(1); 
  }

  // request our name on the bus
  ret = dbus_bus_request_name(conn, "neohope.dbus.method.caller", DBUS_NAME_FLAG_REPLACE_EXISTING , &err);
  if (dbus_error_is_set(&err)) { 
     fprintf(stderr, "Name Error (%s)\n", err.message); 
     dbus_error_free(&err);
  }
  if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) { 
     exit(1);
  }

  // create a new method call and check for errors
  msg = dbus_message_new_method_call("neohope.dbus.method.provider", // target for the method call
                                     "/neohope/dbus/method/Object", // object to call on
                                     "neohope.dbus.method.Type", // interface to call on
                                     "TestMethod"); // method name
  if (NULL == msg) { 
     fprintf(stderr, "Message Null\n");
     exit(1);
  }

  // append arguments
  dbus_message_iter_init_append(msg, &args);
  if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &param)) {
     fprintf(stderr, "Out Of Memory!\n"); 
     exit(1);
  }
  
  // send message and get a handle for a reply
  if (!dbus_connection_send_with_reply (conn, msg, &pending, -1)) { // -1 is default timeout
     fprintf(stderr, "Out Of Memory!\n"); 
     exit(1);
  }
  if (NULL == pending) { 
     fprintf(stderr, "Pending Call Null\n"); 
     exit(1); 
  }
  dbus_connection_flush(conn);
  
  printf("Request Sent\n");
  
  // free message
  dbus_message_unref(msg);
  
  // block until we recieve a reply
  dbus_pending_call_block(pending);

  // get the reply message
  msg = dbus_pending_call_steal_reply(pending);
  if (NULL == msg) {
     fprintf(stderr, "Reply Null\n"); 
     exit(1); 
  }
  // free the pending message handle
  dbus_pending_call_unref(pending);

  // read the parameters
  if (!dbus_message_iter_init(msg, &args))
     fprintf(stderr, "Message has no arguments!\n"); 
  else if (DBUS_TYPE_BOOLEAN != dbus_message_iter_get_arg_type(&args)) 
     fprintf(stderr, "Argument is not boolean!\n"); 
  else
     dbus_message_iter_get_basic(&args, &stat);

  if (!dbus_message_iter_next(&args))
     fprintf(stderr, "Message has too few arguments!\n"); 
  else if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&args)) 
     fprintf(stderr, "Argument is not int!\n"); 
  else
     dbus_message_iter_get_basic(&args, &level);

  printf("Got Reply: %d, %d\n", stat, level);
  
  // free reply and close connection
  dbus_message_unref(msg);   
  //dbus_connection_close(conn);
}

int main(int argc, char** argv)
{
  if (2 > argc) {
     printf ("Syntax: testdbus_c [send|query] [<param>]\n");
     return 1;
  }
  char* param = "no param";
  if (3 >= argc && NULL != argv[2]) param = argv[2];

  if (0 == strcmp(argv[1], "send"))
     sendsignal(param);
  else if (0 == strcmp(argv[1], "query"))
     query(param);
  else {
     printf ("Syntax: testdbus_c [send|query] [<param>]\n");
     return 1;
  }
  return 0;
}

3、Makefile

CC=gcc
LDFLAGS+=-ldbus-1
CFLAGS+=-I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include/

all:testdbus_c.bin testdbus_s.bin

testdbus_c.bin:testdbus_c.o
	$(CC) $(LDFLAGS) -o testdbus_c.bin testdbus_c.o 

testdbus_c.o:testdbus_c.c
	$(CC) $(CFLAGS) -c -o testdbus_c.o testdbus_c.c 

testdbus_s.bin:testdbus_s.o
	$(CC) $(LDFLAGS) -o testdbus_s.bin testdbus_s.o 

testdbus_s.o:testdbus_s.c
	$(CC) $(CFLAGS) -c -o testdbus_s.o testdbus_s.c 

clean:
	rm *.o *.bin

4、编译

make

CMD常用命令17常用软件注册为Widows服务

1、Apache注册为Widows服务

httpd -k install

2、MySQL注册为Widows服务

mysqld --install MySQL --defaults-file="D:\MySQL\MySQL Server 5.1\my.ini"

3、PostgreSQL注册为Widows服务

pg_ctl.exe register -N "postgresql-8.4" -D "D:/PostgreSQL/8.4/data" -w

4、SVN注册为Widows服务

sc create svnserve binPath= "\"D:\Subversion\bin\svnserve.exe\" --service -r \"D:\Subversion\repository\"" displayname= "Subversion Service" depend= Tcpip start= auto 
sc start svnserve 
sc stop svnserve 
sc delete svnserve

5、redis注册为Widows服务

#loglevel 分为debug, notice, warning三级
redis-server.exe --service-install D:\Database\Redis2.8\db\redis.windows.conf --loglevel notice
redis-server --service-start
redis-server --service-stop
redis-server --service-uninstall

6、mongodb注册为Widows服务

mongod --dbpath=D:\Database\MongoDB3\db --logpath=D:\Database\MongoDB3\log\mongo.log --port 27027 --noauth --install -serviceName MongoDB01 --serviceDisplayName MongoDB01 
net start MongoDB01

FreeBSD10安装开发环境

1、安装JDK
1.1、Oracle没有为FreeBSD提供JDK环境,自带版本也挺高,那就安装默认的咯

pkg install jdk8

*在windows下编译过,超级大,时间也很久,实在不想编译openjdk了。

1.2、修改/etc/fstab文件,增加下面两行,搞定

# Device	Mountpoint	FStype	Options	Dump	Pass#
/dev/ada0p2	/		ufs	rw	1	1
/dev/ada0p3	none		swap	sw	0	0
fdesc		/dev/fd		fdescfs	rw	0	0
proc		/proc		procfs	rw	0	0

2、自己编译Ruby,当然也可以用pkg安装
2.1、下载并编译源码
ruby-lang.org

./configure --prefix=usr/ruby/ruby_2.2.3
make
make install

2.2、配置环境变量,默认为csh
编辑~/.cshrc

set RUBY_HOME=/usr/ruby/ruby_2.2.3
set path=($RUBY_HOME/bin $path)

重新登录一下。

2.3、切换为国内源

gem sources --add https://ruby.taobao.org/
gem sources --remove https://rubygems.org/
gem sources -l

2.4、安装gems

$ gem install rails
$ gem install redis

3、自己编译redis,当然也可以用pkg安装
3.1、下载并编译源码
redis.io

pkg install gmake
gmake
gmake PREFIX=/usr/redis/redis_3.0.4 install

3.2、配置环境变量,默认为csh
编辑~/.cshrc

set REDIS_HOME=/usr/redis/redis_3.0.4
set path=($REDIS_HOME/bin $path)

重新登录一下。

4、安装mongodb
4.1、下载并编译源码
mongodb.org

pkg install gcc
pkg install scons
pkg install python
pkg install libexecinfo

scons all
scons --prefix=/usr/mongodb/mongodb_3.0.7 install

*顺便说一下,这个编译后是18G,安装后为1.1G。。。
*如果你用的是3.0.7版本的源码,在FreeBSD下需要打补丁
github.com

4.2、配置环境变量,默认为csh
编辑~/.cshrc

set MONGODB_HOME=/usr/mongodb/mongodb_3.0.7
set path=($MONGODB_HOME/bin $path)

重新登录一下。

Virtualbox安装配置FreeBSD10

1、新建虚拟机,下载DVD镜像文件,安装虚拟机,整个过程比较简单:分区,选择需要的包,配置网络,配置用户
其中,我的虚拟机网卡配置为:
le0 是hostonly,用于与宿主机、其他虚拟机进行网络通许,要手工设置
le1 是nat,用于蹭网,设置为DHCP就好了

2、安装后重启,发现新用户不能su,将新用户添加到wheel组

#此命令一如既往的强大
bsdconfig

3、然后发现,le1发现可以连外网,但le0配置有些问题,编辑/etc/rc.conf

#network config
hostname="freebsd10"
ifconfig_le0="inet 172.16.172.5 netmask 255.255.0.0"
ifconfig_le1="DHCP"
ip6addrctl_enable="NO"
defaultrouter="10.0.3.2"
#static_routes="net1"
#route_net1="-net 172.16.172.0/16 172.16.172.1"

重启网络,OK。

4、找了一下,VirtualBox自带的扩展插件是没有BSD系统支持的,那就安装开源的呗
首先尝试了bsdconfig进行安装,但系统提示找不到数据库

bsdconfig
#选择Packages
no pkg(8) database found.

4.1A网上找了下,从DVD安装可以这样处理:

mount -t cd9660 /dev/cd0 /dist
env REPOS_DIR=/dist/packages/repos pkg search virtualbox
env REPOS_DIR=/dist/packages/repos pkg install virtualbox-ose-additions 

4.1B或者,直接采用网络安装可以这样处理:

pkg install virtualbox-ose-additions 

4.2安装后,需要在/etc/rc.conf中增加

vboxguest_enable=“YES”
vboxservice_enable=“YES”

重启

5、安装图形界面
从DVD安装可以这样处理:
5.1A

mount -t cd9660 /dev/cd0 /dist

env REPOS_DIR=/dist/packages/repos pkg search xorg
env REPOS_DIR=/dist/packages/repos pkg install xorg

env REPOS_DIR=/dist/packages/repos pkg search gnome
env REPOS_DIR=/dist/packages/repos pkg install gnome3

5.1B或者,直接采用网络安装可以这样处理:

pkg install xorg
pkg install gnome3

5.2A安装完毕后,如果想重启后直接进入图形界面,需要在/etc/rc.conf中增加

gdm_enable="YES"
gnome_enable="YES"

5.2B如果想重启后进入命令行界面,需要在/etc/rc.conf中增加

dbus_enable="YES"

然后,执行命令

echo exec gnome-session > ~/.xinitrc
startx

6、发现命令行界面分辨率太低
6.1查看系统支持的分辨率

#列出所有支持的分辨率
vidcontrol -i mode
#尝试1024x768x24
vidcontrol MODE_280

6.2在/etc/rc.conf中增加

allscreens_flags="MODE_280"

7、启动后,发现sendmail服务启动耗时很久,反正用不到,编辑/etc/rc.conf文件,禁用之

vi /etc/rc.conf
sendmail_enable="NONE"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"

8、最终,我的/etc/rc.conf文件如下

#network config
hostname="freebsd10"
ifconfig_le0="inet 172.16.172.5 netmask 255.255.0.0"
ifconfig_le1="DHCP"
ip6addrctl_enable="NO"
defaultrouter="10.0.3.2"
#static_routes="net1"
#route_net1="-net 172.16.172.0/16 172.16.172.1"

#display config
vboxguest_enable="YES"
vboxservice_enable="YES"
allscreens_flags="MODE_280"
#gdm_enable="YES"
#gnome_enable="YES"

#other service config
sshd_enable="YES"
powerd_enable="YES"
moused_enable="YES"
dbus_enable="YES"

#"AUTO" to enable crash dumps, "NO" to disable crash dumps
dumpdev="AUTO"

#disapbled service
zfs_enable="NO"
sendmail_enable="NONE"
sendmail_outbound_enbale="NO"
sendmail_msp_queue_enable="NO"
sendmail_submit_enable="NO"

Debian8 Jessie修改Terminal分辨率

昨天安装了Debian8 Jessie,禁用了gdb以后,发现Terminal分辨率变的超级低。
用以前的方法调整了一下,发现搞不定了,搞了大半天,终于找到了靠谱的方案:

1、修改/etc/default/grub
找到

#GRUB_GFXMODE=XXXXXX

修改该行,并新增一行,最后效果为

GRUB_GFXMODE=1024x768x24
GRUB_GFXPAYLOAD_LINUX=1024x768x24

2、修改/etc/grub.d/00_header
找到

if [ "x${GRUB_GFXMODE}" = "x" ] ; then auto ; fi,

修改该行,并新增一行,最后效果为

if [ "x${GRUB_GFXMODE}" = "x" ] ; then GRUB_GFXMODE=1024x768x24 ; fi
if [ "x${GRUB_GFXPAYLOAD}" = "x" ] ; then GRUB_GFXPAYLOAD=1024x768x24 ; fi

3、仍然是etc/grub.d/00_header
找到

set gfxmode=${GRUB_GFXMODE}

在其后新增一行,最后效果为

set gfxmode=${GRUB_GFXMODE}
set gfxpayload=${GRUB_GFXPAYLOAD}

4、更新grub并重启,搞定

update-grub2
reboot

5、感觉Debian8 Jessie的配置改变了好多。。。

CentOS7常见操作

1、通过CentOS光盘安装软件

#挂载光盘
mount -r /dev/sr0 /media/cdrom

#修改文件,将光盘查找路径定为/media/cdrom
vi /etc/yum.repos.d/CentOS-Media.repo

#刷新列表
yum --disablerepo=\* --enablerepo=c7-media repolist

#安装vim
yum --disablerepo=\* --enablerepo=c7-media install vim

#通过命令查找包并安装包
yum --disablerepo=\* --enablerepo=c7-media provides ifconfig
yum --disablerepo=\* --enablerepo=c7-media install net-tools

#卸载包
yum erase 包名

2、rpm安装及卸载软件

#安装
rpm -ivh rpm文件路径

#安装并不进行依赖检查
rpm -ivh --nodeps rpm文件路径

#更新
rpm -Uvh rpm文件路径

#删除
rpm -e 包名

#查看包的用途、版本等信息
rpm -qpi rpm文件路径

#查看包的文件清单
rpm -qpl rpm文件路径

#查看软件包文档位置
rpm -qpd rpm文件路径

#查看软件包的配置文件
rpm -qpc rpm文件路径

#查看软件包依赖关系
rpm -qpR rpm文件路径

3、rpm查看已安装软件包信息

#查看已经安装的软件
rpm -qa
 
#查看一个文件属于哪个软件包
rpm -qf 文件绝对路径

#查看安装软件包都安装到何处;
rpm -ql 包名

#查看包的信息
rpm  -qi 包名

#查看包配置文件
rpm -qc 包名

#查看包文档安装位置
rpm -qd 包名

#查看包的依赖
rpm -qR 包名

4、配置网络为静态地址

vim /etc/sysconfig/network-scripts/ifcfg-enp0s3
#修改或新增以下内容
BOOTPROTO=static
ONBOOT=yes
IPADDR=172.16.172.80
NETMASK=255.255.0.0
GATEWAY=172.16.172.2

#重启网络
service network restart

5、防火墙配置

#查看状态
systemctl status firewalld 

#启动
systemctl start firewalld

#关闭
systemctl stop firewalld

#开机启用
systemctl enable firewalld

#开机禁用 
systemctl disable firewalld

Debian默认命令行启动

由于Debian6和Debian8服务管理方式不同,很多旧方法不再适用于Debian8

1、Debian6之前:修改内核启动参数
1.1、修改文件/etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="quiet"

GRUB_CMDLINE_LINUX_DEFAULT="quiet text"

1.2、然后运行

update-grub

2、Debian8之后:systemctl

#切换为命令行登录
systemctl set-default multi-user.target
#退出GUI
gnome-session-quit

#切换为GUI登录
systemctl set-default graphical

3、Grub禁用图像模式
3.1、修改文件/etc/default/grub

#GRUB_TERMINAL=console

GRUB_TERMINAL=console

3.2、然后运行

update-grub

Hadoop Linux Native 编译说明

首先说明一下,如果要使用Linux Native的话,Hadoop是已经自带了哦

然后,如果要编译的话,建议直接从Hadoop源码按官方的说明进行编译,不要像我这样自己搞。。。

如果你喜欢折腾,请继续看:

1、按源码架构拷贝下面的文件及文件夹

hadoop-2.5.2-src\hadoop-common-project\hadoop-common\src\main\native
hadoop-2.5.2-src\hadoop-common-project\hadoop-common\src\CMakeLists.txt
hadoop-2.5.2-src\hadoop-common-project\hadoop-common\src\config.h.cmake
hadoop-2.5.2-src\hadoop-common-project\hadoop-common\src\JNIFlags.cmake
hadoop-2.5.2-src\hadoop-hdfs-project\hadoop-hdfs\src\main\native
hadoop-2.5.2-src\hadoop-hdfs-project\hadoop-hdfs\src\CMakeLists.txt(可能需要调整一下依赖文件JNIFlags.cmake的相对路径)
hadoop-2.5.2-src\hadoop-hdfs-project\hadoop-hdfs\src\config.h.cmake

2、编译libhadoop
2.1、检查并安装以来关系

#需要gcc、make、jdk,这些一般大家都有了
#需要zlib
apt-get install zlib1g-dev
#需要cmake
apt-get install cmake

2.2、用cmake生成Makefile

cmake ./src/ -DGENERATED_JAVAH=~/Build/hadoop-2.5.2-src/build/hadoop-common-project/hadoop-common/native/javah -DJVM_ARCH_DATA_MODEL=64 -DREQUIRE_BZIP2=false -DREQUIRE_SNAPPY=false

2.3、用javah生成头文件
需要三个jar包,hadoop-common,hadoop-annotations,guava

javah org.apache.hadoop.io.compress.lz4.Lz4Compressor
javah org.apache.hadoop.io.compress.lz4.Lz4Decompressor
javah org.apache.hadoop.io.compress.zlib.ZlibCompressor
javah org.apache.hadoop.io.compress.zlib.ZlibDecompressor
javah org.apache.hadoop.io.nativeio.NativeIO 
javah org.apache.hadoop.io.nativeio.SharedFileDescriptorFactory
javah org.apache.hadoop.net.unix.DomainSocket
javah org.apache.hadoop.net.unix.DomainSocketWatcher
javah org.apache.hadoop.security.JniBasedUnixGroupsMapping
javah org.apache.hadoop.security.JniBasedUnixNetgroupsMapping
javah org.apache.hadoop.util.NativeCrc32

将生成的文件,拷贝到对应的c文件夹中

2.3、生成

make

3、编译libhdfs
3.1、用cmake生成Makefile

cmake ./src/ -DGENERATED_JAVAH=~/Build/hadoop-2.5.2-src/build/hadoop-common-project/hadoop-common/native/javah -DJVM_ARCH_DATA_MODEL=64 -DREQUIRE_LIBWEBHDFS=false -DREQUIRE_FUSE=false

3.2、生成

make

4、将生成的文件拷贝到HADOOP_HOME/lib/mynative

5、修改/etc/profile,增加下面一行

export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib/mynative"

6、刷新配置

source /etc/profile

搞定!