随笔 - 137  文章 - 1  trackbacks - 0
<2024年5月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿

随笔分类

随笔档案

收藏夹

调试技巧

搜索

  •  

最新评论

阅读排行榜

评论排行榜

1、ruby
https://tecadmin.net/install-ruby-latest-stable-centos/
2、mysql访问权限

 GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.100 

' IDENTIFIED BY '' WITH GRANT OPTION; 
posted @ 2018-01-30 15:53 长戟十三千 阅读(237) | 评论 (0)编辑 收藏
 有两种方式:
   1. command & : 后台运行,你关掉终端会停止运行
   2. nohup command & : 后台运行,你关掉终端也会继续运行
   
一、 简介 
    Linux/Unix 区别于微软平台最大的优点就是真正的多用户,多任务。因此在任务管理上也有别具特色的管理思想。
我们知道,在 Windows 上面,我们要么让一个程序作为服务在后台一直运行,要么停止这个服务。而不能让程序在前台后台之间切换。而 Linux 提供了 fg 和bg 命令,让你轻松调度正在运行的任务。假设你发现前台运行的一个程序需要很长的时间,但是需要干其他的事情,你就可以用 Ctrl-Z ,挂起这个程序,然后可以看到系统提示:
[1]+ Stopped /root/bin/rsync.sh
然后我们可以把程序调度到后台执行:(bg 后面的数字为作业号)
#bg 1
[1]+ /root/bin/rsync.sh &
用 jobs 命令查看正在运行的任务:
#jobs
[1]+ Running /root/bin/rsync.sh &
如果想把它调回到前台运行,可以用
#fg 1
/root/bin/rsync.sh
这样,你在控制台上就只能等待这个任务完成了。
& 将指令丢到后台中去执行
[ctrl]+z 將前台任务丟到后台中暂停
jobs 查看后台的工作状态
fg %jobnumber 将后台的任务拿到前台来处理
bg %jobnumber 将任务放到后台中去处理
kill 管理后台的任务
二、&
在Linux中,当在前台运行某个作业时,终端被该作业占据;而在后台运行作业时,它不会占据终端。可以使用&命令把作业放到后台执行。实际上,这样是将命令放入到一个作业队列中了:
$ ./test.sh &
[1] 17208
$ jobs -l
[1]+ 17208 Running                 ./test.sh &
    在后台运行作业时要当心:需要用户交互的命令不要放在后台执行,因为这样你的机器就会在那里傻等。不过,作业在后台运行一样会将结果输出到屏幕上,干扰你的工作。如果放在后台运行的作业会产生大量的输出,最好使用下面的方法把它的输出重定向到某个文件中:
command >out.file 2>&1 &
在上面的例子中,2>&1表示所有的标准输出和错误输出都将被重定向到一个叫做out.file 的文件中。 当你成功地提交进程以后,就会显示出一个进程号,可以用它来监控该进程,或杀死它。 
例:查找名为“httpd.conf”的文件,并把所有标准输出和错误输出重定向到find.dt的文件中: 
# find /etc/httpd/ -name "httpd.conf" -print >find.dt 2>&1 & 
[2] 7832 
成功提交该命令之后,系统给出了它的进程号7832。 对于已经在前台执行的命令,也可以重新放到后台执行,首先按ctrl+z暂停已经运行的进程,然后使用bg命令将停止的作业放到后台运行,例如对正在前台执行的tesh.sh使用ctrl+z挂起它:
$ ./test.sh
[1]+ Stopped                 ./test.sh
$ bg %1
[1]+ ./test.sh &
$ jobs -l
[1]+ 22794 Running                 ./test.sh &
但是如上方到后台执行的进程,其父进程还是当前终端shell的进程,而一旦父进程退出,则会发送hangup信号给所有子进程,子进程收到hangup以后也会退出。如果我们要在退出shell的时候继续运行进程,则需要使用nohup忽略hangup信号,或者setsid将将父进程设为init进程(进程号为1)
$ echo $$
21734
$ nohup ./test.sh &
[1] 29016
$ ps -ef | grep test
515      29710 21734 0 11:47 pts/12   00:00:00 /bin/sh ./test.sh
515      29713 21734 0 11:47 pts/12   00:00:00 grep test
$ setsid ./test.sh &
[1] 409
$ ps -ef | grep test
515        410     1 0 11:49 ?        00:00:00 /bin/sh ./test.sh
515        413 21734 0 11:49 pts/12   00:00:00 grep test
上面的试验演示了使用nohup/setsid加上&使进程在后台运行,同时不受当前shell退出的影响。那么对于已经在后台运行的进程,该怎么办呢?可以使用disown命令:
$ ./test.sh &
[1] 2539
$ jobs -l
[1]+ 2539 Running                 ./test.sh &
$ disown -h %1
$ ps -ef | grep test
515        410     1 0 11:49 ?        00:00:00 /bin/sh ./test.sh
515       2542 21734 0 11:52 pts/12   00:00:00 grep test
另外还有一种方法,即使将进程在一个subshell中执行,其实这和setsid异曲同工。方法很简单,将命令用括号() 括起来即可:
$ (./test.sh &)
$ ps -ef | grep test
515        410     1 0 11:49 ?        00:00:00 /bin/sh ./test.sh
515      12483 21734 0 11:59 pts/12   00:00:00 grep test
注:本文试验环境为Red Hat Enterprise Linux AS release 4 (Nahant Update 5),shell为/bin/bash,不同的OS和shell可能命令有些不一样。例如AIX的ksh,没有disown,但是可以使用nohup -p PID来获得disown同样的效果。
还有一种更加强大的方式是使用screen,首先创建一个断开模式的虚拟终端,然后用-r选项重新连接这个虚拟终端,在其中执行的任何命令,都能达到nohup的效果,这在有多个命令需要在后台连续执行的时候比较方便:
$ screen -dmS screen_test
$ screen -list
There is a screen on:
        27963.screen_test       (Detached)
1 Socket in /tmp/uscreens/S-jiangfeng.
$ screen -r screen_test
三、 nohup 
    如果你正在运行一个进程,而且你觉得在退出帐户时该进程还不会结束,那么可以使用nohup命令。该命令可以在你退出帐户之后继续运行相应的进程。nohup就是不挂起的意思( no hang up)。 该命令的一般形式为: 
nohup conmmand &
如果使用nohup命令提交作业,那么在缺省情况下该作业的所有输出都被重定向到一个名为nohup.out的文件中,除非另外指定了输出文件:
nohup command > myout.file 2>&1 
在上面的例子中,输出被重定向到myout.file文件中。
四、.*,?,[...],[!...]等 
下面就是这些特殊字符: 
* 匹配文件名中的任何字符串,包括空字符串。 
? 匹配文件名中的任何单个字符。 
[...] 匹配[ ]中所包含的任何字符。 
[!...] 匹配[ ]中非感叹号!之后的字符。 
当s h e l l遇到上述字符时,就会把它们当作特殊字符,而不是文件名中的普通字符,这样用户就可以用它们来匹配相应的文件名。
1)列出以i或o开头的文件名:     #ls [io]*
2)列出log.开头、后面跟随一个数字、然后可以是任意字符串的文件名: #ls log.[0-9]* 
3)与例二相反,列出log.开头、后面不跟随一个数字、然后可以是任意字符串的文件名 : #ls log.[!0-9]* 
4)列出所有以LPS开头、中间可以是任何两个字符,最后以1结尾的文件名:#ls LPS??1
5)列出所有以大写字母开头的文件名:$ ls [A-Z]* 6)列出所有以. 开头的文件名(隐含文件,例如. profile、.rhosts、.histo ry等): $ ls .*
其他相关命令:
jobs:查看当前有多少在后台运行的命令
fg:将后台中的命令调至前台继续运行。如果后台中有多个命令,可以用 fg %jobnumber将选中的命令调出,%jobnumber是通过jobs命令查到的后台正在执行的命令的序号(不是pid)
bg:将一个在后台暂停的命令,变成继续执行。如果后台中有多个命令,可以用bg %jobnumber将选中的命令调出,%jobnumber是通过jobs命令查到的后台正在执行的命令的序号(不是pid)
杀死进程
杀死已经启动的程序和普通方式一样:
pkill -9 name
killall name
kill pid
posted @ 2018-01-29 09:35 长戟十三千 阅读(414) | 评论 (0)编辑 收藏

