Ubuntu 安装java8(jdk8)和java7(jdk7)并灵活切换

前言

本机装的是 jdk7 ,无奈最近看的源码不少都已经拥抱 jdk8 了。便于调试,安装了新的 java 版本。

安装 jdk

这里简单说明下 Ubuntu 下 jdk8 的安装过程,jdk7 的类似,不再赘述。

下载安装包: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html ,选择 jdk-8u162-linux-x64.tar.gz。

新建目录并解压到该目录

sudo mkdir /usr/lib/java
sudo tar zxvf ./jdk-8u162-linux-x64.tar.gz -C /usr/lib/java
sudo mv /usr/lib/java/jdk1.8.0_162/ /usr/lib/java/jdk8

打开配置文件, sudo gedit /etc/profile, 在文件中加入以下内容

export JAVA_HOME=/usr/lib/java/jdk8
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

将新安装的 jdk 加入到选项里

sudo update-alternatives --install /usr/bin/java java /usr/lib/java/jdk8/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/java/jdk8/bin/javac 300

通过 sudo update-alternatives –config java 指令,选择相应的jdk即可!

$ sudo update-alternatives --config java       
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      auto mode
* 1            /usr/lib/java/jdk7/bin/java                      300       manual mode
  2            /usr/lib/java/jdk8/bin/java                      300       manual mode
  3            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/java/jdk8/bin/java to provide /usr/bin/java (java) in manual mode

然后在命令行里查看 jdk 的版本

$ java -version
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

切换 jdk 版本

修改 $PATH 中的java路径,然后通过 sudo update-alternatives –config java 指令切换版本即可!

Ubuntu搭建ghost博客 V1.20

官方推荐以下环境:

  • Ubuntu 16.04
  • MySQL
  • NGINX (minimum of 1.9.5 for SSL)
  • Systemd
  • Node v6 installed via NodeSource
  • 至少1GB内存 (可用)
  • 可运行Ghost的非root用户

增加运行Ghost用户

adduser <user>

(为自定义的用户名称,需改,下同)

usermod -aG sudo <user>

为新增用户添加root权限

su - <user>

切换到新增用户

升级Packages

sudo apt-get update

升级package lists

sudo apt-get upgrade

升级installed packages

安装Mysql&Nginx

sudo apt-get install nginx

安装nginx

sudo ufw allow 'Nginx Full'

打开HTTP/HTTPS防火墙

sudo apt-get install mysql-server

安装mysql数据库(root密码不要设为空)

安装Node.js

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash

安装6版本以上的Node.js

sudo apt-get install -y nodejs

运行安装命令

安装Ghost-CLI

sudo npm i -g ghost-cli

用CLI安装Ghost博客

sudo mkdir -p /var/www/ghost

新建一个ghost博客的目录(可改)

sudo chown [user]:[user] /var/www/ghost

给新增的用户全部新建的目录的权限

cd /var/www/ghost

进入目录

ghost install

安装ghost博客

后面会提示你输入ghost地址,只需要把域名解析到服务器地址并输入博客地址就行,一键安装包会帮你配置Nginx,并且支持一键申请ssl。

使用PM2让你的ghost博客保持运行

cd /var/www/ghost  
npm install pm2 -g # 安装PM2  
NODE_ENV=production pm2 ghost start --name "ghost"  
pm2 startup ubuntu  
pm2 save 

如果是centos请把代码中的ubuntu改为centos,debian也是如此。
因为GFW的强大,在上一步直接使用npm安装依赖的时候可能出现无法安装的情况,这时候可以使用以下代码:

npm install -g cnpm --registry=https://registry.npm.taobao.org  
cnpm install pm2 -g  
NODE_ENV=production pm2 start index.js --name "ghost"  
pm2 startup   ubuntu
pm2 save  

这样一来,我们的Ghost博客就可以保持运行啦,你可以使用以下指令来控制Ghost博客:

pm2 start/stop/restart ghost

Ubuntu下Python设置pip使用国内源站

在用户目录下建立.pip/pip.conf文件

cd ~/ && mkdir .pip
cd .pip && nano pip.conf

写入以下配置并保存即可

[global]
index-url = https://pypi.douban.com/simple/

当然,还可以选择使用清华,阿里等源站

清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里: https://mirrors.aliyun.com/pypi/simple

未分类

解决 Ubuntu 下 ssh 服务器中文显示乱码

在 Ubuntu 16.10 下使用终端 ssh 登录远程服务器,然后使用服务器上的 VIM 打开代码文件,发现文件中的中文都是乱码。而使用 Mac 的自带终端进行同样的操作,看到的中文显示就是正常的。遂怀疑 Ubuntu 本地的配置有问题。

问题的原因是,本地的 locale 与服务器上的 locale 不匹配。参考链接里提供了四种解决方案,而我觉得 Stop forwarding locale from the client 这种解决方案最简单。

即,修改 Ubuntu 本地的 /etc/ssh/ssh_config 文件,注释掉

