分类目录归档:Linux

GlusterFS in AWS

挂载Amazon EBS

lsblk
yum install -y xfsprogs
wget -P /etc/yum.repos.d http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/glusterfs-epel.repo
sed -i 's/$releasever/6/g' /etc/yum.repos.d/glusterfs-epel.repo 
mkfs.xfs -i size=512 /dev/xvdf
mkdir -p /export/xvdf
echo "/dev/xvdf /export/xvdf xfs defaults,nofail,noatime 1 2"  >> /etc/fstab
mount -a

安装服务器端

#install glusterfs
yum install -y glusterfs{-fuse,-server}
#start glusterfs
service glusterd start
#turn on auto-start
chkconfig glusterd on
mkdir /export/xvdf/brick1
gluster volume create pcvol 172.31.42.77:/export/xvdf/brick1
gluster volume start pcvol
gluster volume info
gluster volume status

客户端

#install glusterfs repo
wget -P /etc/yum.repos.d http://download.gluster.org/pub/gluster/glusterfs/LATEST/EPEL.repo/glusterfs-epel.repo
#fix it for amazon linux
sed -i 's/$releasever/6/g' /etc/yum.repos.d/glusterfs-epel.repo 

#install glusterfs
yum install -y glusterfs-fuse

#setup fstab
echo "172.31.42.77:/pcvol /data_pcvol glusterfs defaults,noatime 0 0" >> /etc/fstab

#mount
mkdir /data_pcvol
mount -a
ls /data_pcvol

参考

  • http://www.gluster.org/documentation/quickstart/
  • http://blog.gluster.org/category/aws-en/
  • http://serverfault.com/questions/479576/installing-glusterfs-on-amazon-ec2

Fedora 20安装Fcitx输入法并安装搜狗资源包

原文链接:http://yanue.net/post-140.html

1、先卸载系统自带的Ibus输入法

sudo yum remove ibus
gsettings set org.gnome.settings-daemon.plugins.keyboard active false

2、安装Fcitx输入法

yum install fcitx fcitx-devel fcitx-configtool fcitx-cloudpinyin fcitx-pinyin

3、配置一下Fcitx、在~/.bashrc中添加:如下内容

export GTK_IM_MODULE=fcitx  
export QT_IM_MODULE=fcitx  
export XMODIFIERS="@im=fcitx"

4、注销或重启后完成安装

上面步骤完成之后其实就可以使用Fcitx输入法

不过看到搜狗输入法都已经出deb包了

所以就想着安装个搜狗输入法到Fcitx上去。

5、安装搜狗资源包

从下面的连接地址下载对应的deb包、32位系统用i386.deb、64位系统用amd64.deb

http://mirrors.ustc.edu.cn/deepin/pool/non-free/f/fcitx-sogoupinyin-release/

随便在从如下地址下载一个搜狗输入法的皮肤

http://mirrors.ustc.edu.cn/deepin/pool/main/f/fcitx-skins/

6、下载完成之后双击打开amd64.deb、将里面的data.tar.bz提取出来、然后到解压压缩文件

接着我们把解压出来的.so文件移动到Fcitx的指定目录即可(64位为例)

cp /usr/lib/x86_64-linux-gnu/fcitx/fcitx-sogoupinyin.so /usr/lib64/fcitx/

最后加上执行权限

chmod +x /usr/lib64/fcitx/fcitx-sogoupinyin.so

fedora20下使用sublime text 3

原文链接:http://fewspider.github.io/linux/Sublime-Text-Chinese-input-under-Linux.html

编译库

复制以下内容到sublime-imfix.c

/*
sublime-imfix.c
Use LD_PRELOAD to interpose some function to fix sublime input method support for linux.
By Cjacker Huang

gcc -shared -o libsublime-imfix.so sublime-imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC
LD_PRELOAD=./libsublime-imfix.so subl
*/
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
typedef GdkSegment GdkRegionBox;

struct _GdkRegion
{
  long size;
  long numRects;
  GdkRegionBox *rects;
  GdkRegionBox extents;
};

GtkIMContext *local_context;

void
gdk_region_get_clipbox (const GdkRegion *region,
            GdkRectangle    *rectangle)
{
  g_return_if_fail (region != NULL);
  g_return_if_fail (rectangle != NULL);

  rectangle->x = region->extents.x1;
  rectangle->y = region->extents.y1;
  rectangle->width = region->extents.x2 - region->extents.x1;
  rectangle->height = region->extents.y2 - region->extents.y1;
  GdkRectangle rect;
  rect.x = rectangle->x;
  rect.y = rectangle->y;
  rect.width = 0;
  rect.height = rectangle->height;
  //The caret width is 2;
  //Maybe sometimes we will make a mistake, but for most of the time, it should be the caret.
  if(rectangle->width == 2 && GTK_IS_IM_CONTEXT(local_context)) {
        gtk_im_context_set_cursor_location(local_context, rectangle);
  }
}

//this is needed, for example, if you input something in file dialog and return back the edit area
//context will lost, so here we set it again.

static GdkFilterReturn event_filter (GdkXEvent *xevent, GdkEvent *event, gpointer im_context)
{
    XEvent *xev = (XEvent *)xevent;
    if(xev->type == KeyRelease && GTK_IS_IM_CONTEXT(im_context)) {
       GdkWindow * win = g_object_get_data(G_OBJECT(im_context),"window");
       if(GDK_IS_WINDOW(win))
         gtk_im_context_set_client_window(im_context, win);
    }
    return GDK_FILTER_CONTINUE;
}