在.vimrc中添加以下代码后,重启vim即可实现按TAB产生4个空格:
set ts=4  (注:ts是tabstop的缩写,设TAB宽4个空格)
set expandtab

 

对于已保存的文件,可以使用下面的方法进行空格和TAB的替换: 
TAB替换为空格: 
:set ts=4
:set expandtab
:%retab!

 

空格替换为TAB:
:set ts=4
:set noexpandtab
:%retab!

 

加!是用于处理非空白字符之后的TAB,即所有的TAB,若不加!,则只处理行首的TAB。

posted @ 2017-11-30 11:51 长戟十三千 阅读(664) | 评论 (0)编辑 收藏

vim代码补全

现在的图形界面的IDE(Integrated Development Environment)一般具有语法高亮,语法检查,自动补全功能,大大提高了编程的效率。

vim作为文本编辑器其强大的编辑能力很大部分来自于普通模式命令,用户使用这些命令可以快速的在文档中移动、定位、查找、替换删除、而不用使用鼠标去完成这些操作。vim另一个强大之处是支持各种插件安装,用户可以根据功能需求和习惯安装需要的插件。本文将介绍两个非常强大的开源vim插件使得vim具有IDE一样的功能,提高使用vim编程的效率。这两个vim插件分别是spf13 和 YouCompleteMe

1. vim7.4添加Lua支持

之所以安装支持Lua的vim7.4,是因为spf13需要Lua支持。

1.1 安装Lua和LuaJit

Centos的官方源中包含Lua,可以直接使用Yum命令安装

sudo yum install lua lua-devel -y

Luajit不在Centos的官方源中,需要源码安装

wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz tar -xzvf LuaJIT-2.0.4.tar.gz cd LuaJIT-2.0.4 // 使用默认安装路径 make sudo make install

1.2编译安装vim7.4

// git好处是以后可以方便地更新 git clone git@github.com:vim/vim.git tar xzvf vim-7.4.tar.bz2 cd vim74 ./configure --prefix=/usr/local/bin/vim74 \ --with-features=huge \ --with-luajit \ --enable-pythoninterp=yes \ --with-python-config-dir=/usr/lib64/python2.7/config \ --enable-luainterp=yes \ --enable-fail-if-missing --enable-fail-if-missing make sudo make install

2. 安装spf13

自己配置vim往往很繁琐,需要对vim配置很熟悉,spf13-vim不仅配置精良而且包含一整套精心挑选的插件,省去了很多配置细节。

curl https://j.mp/spf13-vim3 -L > spf13-vim.sh && sh spf13-vim.sh

3. 安装和配置YouCompleteMe

3.1 安装YouCompleteMe

YouCompleteMe是一个vim插件,而在spf13中指定安装YouCompleteMe插件也很方便,只需要在文件~/.vimrc.before.local中添加下面一行,然后使用Vundle安装命令即可。

let g:spf13_bundle_groups=['general', 'youcompleteme']

Vundle命令安装:

vim :BundleInstall!

编译ycm_core.so:
ycm自动补全需要动态库ycm_core.so,需要用户自己编译,用户可以选择编译全部功能或者选择只支持C/C++自动补全:

cd ~/.vim/bundle/YouCompleteMe/ ./install.py --all #编译支持所有功能 or ./install.py --clang-completer #只支持C/C++补全

3.2 YouCompleteMe配置

YouCompleteMe有两个需要配置的地方一个是.virmc,另一个是.ycm_extra_conf.py。

.vimrc位于用户home目录下,用来配置YouCompleteMe的全局行为,例如全局ycm_extra_conf.py路径,代码跳转快捷键映射。我的.vimrc配置如下:

" YouCompleteMe {         if count(g:spf13_bundle_groups, 'youcompleteme')             let g:acp_enableAtStartup = 0             " global conf which is needed to resolve name in system include             " file or other  third-part include file             let g:ycm_global_ycm_extra_conf = '~/.vim/data/ycm/.ycm_extra_conf.py'              " enable completion from tags             let g:ycm_collect_identifiers_from_tags_files = 1             let g:ycm_seed_identifiers_with_syntax = 1             let g:ycm_confirm_extra_conf = 0             let g:ycm_cache_omnifunc=0             let g:ycm_key_invoke_completion = '<C-;>'               nnoremap <F5> :YcmForceCompileAndDiagnostics<CR>             nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR>

上面配置中全局.ycm_extra_conf.py路径很重要,如果不配置将无法解析C/C++头文件

.ycm_extra_conf.py 模版位于./YouCompleteMe/third_party/ycmd/cpp/ycm/,其中-isystem flag用来配置系统头文件路径,-I用来配置第三方头文件路径, 一个支持C/C++工程的ycm_extra_conf.py部分配置文件如下:

'-std=c++11', #'-std=c99', # ...and the same thing goes for the magic -x option which specifies the # language that the files to be compiled are written in. This is mostly # relevant for c++ headers. # For a C project, you would set this to 'c' instead of 'c++'. '-x', 'c++', '-isystem', '../BoostParts', #-isystem: system include file path '-isystem', '/usr/include', '-isystem', '/usr/local/include', '-isystem', '/usr/include/c++/4.8.5', ]

YouCompleteMe查找.ycm_extra_conf.py过程是在当前编辑文件所在目录查找,然后逐级向上查找,如果没有找到则使用全局配置文件。

最后截图:

posted @ 2017-11-24 15:40 长戟十三千 阅读(606) | 评论 (0)编辑 收藏
[1]Install some packages.
# install from EPEL

[root@dlp ~]# 
yum --enablerepo=epel -y install composer php-bcmath
[2]Install AMQP client library.
[cent@dlp ~]$ 
composer require php-amqplib/php-amqplib 

Using version ^2.6 for php-amqplib/php-amqplib ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev)   - Installing php-amqplib/php-amqplib (v2.6.3)     Downloading: 100%  Writing lock file Generating autoload files  
[cent@dlp ~]$ 
composer install 

Loading composer repositories with package information Installing dependencies (including require-dev) from lock file Nothing to install or update Generating autoload files 
[3]This is an example of sending message on PHP.
For example, connect with RabbitMQ user "serverworld", virtualhost "my_vhost".
[cent@dlp ~]$ 
vi send_msg.php
<?php require_once __DIR__ . '/vendor/autoload.php';  use PhpAmqpLib\Connection\AMQPStreamConnection; use PhpAmqpLib\Message\AMQPMessage;  $connection = new AMQPStreamConnection('127.0.0.1', 5672, 'serverworld', 'password', '/my_vhost');  $channel = $connection->channel(); $channel->queue_declare('Hello_World', false, false, false, false);  $msg = new AMQPMessage('Hello RabbitMQ World!'); $channel->basic_publish($msg, '', 'Hello_World'); echo " [x] Sent 'Hello_World'\n";  $channel->close(); $connection->close(); ?>  
[cent@dlp ~]$ 
php send_msg.php 

 [x] Sent 'Hello_World' 
[4]This is an example of receiving message on PHP.
[cent@node01 ~]$ 
vi receive_msg.php
<?php require_once __DIR__ . '/vendor/autoload.php'; use PhpAmqpLib\Connection\AMQPStreamConnection;  $connection = new AMQPStreamConnection('127.0.0.1', 5672, 'serverworld', 'password', '/my_vhost'); $channel = $connection->channel();  $channel->queue_declare('Hello_World', false, false, false, false);  echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";  $callback = function($msg) {     echo " [x] Received ", $msg->body, "\n"; };  $channel->basic_consume('Hello_World', '', false, true, false, false, $callback);  while(count($channel->callbacks)) {     $channel->wait(); } ?>  
[cent@node01 ~]$ 
php receive_msg.php 

 [*] Waiting for messages. To exit press CTRL+C  [x] Received Hello RabbitMQ World!