SendEnv LANG LC_*

这一行。然后重新 ssh 服务器,会发现中文已经可以正常显示了。

CentOS 6.9上inotify-tools 安装及使用方法

Linux内核从2.6.13开始,引入了inotify机制。通过intofity机制,能够对文件系统的变化进行监控,如对文件进行创建、删除、修改等操作,可以及时通知应用程序进行相关事件的处理。这种响应处理机制,避免了频繁的文件轮询任务,提高了任务的处理效率。

一、检查系统内核版本

[root@localhost tan]# uname -r
2.6.32-696.el6.x86_64

二、检查系统是否支持inotify

[root@localhost tan]# ls -lsart /proc/sys/fs/inotify  
total 0
0 dr-xr-xr-x 0 root root 0 Jan 17 08:47 ..
0 dr-xr-xr-x 0 root root 0 Jan 17 08:53 .
0 -rw-r--r-- 1 root root 0 Jan 19 13:33 max_user_watches
0 -rw-r--r-- 1 root root 0 Jan 19 13:33 max_queued_events
0 -rw-r--r-- 1 root root 0 Jan 19 13:40 max_user_instances
[root@localhost tan]#

如果出现上面结果说明系统支持inotify。

三、下载安装(下载有点慢)

[root@localhost tan]#wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz  

[root@localhost tan]# tar -zvxf inotify-tools-3.14.tar.gz  
[root@localhost tan]# cd inotify-tools-3.14  

[root@localhost inotify-tools-3.14]# ./configure --prefix=/usr/local/inotify  
[root@localhost inotify-tools-3.14]# make  
[root@localhost inotify-tools-3.14]# make install

四、查看inotify默认参数

[root@localhost bin]# sysctl -a | grep max_queued_events  
fs.inotify.max_queued_events = 16384  

[root@localhost bin]# sysctl -a | grep max_user_watches  
fs.inotify.max_user_watches = 8192  
fs.epoll.max_user_watches = 798863  

[root@localhost bin]# sysctl -a | grep max_user_instances  
fs.inotify.max_user_instances = 128

五、修改inotify参数

1、命令修改

[root@localhost bin]# sysctl -w fs.inotify.max_user_instances=130  
fs.inotify.max_user_instances = 130

2、文件修改

[root@localhost]# vi /etc/sysctl.conf  
#添加如下代码  
fs.inotify.max_user_instances=130

3、参数说明

  • max_user_instances:每个用户创建inotify实例最大值
  • max_queued_events:inotify队列最大长度,如果值太小,会出现错误,导致监控文件不准确
  • max_user_watches:要知道同步的文件包含的目录数,可以用:
    [root@localhost]# find /home/rain -type d|wc -l 统计,必须保证参数值大于统计结果(/home/tan/uploadFile/为同步文件目录)。

六、创建实时监控脚本 (file 里面放的需要监听的目录)

[root@localhost shell]# vi inotify.sh
/usr/local/inotify/bin/inotifywait -mrq -e modify,create,move,delete --fromfile '/root/shell/file' --timefmt '%y-%m-%d %H:%M' --format '%T %w%f %e' --outfile '/home/tan/inotify.log'
[root@localhost shell]# vi file 

/home/tan
@/home/tan/uploadFile

inotifywait常用参数:

  • –timefmt 时间格式
  • %y年 %m月 %d日 %H小时 %M分钟
  • –format 输出格式
  • %T时间 %w路径 %f文件名 %e状态
  • -m 始终保持监听状态,默认触发事件即退出。
  • -r 递归查询目录
  • -q 打印出监控事件
  • -e 定义监控的事件,可用参数:
  • open 打开文件
  • access 访问文件
  • modify 修改文件
  • delete 删除文件
  • create 新建文件
  • attrb 属性变更
事件  描述

access  访问,读取文件。
modify  修改,文件内容被修改。
attrib  属性,文件元数据被修改。
move    移动,对文件进行移动操作。
create  创建,生成新文件
open    打开,对文件进行打开操作。
close   关闭,对文件进行关闭操作。
delete  删除,文件被删除。

七:实例操作

1、首先启动监听脚本,权限问题的话先:chmod 755 inotify.sh

[root@localhost shell]# ./inotify.sh

我在监听的目录中上传文件,没截图,自己想象吧

[root@localhost tan]# cat inotify.log 
18-01-19 15:07 /home/tan/uploadfile/test//ssh.txt CREATE
18-01-19 15:13 /home/tan/uploadfile/test/QQ20180119143826.png CREATE

这里可以看到打印的日志了。

八、附

1、inotifywait

使用方法和参数说明: 使用命令help就行