void gtk_im_context_set_client_window (GtkIMContext *context,
          GdkWindow    *window)
{
  GtkIMContextClass *klass;
  g_return_if_fail (GTK_IS_IM_CONTEXT (context));
  klass = GTK_IM_CONTEXT_GET_CLASS (context);
  if (klass->set_client_window)
    klass->set_client_window (context, window);

  if(!GDK_IS_WINDOW (window))
    return;
  g_object_set_data(G_OBJECT(context),"window",window);
  int width = gdk_window_get_width(window);
  int height = gdk_window_get_height(window);
  if(width != 0 && height !=0) {
    gtk_im_context_focus_in(context);
    local_context = context;
  }
  gdk_window_add_filter (window, event_filter, context);
}

执行以下命令生成SO文件:

gcc -shared -o libsublime-imfix.so sublime-imfix.c `pkg-config --libs --cflags gtk+-2.0` -fPIC

编译时如果提示 gtk/gtk.h: No such file or directory,需要先安装编译工具

yum install gtk2-devel

运行方式

LD_PRELOAD=./libsublime-imfix.so subl

生成启动快捷方式

复制subl目录下的sublime_text.desktop到/usr/share/applications/sublime_text.desktop并修改exec与icon

Icon=/opt/sublime_text_3/Icon/256x256/sublime-text.png
Exec=bash -c 'LD_PRELOAD=/opt/sublime_text_3/libsublime-imfix.so /opt/sublime_text_3/sublime_text' %F

现在,使用sublime可以支持fcitx输入法输入中文了,要将ibus替换成fcitx请参考我的另外一篇文章Fedora 20安装Fcitx输入法并安装搜狗资源包

ssh config常用配置

vim ~/.ssh/config

Host    别名
    HostName        主机名
    Port            端口
    User            用户名
    IdentityFile    密钥文件的路径

有了这些配置,就可以这样用 ssh 登陆服务器了:

ssh 别名

如果遇到Bad owner or permissions错误,执行以下语句:

sudo chmod 600 config

拷贝ssh key

ssh-copy-id 别名

gedit中文乱码解决

终端配置

gsettings set org.gnome.gedit.preferences.encodings auto-detected "['UTF-8', 'GB18030', 'GB2312', 'GBK', 'BIG5', 'CURRENT', 'UTF-16']"
gsettings set org.gnome.gedit.preferences.encodings shown-in-menu "['UTF-8', 'GB18030', 'GB2312', 'GBK', 'BIG5', 'CURRENT', 'UTF-16']"

使用dconf-tools工具进行配置

yum install dconf-tools,然后运行dconf-editor(ctrl+f2),依次点开->org->gnome->gedit->preferences->encodings设置如上即可

centos7基本系统安装(php-fpm,mariadb,nginx,epel)

安装epel

su -c 'rpm -Uvh http://mirrors.hust.edu.cn/epel/beta/7/x86_64/epel-release-7-0.2.noarch.rpm'
su -c 'yum install epel-release-7-0.2'

安装mariadb,php,nginx

su -c 'yum install mariadb mariadb-server php php-cli php-fpm php-pdo nginx'

创建数据库账户

CREATE USER 'th'@'%' IDENTIFIED BY '***';
GRANT ALL PRIVILEGES ON * . * TO 'th'@'%' IDENTIFIED BY '***';
flush privileges;

fedora开放环境一键安装

sudo不需要密码

visudo

%wheel  ALL=(ALL)       NOPASSWD: ALL

开发环境

yum groupinstall "Development tools" -y

右键打开控制台窗口

yum install nautilus-open-terminal

禁止selinux

setenforce 0 

vi /etc/selinux/config

SELINUX=disabled

安装vscode

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'

vim & git & hg & svn

yum install vim git hg subversion

nginx & php & mysql

yum install mariadb nginx php-cli php-devel php-mbstring php-opcache php-mysqlnd php-intl php-mcrypt php-pdo php-xml php-pecl-memcache  php-pecl-redis php-pecl-sphinx php-pecl-zip php-pgsql php-xdebug php-gd  php-pecl-redis  php-pecl-imagick  php-fpm

python

yum install python-virtualenv pyvenv ~/py cd ~/py/bin source activate wget https://bootstrap.pypa.io/get-pip.py python get-pip.py

golang

wget http://golang.org/dl/go1.3.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.3.linux-amd64.tar.gz 
mkdir ~/gosrc
vim ~/.bash_profile

设置GOROOT与GOPATH

GOPATH=$HOME/gosrc
GOROOT=/usr/local/go
export GOROOT
export GOPATH
PATH=$PATH:$GOROOT/bin:$GOPATH/bin
export PATH

修改系统参数

vi /etc/sysctl.conf

fs.file-max = 500000

vi /etc/security/limits.conf

* soft nofile 60000
* hard nofile 60000

vi /etc/security/limits.d/90-nproc.conf

*          soft    nproc     4096
root       soft    nproc     unlimited

sudo无需密码

编辑sudo配置文件

# sudo visudo
your_user_name ALL=(ALL) NOPASSWD: ALL

不起作用?

原因是被后面的group的设置覆盖了,需要把group的设置也改为nopasswd

%wheel  ALL=(ALL)       NOPASSWD: ALL

mysql批量导入导出

备份数据库到脚本(20分钟)

mysqldump -u username -p password --all-databases --flush-privileges | gzip  > all.sql.gz

拷贝到新机器(20分钟)

scp -P xxx -r all.sql.gz root@host:~

解压缩(2分钟)

gunzip  all.sql.gz 

解决掉视图权限问题(1分钟)

sed '/\/*!50013/d' all.sql  > all_without_50013.sql

导入(40分钟)

mysql -u username -p password < all_without_50013.sql