posted @ 2017-11-16 17:53 长戟十三千 阅读(266) | 评论 (0)编辑 收藏
gitlab unicorn settings
https://docs.gitlab.com/omnibus/settings/unicorn.html

Unicorn settings 

If you need to adjust the Unicorn timeout or the number of workers you can use the following settings in /etc/gitlab/gitlab.rb. Run sudo gitlab-ctl reconfigure for the change to take effect.

unicorn['worker_processes'] = 3 unicorn['worker_timeout'] = 60 
Minimum required worker_processes is 2 in order for the web editor to work correctly, see gitlab-ce#18771

Edit this page
posted @ 2017-11-16 11:49 长戟十三千 阅读(347) | 评论 (0)编辑 收藏
rabbitmqctl add_user test test 
rabbitmqctl set_user_tags test administrator
rabbitmqctl set_permissions -p / test ".*" ".*" ".*"

posted @ 2017-11-09 10:51 长戟十三千 阅读(427) | 评论 (0)编辑 收藏

一、Install Erlang:

因为RabbitMQ是基于Erlang开发的,所以首先需要安装Erlang。

安装的方式有很多种,我比较喜欢直接使用yum安装,其他方式请自行Google。

因为yum官方源没有Erlang,所以需要添加EPEL源,具体方式如下:

su -c 'rpm -Uvh http://download.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm'

su -c 'yum install foo'

以上是针对CentOS7的命令。

附上centos5和centos6的操作命令:

For EL5:

su -c 'rpm -Uvh http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm'

su -c 'yum install foo'

For EL6:

su -c 'rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm'

su -c 'yum install foo'

添加源完成后,执行yum命令:

yum install erlang

如果顺利的话,应该Erlang成功安装。

二、安装RabbitMQ:

首先下载安装文件(我安装的是目前最新版,如果想尝试安装其他版本,在官网找吧):

wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.5/rabbitmq-server-3.6.5-1.noarch.rpm

rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc

yum install rabbitmq-server-3.6.5-1.noarch.rpm

好哒,不出意外,mq就安装成功了。如果有意外,只能靠你的聪明才智去解决了,编程就是这样不断的和bug作斗争。

三、设置开机启动&启动

chkconfig rabbitmq-server on

service rabbitmq-server start

四、安装web管理界面

rabbitmq-plugins enable rabbitmq_management

现在可以通过http://ip:15672访问了。



作者:Luomeng
链接:http://www.jianshu.com/p/ea6296406995
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
posted @ 2017-11-08 16:17 长戟十三千 阅读(301) | 评论 (0)编辑 收藏
pre: 更换阿里云的yum 源

yum install -y autojump
yum install autojump-zsh
source /etc/profile.d/autojump.sh
posted @ 2017-11-08 15:07 长戟十三千 阅读(514) | 评论 (0)编辑 收藏

使用Linux肯定少不了使用yum来安装软件,CentOS7默认的yum源貌似是网易的?反正给我的感觉是又慢又旧,于是想更换到更快的阿里云的yum源。

首先得安装wget

sudo yum -y install wget

安装好wget后开始我们的yum源切换啦~

  1. 备份原来的yum源
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
  1. 设置aliyun的yum源
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  1. 添加EPEL源

EPEL(http://fedoraproject.org/wiki/EPEL)是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。装上 EPEL后,可以像在 Fedora 上一样,可以通过 yum install package-name,安装更多软件。

sudo wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo

清理缓存并生成新的缓存

sudo yum clean all  
sudo yum makecache 

本文属转载,原文地址:http://blog.csdn.net/skykingf/article/details/51953700

posted @ 2017-11-08 15:04 长戟十三千 阅读(385) | 评论 (0)编辑 收藏
仅列出标题
共14页: First 6 7 8 9 10 11 12 13 14