[root@localhost bin]# ./inotifywait -h
inotifywait 3.14
Wait for a particular event on a file or set of files.
Usage: inotifywait [ options ] file1 [ file2 ] [ file3 ] [ ... ]
Options:
        -h|--help       Show this help text.
        @<file>         Exclude the specified file from being watched.
        --exclude <pattern>
                        Exclude all events on files matching the
                        extended regular expression <pattern>.
        --excludei <pattern>
                        Like --exclude but case insensitive.
        -m|--monitor    Keep listening for events forever.  Without
                        this option, inotifywait will exit after one
                        event is received.
        -d|--daemon     Same as --monitor, except run in the background
                        logging events to a file specified by --outfile.
                        Implies --syslog.
        -r|--recursive  Watch directories recursively.
        --fromfile <file>
                        Read files to watch from <file> or `-' for stdin.
        -o|--outfile <file>
                        Print events to <file> rather than stdout.
        -s|--syslog     Send errors to syslog rather than stderr.
        -q|--quiet      Print less (only print events).
        -qq             Print nothing (not even events).
        --format <fmt>  Print using a specified printf-like format
                        string; read the man page for more details.
        --timefmt <fmt> strftime-compatible format string for use with
                        %T in --format string.
        -c|--csv        Print events in CSV format.
        -t|--timeout <seconds>
                        When listening for a single event, time out after
                        waiting for an event for <seconds> seconds.
                        If <seconds> is 0, inotifywait will never time out.
        -e|--event <event1> [ -e|--event <event2> ... ]
                Listen for specific event(s).  If omitted, all events are 
                listened for.

Exit status:
        0  -  An event you asked to watch for was received.
        1  -  An event you did not ask to watch for was received
              (usually delete_self or unmount), or some error occurred.
        2  -  The --timeout option was given and no events occurred
              in the specified interval of time.

Events:
        access          file or directory contents were read
        modify          file or directory contents were written
        attrib          file or directory attributes changed
        close_write     file or directory closed, after being opened in
                        writeable mode
        close_nowrite   file or directory closed, after being opened in
                        read-only mode
        close           file or directory closed, regardless of read/write mode
        open            file or directory opened
        moved_to        file or directory moved to watched directory
        moved_from      file or directory moved from watched directory
        move            file or directory moved to or from watched directory
        create          file or directory created within watched directory
        delete          file or directory deleted within watched directory
        delete_self     file or directory was deleted
        unmount         file system containing file or directory unmounted

2、inotifywatch

使用方法和参数说明:

[root@localhost bin]# ./inotifywatch -h
inotifywatch 3.14
Gather filesystem usage statistics using inotify.
Usage: inotifywatch [ options ] file1 [ file2 ] [ ... ]
Options:
        -h|--help       Show this help text.
        -v|--verbose    Be verbose.
        @<file>         Exclude the specified file from being watched.
        --fromfile <file>
                Read files to watch from <file> or `-' for stdin.
        --exclude <pattern>
                Exclude all events on files matching the extended regular
                expression <pattern>.
        --excludei <pattern>
                Like --exclude but case insensitive.
        -z|--zero
                In the final table of results, output rows and columns even
                if they consist only of zeros (the default is to not output
                these rows and columns).
        -r|--recursive  Watch directories recursively.
        -t|--timeout <seconds>
                Listen only for specified amount of time in seconds; if
                omitted or 0, inotifywatch will execute until receiving an
                interrupt signal.
        -e|--event <event1> [ -e|--event <event2> ... ]
                Listen for specific event(s).  If omitted, all events are 
                listened for.
        -a|--ascending <event>
                Sort ascending by a particular event, or `total'.
        -d|--descending <event>
                Sort descending by a particular event, or `total'.

Exit status:
        0  -  Exited normally.
        1  -  Some error occurred.

Events:
        access          file or directory contents were read
        modify          file or directory contents were written
        attrib          file or directory attributes changed
        close_write     file or directory closed, after being opened in
                        writeable mode
        close_nowrite   file or directory closed, after being opened in
                        read-only mode
        close           file or directory closed, regardless of read/write mode
        open            file or directory opened
        moved_to        file or directory moved to watched directory
        moved_from      file or directory moved from watched directory
        move            file or directory moved to or from watched directory
        create          file or directory created within watched directory
        delete          file or directory deleted within watched directory
        delete_self     file or directory was deleted
        unmount         file system containing file or directory unmounted

在 RHEL/CentOS 系统上使用 YUM history 命令回滚升级操作

为服务器打补丁是 Linux 系统管理员的一项重要任务,为的是让系统更加稳定,性能更加优化。厂商经常会发布一些安全/高危的补丁包,相关软件需要升级以防范潜在的安全风险。

Yum (Yellowdog Update Modified) 是 CentOS 和 RedHat 系统上用的 RPM 包管理工具,yum history 命令允许系统管理员将系统回滚到上一个状态,但由于某些限制,回滚不是在所有情况下都能成功,有时 yum 命令可能什么都不做,有时可能会删掉一些其他的包。

我建议你在升级之前还是要做一个完整的系统备份,而 yum history 并不能用来替代系统备份的。系统备份能让你将系统还原到任意时候的节点状态。

某些情况下,安装的应用程序在升级了补丁之后不能正常工作或者出现一些错误(可能是由于库不兼容或者软件包升级导致的),那该怎么办呢?

与应用开发团队沟通,并找出导致库和软件包的问题所在,然后使用 yum history 命令进行回滚。

注意:

  • 它不支持回滚 selinux,selinux-policy-*,kernel,glibc (以及依赖 glibc 的包,比如 gcc)。
  • 不建议将系统降级到更低的版本(比如 CentOS 6.9 降到 CentOS 6.8),这会导致系统处于不稳定的状态
    让我们先来看看系统上有哪些包可以升级,然后挑选出一些包来做实验。
#yum update
Loaded plugins: fastestmirror, security
Setting up UpdateProcess
Loading mirror speeds from cached hostfile
epel/metalink |12 kB 00:00
* epel: mirror.csclub.uwaterloo.ca
base |3.7 kB 00:00
dockerrepo |2.9 kB 00:00
draios |2.9 kB 00:00
draios/primary_db |13 kB 00:00
epel |4.3 kB 00:00
epel/primary_db |5.9 MB 00:00
extras |3.4 kB 00:00
updates |3.4 kB 00:00
updates/primary_db |2.5 MB 00:00
ResolvingDependencies
-->Running transaction check
--->Packagegit.x86_64 0:1.7.1-8.el6 will be updated
--->Packagegit.x86_64 0:1.7.1-9.el6_9 will be an update
--->Package httpd.x86_64 0:2.2.15-60.el6.centos.4 will be updated
--->Package httpd.x86_64 0:2.2.15-60.el6.centos.5 will be an update
--->Package httpd-tools.x86_64 0:2.2.15-60.el6.centos.4 will be updated
--->Package httpd-tools.x86_64 0:2.2.15-60.el6.centos.5 will be an update
--->Package perl-Git.noarch 0:1.7.1-8.el6 will be updated
--->Package perl-Git.noarch 0:1.7.1-9.el6_9 will be an update
-->FinishedDependencyResolution
DependenciesResolved
=================================================================================================
PackageArchVersionRepositorySize
=================================================================================================
Updating:
git x86_64 1.7.1-9.el6_9 updates 4.6 M
httpd x86_64 2.2.15-60.el6.centos.5 updates 836 k
httpd-tools x86_64 2.2.15-60.el6.centos.5 updates 80 k
perl-Git noarch 1.7.1-9.el6_9 updates 29 k
TransactionSummary
=================================================================================================
Upgrade4Package(s)
Total download size:5.5 M
Isthis ok [y/N]: n

你会发现 git 包可以被升级,那我们就用它来实验吧。运行下面命令获得软件包的版本信息(当前安装的版本和可以升级的版本)。

#yumlistgit
Loaded plugins: fastestmirror, security
Setting up UpdateProcess
Loading mirror speeds from cached hostfile
* epel: mirror.csclub.uwaterloo.ca
InstalledPackages
git.x86_64 1.7.1-8.el6@base
AvailablePackages
git.x86_64 1.7.1-9.el6_9 updates

运行下面命令来将 git 从 1.7.1-8 升级到 1.7.1-9。

#yum update git
Loaded plugins: fastestmirror, presto
Setting up UpdateProcess
Loading mirror speeds from cached hostfile
* base: repos.lax.quadranet.com
* epel: Fedora.mirrors.pair.com
* extras: mirrors.seas.harvard.edu
* updates: mirror.sesp.northwestern.edu
ResolvingDependencies
-->Running transaction check
--->Packagegit.x86_64 0:1.7.1-8.el6 will be updated
-->ProcessingDependency:git=1.7.1-8.el6forpackage: perl-Git-1.7.1-8.el6.noarch
--->Packagegit.x86_64 0:1.7.1-9.el6_9 will be an update
-->Running transaction check
--->Package perl-Git.noarch 0:1.7.1-8.el6 will be updated
--->Package perl-Git.noarch 0:1.7.1-9.el6_9 will be an update
-->FinishedDependencyResolution
DependenciesResolved
=================================================================================================
PackageArchVersionRepositorySize
=================================================================================================
Updating:
git x86_64 1.7.1-9.el6_9 updates 4.6 M
Updatingfor dependencies:
perl-Git noarch 1.7.1-9.el6_9 updates 29 k
TransactionSummary
=================================================================================================
Upgrade2Package(s)
Total download size:4.6 M
Isthis ok [y/N]: y
DownloadingPackages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download:4.6 M
(1/2):git-1.7.1-9.el6_9.x86_64.rpm |4.6 MB 00:00
(2/2): perl-Git-1.7.1-9.el6_9.noarch.rpm |29 kB 00:00
-------------------------------------------------------------------------------------------------
Total5.8 MB/s |4.6 MB 00:00
Running rpm_check_debug
RunningTransactionTest
TransactionTestSucceeded
RunningTransaction
Updating: perl-Git-1.7.1-9.el6_9.noarch1/4
Updating:git-1.7.1-9.el6_9.x86_64 2/4
Cleanup: perl-Git-1.7.1-8.el6.noarch3/4
Cleanup:git-1.7.1-8.el6.x86_64 4/4
Verifying:git-1.7.1-9.el6_9.x86_64 1/4
Verifying: perl-Git-1.7.1-9.el6_9.noarch2/4
Verifying:git-1.7.1-8.el6.x86_64 3/4
Verifying: perl-Git-1.7.1-8.el6.noarch4/4
Updated:
git.x86_64 0:1.7.1-9.el6_9
DependencyUpdated:
perl-Git.noarch 0:1.7.1-9.el6_9
Complete!

验证升级后的 git 版本.

#yumlistgit
InstalledPackages
git.x86_64 1.7.1-9.el6_9@updates
或
# rpm -q git
git-1.7.1-9.el6_9.x86_64

现在我们成功升级这个软件包,可以对它进行回滚了。步骤如下。

使用 YUM history 命令回滚升级操作

首先,使用下面命令获取 yum 操作的 id。下面的输出很清晰地列出了所有需要的信息,例如操作 id、谁做的这个操作(用户名)、操作日期和时间、操作的动作(安装还是升级)、操作影响的包数量。

#yum history
或
#yum history list all
Loaded plugins: fastestmirror, presto
ID |Login user |Dateandtime|Action(s)|Altered
-------------------------------------------------------------------------------
13| root |2017-08-1813:30|Update|2
12| root |2017-08-1007:46|Install|1
11| root |2017-07-2817:10| E, I, U |28 EE
10| root |2017-04-2109:16| E, I, U |162 EE
9| root |2017-02-0917:09| E, I, U |20 EE
8| root |2017-02-0210:45|Install|1
7| root |2016-12-1506:48|Update|1
6| root |2016-12-1506:43|Install|1
5| root |2016-12-0210:28| E, I, U |23 EE
4| root |2016-10-2805:37| E, I, U |13 EE
3| root |2016-10-1812:53|Install|1
2| root |2016-09-3010:28| E, I, U |31 EE
1| root |2016-07-2611:40| E, I, U |160 EE

上面命令显示有两个包受到了影响,因为 git 还升级了它的依赖包 perl-Git。 运行下面命令来查看关于操作的详细信息。

#yum history info13
Loaded plugins: fastestmirror, presto
Transaction ID :13
Begintime:FriAug1813:30:522017
Begin rpmdb :420:f5c5f9184f44cf317de64d3a35199e894ad71188
Endtime:13:30:542017(2 seconds)
End rpmdb :420:d04a95c25d4526ef87598f0dcaec66d3f99b98d4
User: root
Return-Code:Success
CommandLine: update git
Transaction performed with:
Installed rpm-4.8.0-55.el6.x86_64 @base
Installedyum-3.2.29-81.el6.centos.noarch @base
Installedyum-plugin-fastestmirror-1.1.30-40.el6.noarch@base
Installedyum-presto-0.6.2-1.el6.noarch@anaconda-CentOS-201207061011.x86_64/6.3
PackagesAltered:
Updatedgit-1.7.1-8.el6.x86_64 @base
Update1.7.1-9.el6_9.x86_64 @updates
Updated perl-Git-1.7.1-8.el6.noarch@base
Update1.7.1-9.el6_9.noarch@updates
history info

运行下面命令来回滚 git 包到上一个版本。

#yum history undo 13
Loaded plugins: fastestmirror, presto
Undoing transaction 53,fromFriAug1813:30:522017
Updatedgit-1.7.1-8.el6.x86_64 @base
Update1.7.1-9.el6_9.x86_64 @updates
Updated perl-Git-1.7.1-8.el6.noarch@base
Update1.7.1-9.el6_9.noarch@updates
Loading mirror speeds from cached hostfile
* base: repos.lax.quadranet.com
* epel: fedora.mirrors.pair.com
* extras: repo1.dal.innoscale.net
* updates: mirror.vtti.vt.edu
ResolvingDependencies
-->Running transaction check
--->Packagegit.x86_64 0:1.7.1-8.el6 will be a downgrade
--->Packagegit.x86_64 0:1.7.1-9.el6_9 will be erased
--->Package perl-Git.noarch 0:1.7.1-8.el6 will be a downgrade
--->Package perl-Git.noarch 0:1.7.1-9.el6_9 will be erased
-->FinishedDependencyResolution
DependenciesResolved
=================================================================================================
PackageArchVersionRepositorySize
=================================================================================================
Downgrading:
git x86_64 1.7.1-8.el6 base 4.6 M
perl-Git noarch 1.7.1-8.el6 base 29 k
TransactionSummary
=================================================================================================
Downgrade2Package(s)
Total download size:4.6 M
Isthis ok [y/N]: y
DownloadingPackages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download:4.6 M
(1/2):git-1.7.1-8.el6.x86_64.rpm |4.6 MB 00:00
(2/2): perl-Git-1.7.1-8.el6.noarch.rpm |29 kB 00:00
-------------------------------------------------------------------------------------------------
Total3.4 MB/s |4.6 MB 00:01
Running rpm_check_debug
RunningTransactionTest
TransactionTestSucceeded
RunningTransaction
Installing: perl-Git-1.7.1-8.el6.noarch1/4
Installing:git-1.7.1-8.el6.x86_64 2/4
Cleanup: perl-Git-1.7.1-9.el6_9.noarch3/4
Cleanup:git-1.7.1-9.el6_9.x86_64 4/4
Verifying:git-1.7.1-8.el6.x86_64 1/4
Verifying: perl-Git-1.7.1-8.el6.noarch2/4
Verifying:git-1.7.1-9.el6_9.x86_64 3/4
Verifying: perl-Git-1.7.1-9.el6_9.noarch4/4
Removed:
git.x86_64 0:1.7.1-9.el6_9 perl-Git.noarch 0:1.7.1-9.el6_9
Installed:
git.x86_64 0:1.7.1-8.el6 perl-Git.noarch 0:1.7.1-8.el6
Complete!

回滚后,使用下面命令来检查降级包的版本。

#yumlistgit
或
# rpm -q git
git-1.7.1-8.el6.x86_64

使用YUM downgrade 命令回滚升级

此外,我们也可以使用 YUM downgrade 命令回滚升级。

#yum downgrade git-1.7.1-8.el6 perl-Git-1.7.1-8.el6
Loaded plugins: search-disabled-repos, security, ulninfo
Setting up DowngradeProcess
ResolvingDependencies
-->Running transaction check
--->Packagegit.x86_64 0:1.7.1-8.el6 will be a downgrade
--->Packagegit.x86_64 0:1.7.1-9.el6_9 will be erased
--->Package perl-Git.noarch 0:1.7.1-8.el6 will be a downgrade
--->Package perl-Git.noarch 0:1.7.1-9.el6_9 will be erased
-->FinishedDependencyResolution
DependenciesResolved
=================================================================================================
PackageArchVersionRepositorySize
=================================================================================================
Downgrading:
git x86_64 1.7.1-8.el6 base 4.6 M
perl-Git noarch 1.7.1-8.el6 base 29 k
TransactionSummary
=================================================================================================
Downgrade2Package(s)
Total download size:4.6 M
Isthis ok [y/N]: y
DownloadingPackages:
(1/2):git-1.7.1-8.el6.x86_64.rpm |4.6 MB 00:00
(2/2): perl-Git-1.7.1-8.el6.noarch.rpm |28 kB 00:00
-------------------------------------------------------------------------------------------------
Total3.7 MB/s |4.6 MB 00:01
Running rpm_check_debug
RunningTransactionTest
TransactionTestSucceeded
RunningTransaction
Installing: perl-Git-1.7.1-8.el6.noarch1/4
Installing:git-1.7.1-8.el6.x86_64 2/4
Cleanup: perl-Git-1.7.1-9.el6_9.noarch3/4
Cleanup:git-1.7.1-9.el6_9.x86_64 4/4
Verifying:git-1.7.1-8.el6.x86_64 1/4
Verifying: perl-Git-1.7.1-8.el6.noarch2/4
Verifying:git-1.7.1-9.el6_9.x86_64 3/4
Verifying: perl-Git-1.7.1-9.el6_9.noarch4/4
Removed:
git.x86_64 0:1.7.1-9.el6_9 perl-Git.noarch 0:1.7.1-9.el6_9
Installed:
git.x86_64 0:1.7.1-8.el6 perl-Git.noarch 0:1.7.1-8.el6
Complete!

注意: 你也需要降级依赖包,否则它会删掉当前版本的依赖包而不是对依赖包做降级,因为 downgrade 命令无法处理依赖关系。

至于 Fedora 用户

命令是一样的,只需要将包管理器名称从 yum 改成 dnf 就行了。

# dnf listgit
# dnf history
# dnf history info
# dnf history undo
# dnf listgit
# dnf downgrade git-1.7.1-8.el6 perl-Git-1.7.1-8.el6

CentOS/Linux下设置IP地址

CentOS/Linux下设置IP地址

1、临时修改

1.1 修改IP地址

# ifconfig eth0 192.168.100.100

1.2 修改网关地址

# route add default gw 192.168.100.1 dev eth0

1.3 修改DNS

# echo “nameserver 8.8.8.8” >> /etc/resolv.conf

这个时候就可以上网了,上网的IP地址为192.168.100.100,网关地址为192.168.100.1。但是这样的设置是临时性的,一旦重启网卡或者重启服务器,除了1.3的操作其他均会被还原,这样的方式只适合临时IP修改,想要永久性修改网卡配置文件,就需要修改相应的文件

2、永久性修改

2.1 修改IP地址

修改/etc/sysconfig/network-scripts/ifcfg-eth0文件,如果有多张网卡,则修改相应的网卡

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0 #网卡对应的设备别名
BOOTPROTO=static #网卡获得ip地址的方式(默认为dhcp,表示自动获取)
HWADDR=00:07:E9:05:E8:B4 #网卡MAC地址(物理地址)
IPADDR=192.168.100.100 #IP地址
NETMASK=255.255.255.0 #子网掩码
ONBOOT=yes #系统启动时是否激活此设备

2.2 修改网关地址

修改/etc/sysconfig/network文件

# vi /etc/sysconfig/network

NETWORKING=yes #表示系统是否使用网络,no表示不能使用网络
HOSTNAME=doiido #设置本机的主机名,要和/etc/hosts中设置的主机名相同
GATEWAY=192.168.100.1 #设置网关的IP地址
这个时候已经可以ping通IP地址,但是还无法ping通域名,因此需要修改DNS

2.3 修改DNS

修改/etc/resolv.conf文件

# vi /etc/resolv.conf

nameserver 8.8.8.8 #google域名服务器
nameserver 114.144.114.114 #国内域名服务器

2.4 重启网卡

# service network restart

正在关闭接口 eth0: [确定]
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 eth0: [确定]

这个时候,系统就可以正常的上网了

#注:其实网关地址和DNS也是可以写在ifcfg-eth0中,但是为了规范起见,将他们分开写

CentOS 7安装网站环境,以及远程连接MariaDB

vps安装了CentOS 7系统,需要安装网站环境,包括php7+Apache+MariaDB,以及远程连接MariaDB。

一、准备部分

首先我们需要先打开默认的80端口,然后重启防火墙:

firewall-cmd –zone=public –add-port=80/tcp –permanent

systemctl restart firewalld.service

接下来,更新源中的软件:

yum update

到此,准备工作完成。

二、安装Apache

yum install httpd httpd-devel

一条命令就搞定了。

还有几条相关的命令需要注意,特别是开机自启动,一定要记得设置。

systemctl start httpd.service #启动apache

systemctl stop httpd.service #停止apache

systemctl restart httpd.service #重启apache

systemctl enable httpd.service #设置apache开机启动

启动Apache服务器,之前已经开启80端口,直接访问ip地址,成功显示如下:

未分类

三、安装数据库

Centos7中已经使用MariaDB替代MySQL,原因是MySQL已经被甲骨文收购,存在闭源的风险,所以作为开源的系统,为了避免不必要的麻烦,开始使用MariaDB。用户不必担心MariaDB没用过不会用的尴尬,MariaDB数据库基本上可以做到无缝兼容MySQL。下面开始安装MariaDB数据库:

yum install mariadb-server

MariaDB数据库默认root密码为空,安全起见,我们给root设置一个密码:

systemctl start mariadb.service

/usr/bin/mysql_secure_installation

接下来,将通过问答的形式进行安全设置。

首先,需要输入当前的root密码:

Enter current password for root (enter for none):

初次使用,默认密码为空,直接回车下一步。

Set root password? [Y/n]

顾名思义,设置root密码,y表示yes,n表示no,默认yes,所以可以直接回车,然后提示我们设置密码,和确认密码,输入两次即可。一定要记得自己设置的密码。

接下来,还有一些其他设置。

Remove anonymous users? [Y/n]

是否禁止匿名用户,默认选项是yes,建议默认设置,回车继续。

Disallow root login remotely? [Y/n]

是否禁止root用户远程登录。如果只在本机内访问MariaDB,建议默认设置,回车继续。如果还需要其他云主机,或者还需要使用数据库远程连接软件进行连接,则需要选择n。

Remove test database and access to it? [Y/n]

是否删除测试数据库和权限。建议默认设置,回车继续。

Reload privilege tables now? [Y/n]

是否重新加载权限表,建议默认设置,回车继续。

到此,数据库安装完成,最后一步,设置开机启动:

systemctl enable mariadb

可能会用到的一些命令:

systemctl start mariadb.service #启动MariaDB

systemctl stop mariadb.service #停止MariaDB

systemctl restart mariadb.service #重启MariaDB

systemctl enable mariadb.service #设置开机启动

四、安装PHP

虽然PHP7已经发布很久了,性能上进步很大,所以我们选择安装PHP7。

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm   –force –nodeps

yum install php70w

还需要安装一些扩展:

yum install php70w-mysql php70w-gd php70w-imap php70w-ldap php70w-odbc php70w-pear php70w-xml php70w-xmlrpc php70w-mbstring php70w-devel

安装完成!接下来进行测试。

vi /var/www/html/test.php

打开test.php文件,如果没有会自动创建一个,按i字母进入编辑模式,输入下面的内容:

<?php

phpinfo();

?>

编辑完,按Esc键退出编辑模式,并输入:wq,敲击回车保存并退出。

然后打开浏览器,输入:你的ip/test.php,看看是否显示PHP的相关信息。

如果没有成功访问,可以试试重启Apache试试。

五、远程连接MariaDB数据库

我个人习惯用navicat管理数据库,所以需要远程连接数据库,前面数据库相关设置中有一项“是否禁止root用户远程登录”,如果像我一样有这个需要,那么就需要选择n。

仅仅是选择n还是不够的,因为我们还需要给数据库开放一个端口,一般我们默认的端口是3306,按照之前开放80端口,我们再开放一个3306端口给数据库,然后再重启防火墙:

firewall-cmd –zone=public –add-port=3306/tcp –permanent

systemctl restart firewalld.service

至此,所有安装设置都完成了。

CentOS 7搭建LAMP (非一键安装)

因为工作原因需要搭建一个zabbix服务器用来做监控,而zabbix是需要lamp或lnmp环境的。
现在网上一键搞定lamp/lnmp的教程很多,用起来也真的很方便,但是对于初学linux的人(比如说我)就有点儿云里雾里,不知道究竟做了什么?有点儿像windows下你安装一个软件只需要下一步下一步就可以了。
虽然便捷,但不适合新手去操作,一步一步的安装并成功才是真的有成就感,这也是学习的原动力。
废话不多说,网上各种各样的资料也很齐全,只把自己验证过的步骤写出来,能帮到大家最好,也可以给自己写下一备忘文档。

LAMP顾名思义就是Linux Apache Mysql PHP的缩写。
英文版原帖在此:https://www.howtoforge.com/apache_php_mysql_on_centos_7_lamp
有兴趣的朋友可以去看一下。

环境:CentOS 7

未分类

废话不多说,开干!

一、安装CentOS7, 少侠先把你的Linux装起来,LAMP的第一步。

(本次安装都在root权限下进行!!!)

二、安装Apache

1、yum的方式安装:

#yum -y install httpd

2、开启Apache服务:

#systemctl start httpd.service

3、设置Apache服务开机启动

#systemctl enable httpd.service

4、验证Apache服务是否安装成功。
在本机浏览器中输入地址IP地址,ip地址的查看方式

#ifconfig

如果你是用ssh的方式连接你的linux,而服务器在同一个局域网的情况下无法访问,那么请把CentOS的Firewall关闭或打开80和443端口。

#firewall-cmd --permanent --zone=public --add-service=http
#firewall-cmd --permanent --zone=public --add-service=https
#firewall-cmd --reload

此时Apache应该已经可以访问了,如果看到Apache默认页面 有Testing123….字样的话就是安装成功了。

未分类

三、安装PHP

1、安装

#yum -y install php

2、重启Apache服务

#systemctl restart httpd

然后写一个php文件在浏览器中运行一下

#vi /var/www/html/info.php

这是一个新建的php文件,按“i“ 插入以下内容

<?php phpinfo(); ?>

按ECS

:wq

保存退出
然后,在自己电脑浏览器中输入192.168.2.112/info.php
运行后会出现php的一些信息。

未分类

四、安装MySQL

MySQL在CentOS 7里是Mariadb。

1、安装

#yum -y install mariadb*

(这里我看到的教程是不加*的,所以导致我卡在这里卡了好久,有一些相关的东西没有安装上,我在后面的步骤中无法进行下去,后来排错半天加上星号之后问题解决。)

2、开启MySQL服务并设置开机启动

#systemctl start mariadb.service
#systemctl enable mariadb.service

未分类

3、设置root账户的密码

#mysql_secure_installation

这里会跳出一段英文,英文好的同学可以仔细的阅读以下,如果懒得读久在提示出来后按Enter就好了,设置密码时输入自己想设置的密码就可以,然后继续再让你选择y/n时,Enter就好。

未分类

当一切结束的时候,输入#mysql -uroot -p的方式验证一下。

未分类

未分类

五、将PHP和MySQL关联起来

#yum search php

未分类

选择你需要的安装:

#yum -y install php-mysql

未分类

六、安装常用的PHP模块。

包括GD库,Curl,mbstring等等…..

#yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel

然后重启Apach服务

#systemctl restart httpd.service

然后,再次再浏览器中运行info.php。你会看到安装的模块的信息,这就表示你的LAMP就搭建好了。

未分类

至此,完毕。

Grafana 4.x 安装部署(CentOS 7)

一、前言

本篇适用范围

  • CentOS 7+
  • InfluxDB 4.x

环境信息

  • CentOS 7
  • InfluxDB 4.6.3

二、安装

  • 安装
sudo yum install https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.6.3-1.x86_64.rpm
  • 启动服务并设置为开机启动
#启动Grafana服务
sudo systemctl start grafana-server
sudo systemctl status grafana-server

#将Grafana服务设置为开机启动
sudo systemctl enable grafana-server
  • 防火墙配置
#开放端口
firewall-cmd --add-port=3000/tcp --permanent

#重载防火墙配置
firewall-cmd --reload
  • 访问测试
http://<ip>:3000

如果出现登录页面则正常。

未分类

默认管理账号;admin,密码:admin

三、备注

  • 延伸阅读

Grafana + InfluxDB数据源以及曲线图表仪表盘配置:https://ken.io/note/grafana-quickstart-influxdb-datasource-graph

  • 本文参考

http://docs.grafana.org/installation/rpm/