mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
commit
95b88da548
@ -1,45 +0,0 @@
|
||||
Daily Ubuntu Tips – Do Nothing When Laptop Lid Is Closed
|
||||
================================================================================
|
||||
Ubuntu, a powerful and modern operation system is being used by millions of individual users and businesses around the world. From basic workstation to advanced engineering machines, Ubuntu is powering them all.
|
||||
|
||||
If you’re just started out with Ubuntu and need help working with it, keeping coming to this blog for help. We’ve written hundreds of posts on Ubuntu that will get you started.
|
||||
|
||||
From learning how install Ubuntu to configuring basic settings, we’ve have covered all.
|
||||
|
||||
This brief tutorial is going to show you how to configure Ubuntu on a laptop computer so that when the lid is closed, it doesn’t put the computer to sleep or shut it down.
|
||||
|
||||
Most modern operating systems, including Windows is designed to put the laptop to sleep when the lid is closed. Ubuntu also does this. If you only want to close the lid and not put your laptop to sleep, continue below to learn how to do it in Ubuntu.
|
||||
|
||||
There are two ways to go about making this work in Ubuntu. One way is to open **System Settings –> Power** and setting the options there. Some users have had issues where doing it from System Settings didn’t work.
|
||||
|
||||
Another option is go change the settings from the configuration file of the Login Manager (**logind.conf**). Using this method has worked for many and you should try it as well.
|
||||
|
||||
To get started, press **Ctrl – Alt – T** on your keyboard to open the terminal. When it opens, run the commands below to open logind.conf file. There this file is where you’ll make this change.
|
||||
|
||||
sudo gedit /etc/systemd/logind.conf
|
||||
|
||||
When the file opens, modify or change line line from this:
|
||||
|
||||
#HandleLidSwitch=suspend
|
||||
|
||||
To this:
|
||||
|
||||
HandleLidSwitch=ignore
|
||||
|
||||
And save the file. After saving the file, run the commands below to reset the Login Manager.
|
||||
|
||||
sudo restart systemd-logind
|
||||
|
||||
That’s it!
|
||||
|
||||
The ignore value tell Ubuntu not to sleep or hibernate when the laptop lid is closed. Leave the rest of the line intact and save the file.
|
||||
|
||||
![](http://www.liberiangeek.net/wp-content/uploads/2013/12/photo.jpg)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.liberiangeek.net/2013/12/daily-ubuntu-tips-do-nothing-when-laptop-lid-is-closed/
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
@ -1,112 +0,0 @@
|
||||
How to set password policy on Linux
|
||||
================================================================================
|
||||
User account management is one of the most critical jobs of system admins. In particular, password security should be considered the top concern for any secure Linux system. In this tutorial, I will describe **how to set password policy on Linux**.
|
||||
|
||||
I assume that you are using [PAM (Pluggable Authentication Modules)][1] on your Linux system, which is the case on all recent Linux distros.
|
||||
|
||||
### Preparation ###
|
||||
|
||||
Install PAM module to enable cracklib support, which can provide additional password checking capabilities.
|
||||
|
||||
On Debian, Ubuntu or Linux Mint:
|
||||
|
||||
$ sudo apt-get install libpam-cracklib
|
||||
|
||||
The cracklib PAM module is installed by default on CentOS, Fedora, or RHEL. So no further installation is necessary on those systems.
|
||||
|
||||
To enforce password policy, we need to modify PAM configuration file located at /etc/pam.d. Policy change will take effect immediately after change.
|
||||
|
||||
Note that the password rules presented in this tutorial will be enforced only when non-root users change passwords, but not the root.
|
||||
|
||||
### Prevent Reusing Old Passwords ###
|
||||
|
||||
Look for a line that contains both "password" and "pam_unix.so", and append "remember=5" to that line. It will prevent five most recently used passwords (by storing them in /etc/security/opasswd).
|
||||
|
||||
On Debian, Ubuntu or Linux Mint:
|
||||
|
||||
$ sudo vi /etc/pam.d/common-password
|
||||
|
||||
> password [success=1 default=ignore] pam_unix.so obscure sha512 remember=5
|
||||
|
||||
On Fedora, CentOS or RHEL:
|
||||
|
||||
$ sudo vi /etc/pam.d/system-auth
|
||||
|
||||
> password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=5
|
||||
|
||||
### Set Minimum Password Length ###
|
||||
|
||||
Look for a line that contains both "password" and "pam_cracklib.so", and append "minlen=10" to that line. This will enforce a password of length (10 - <# of types>), where <# of types> indicates how many different types of characters are used in the password. There are four types (upper-case, lower-case, numeric, and symbol) of characters. So if you use a combination of all four types, and minlen is set to 10, the shorted password allowed would be 6.
|
||||
|
||||
On Debian, Ubuntu or Linux Mint:
|
||||
|
||||
$ sudo vi /etc/pam.d/common-password
|
||||
|
||||
> password requisite pam_cracklib.so retry=3 minlen=10 difok=3
|
||||
|
||||
On Fedora, CentOS or RHEL:
|
||||
|
||||
$ sudo vi /etc/pam.d/system-auth
|
||||
|
||||
> password requisite pam_cracklib.so retry=3 difok=3 minlen=10
|
||||
|
||||
### Set Password Complexity ###
|
||||
|
||||
Look for a line that contains "password" and "pam_cracklib.so", and append "ucredit=-1 lcredit=-2 dcredit=-1 ocredit=-1" to that line. This will force you to include at least one upper-case letter (ucredit), two lower-case letters (lcredit), one digit (dcredit) and one symbol (ocredit).
|
||||
|
||||
On Debian, Ubuntu or Linux Mint:
|
||||
|
||||
$ sudo vi /etc/pam.d/common-password
|
||||
|
||||
> password requisite pam_cracklib.so retry=3 minlen=10 difok=3 ucredit=-1 lcredit=-2 dcredit=-1 ocredit=-1
|
||||
|
||||
On Fedora, CentOS or RHEL:
|
||||
|
||||
$ sudo vi /etc/pam.d/system-auth
|
||||
|
||||
> password requisite pam_cracklib.so retry=3 difok=3 minlen=10 ucredit=-1 lcredit=-2 dcredit=-1 ocredit=-1
|
||||
|
||||
### Set Password Expiration Period ###
|
||||
|
||||
To set the maximum period of time the current password is valid, edit the following variables in /etc/login.defs.
|
||||
|
||||
$ sudo vi /etc/login.defs
|
||||
|
||||
> PASS_MAX_DAYS 150
|
||||
> PASS_MIN_DAYS 0
|
||||
> PASS_WARN_AGE 7
|
||||
|
||||
This will force every user to change their password once every six months, and send out a warning message seven days prior to password expiration.
|
||||
|
||||
If you want to set password expiration on per-user basis, use chage command instead. To view password expiration policy for a specific user:
|
||||
|
||||
$ sudo chage -l xmodulo
|
||||
|
||||
> Last password change : Dec 30, 2013
|
||||
> Password expires : never
|
||||
> Password inactive : never
|
||||
> Account expires : never
|
||||
> Minimum number of days between password change : 0
|
||||
> Maximum number of days between password change : 99999
|
||||
> Number of days of warning before password expires : 7
|
||||
|
||||
By default, a user's password is set to never expire.
|
||||
|
||||
To change the password expiration period for user xmodulo:
|
||||
|
||||
$ sudo chage -E 6/30/2014 -m 5 -M 90 -I 30 -W 14 xmodulo
|
||||
|
||||
The above command will set the password to expire on 6/30/2014. In addition, the minimum/maximum number of days between password changes is set to 5 and 90 respectively. The account will be locked 30 days after a password expires, and a warning message will be sent out 14 days before password expiration.
|
||||
|
||||
[![](http://farm4.staticflickr.com/3779/11640903324_474963b7bb.jpg)][2]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://xmodulo.com/2013/12/set-password-policy-linux.html
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[1]:http://www.linux-pam.org/
|
||||
[2]:http://www.flickr.com/photos/xmodulo/11640903324/
|
@ -1,125 +0,0 @@
|
||||
How to upgrade MySQL server on Debian or Ubuntu
|
||||
================================================================================
|
||||
One of routine tasks for system admins is to update installed programs with the latest patches and hotfixes, as well as upgrade software to a more recent release with new bells and whistles. The latest MySQL 5.6 was released early this year, targeting [better performance and scalability][1]. For those of you wanting to try out the latest bleeding edge MySQL, I will describe **how to upgrade MySQL server on Debian or Ubuntu**.
|
||||
|
||||
In this tutorial, I assume that you have already [set up MySQL with apt-get][2]. As of this writing, MySQL that ships with major Linux distros is version 5.5. Here I am going to demonstrate how to upgrade MySQL 5.5 to 5.6.
|
||||
|
||||
1.Back up your MySQL config files.
|
||||
|
||||
$ sudo mkdir /backup
|
||||
$ sudo tar cvfvz /backup/mysql_conf.tgz /etc/mysql
|
||||
|
||||
2.Export all databases to a .sql file, and back up MySQL data directory.
|
||||
|
||||
$ sudo sh -c 'mysqldump -u root -p -A --events > /backup/backup_db.sql
|
||||
$ sudo tar cvfvz /backup/mysql_data.tgz /var/lib/mysql
|
||||
|
||||
Note: for a consistent backup of a "live" MySQL system, it is recommended to use a single transaction option or explicit locks on the database, as detailed in [this tutorial][3].
|
||||
|
||||
3.Stop MySQL server.
|
||||
|
||||
$ sudo service mysql stop
|
||||
|
||||
4.Uninstall and remove MySQL packages.
|
||||
|
||||
$ sudo apt-get remove mysql-server mysql-client mysql-common
|
||||
$ sudo apt-get autoremove
|
||||
$ sudo apt-get autoclean
|
||||
|
||||
Do not use "purge" option in apt-get as that would remove MySQL config files and other MySQL related data directories as well, which we will continue to use after MySQL upgrade.
|
||||
|
||||
5.Install MySQL dependency (kernel asynchronous I/O access library) which is needed for MySQL 5.5 and higher.
|
||||
|
||||
$ sudo apt-get install libaio1
|
||||
|
||||
6.Download a MySQL Debian package from the official site.
|
||||
|
||||
On 32-bit system:
|
||||
|
||||
$ wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15-debian6.0-i686.deb
|
||||
|
||||
On 64-bit system:
|
||||
|
||||
$ wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15-debian6.0-x86_64.deb
|
||||
|
||||
7.Install the downloaded MySQL package.
|
||||
|
||||
$ sudo dpkg -i mysql-5.6.15-debian6.0-*.deb
|
||||
|
||||
The MySQL package will be installed under /opt/mysql directory.
|
||||
|
||||
8.Add the MySQL bin directory to the PATH variable system-wide.
|
||||
|
||||
On Debian:
|
||||
|
||||
$ sudo sh -c 'echo "PATH=$PATH:/opt/mysql/server-5.6/bin" >> /etc/profile'
|
||||
$ source /etc/profile
|
||||
|
||||
On Ubuntu or Linux Mint:
|
||||
|
||||
$ sudo sh -c 'echo "PATH=${PATH}:/opt/mysql/server-5.6/bin" >> /etc/environment'
|
||||
$ source /etc/environment
|
||||
|
||||
9.Open the MySQL config file with a text editor, and update the following two entries.
|
||||
|
||||
$ sudo vi /etc/mysql/my.cnf
|
||||
|
||||
> basedir = /opt/mysql/server-5.6
|
||||
> lc-messages-dir = /opt/mysql/server-5.6/share
|
||||
|
||||
10.Copy the MySQL startup script to /etc/init.d and install the script into the boot sequence, so that MySQL server starts up automatically upon boot.
|
||||
|
||||
$ sudo cp /opt/mysql/server-5.6/support-files/mysql.server /etc/init.d/mysql
|
||||
$ sudo update-rc.d mysql defaults
|
||||
|
||||
11.(Ubuntu-only) There is MySQL AppArmor profile created from the previous MySQL installation, which is not compatible with the new MySQL installation. So you need to reconfigure MySQL AppArmor profile so MySQL server can start.
|
||||
|
||||
First, create a symbolic link.
|
||||
|
||||
$ sudo ln -s /opt/mysql/server-5.6/bin/mysqld /usr/sbin/mysqld
|
||||
|
||||
Edit MySQL AppArmor profile.
|
||||
|
||||
$ sudo vi /etc/apparmor.d/usr.sbin.mysqld
|
||||
|
||||
> /opt/mysql/server-5.6/lib/plugin/ r,
|
||||
> /opt/mysql/server-5.6/lib/plugin/*.so* mr,
|
||||
> /opt/mysql/server-5.6/share/** r,
|
||||
|
||||
Reload AppArmor service.
|
||||
|
||||
$ sudo service apparmor restart
|
||||
|
||||
12.(Ubuntu-only) Remove a Upstart configuration for MySQL (which was installed as part of the previous MySQL installation). We will use SysVinit (/etc/init.d/mysql) instead.
|
||||
|
||||
$ sudo rm /etc/init/mysql.conf
|
||||
|
||||
13.Start MySQL server.
|
||||
|
||||
$ sudo service mysql start
|
||||
|
||||
14.Restore MySQL databases.
|
||||
|
||||
$ sudo mysql -u root -p < /backup/backup_db.sql
|
||||
|
||||
15. Finally, upgrade MySQL system tables.
|
||||
|
||||
$ sudo /opt/mysql/server-5.6/bin/mysql_upgrade -v -u root -p
|
||||
|
||||
### Troubleshooting MySQL Upgrade ###
|
||||
|
||||
If MySQL server fails to start with the following error on Ubuntu, this is because the old MySQL AppArmor profile prevents it from launching. To fix the problem, make sure to update the MySQL AppArmor profile as described in step 11.
|
||||
|
||||
Dec 20 19:57:48 ubuntu kernel: [ 5856.960592] type=1400 audit(1387598268.807:39): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=25216 comm="apparmor_parser"
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://xmodulo.com/2013/12/upgrade-mysql-server-debian-ubuntu.html
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[1]:http://dev.mysql.com/tech-resources/articles/whats-new-in-mysql-5.6.html
|
||||
[2]:http://xmodulo.com/2013/06/how-to-install-mysql-server-and-client-on-linux.html
|
||||
[3]:http://xmodulo.com/2012/10/how-to-backup-mysql-server.html
|
@ -0,0 +1,43 @@
|
||||
Ubuntu 一天一课 - 合上笔记本,系统不睡眠
|
||||
================================================================================
|
||||
Ubuntu 是一个处在牛 A 和牛 C 之间的现代操作系统,全世界数百万人和公司都在使用它。无论是充当工作台还是高级工程机器(译者表示不知道 advanced engineering machines 是个什么东西),Ubuntu 都游刃有余。
|
||||
|
||||
如果你是 Ubuntu 初学者,使用过程还需要高手指导,那就关注本博客吧。我们已经写了数百 Ubuntu 教程,足以带你入门。从安装 Ubuntu 到系统基本设置,我们都有涉猎。
|
||||
|
||||
这篇简单的教程为你介绍当笔记本盖子合上时该干嘛还是干嘛,而不是进入睡眠模式或者直接关机。
|
||||
|
||||
很多现代操作系统(包括 Windows)会在笔记本合上时进入睡眠状态。Ubuntu 也是这样做的。如果你想让你的笔记本盖子合上时不睡眠,就跟着我们学习吧。
|
||||
|
||||
要达到这个目的,Ubuntu 有两种方法。第一种是打开 **System Settings –> Power**(中文版是打开 **系统设置 -> 电源**),然后进行设置。一些用户设置后不会生效。
|
||||
|
||||
另一个方法是直接编辑 Login Manager 的配置文件(**logind.conf**)。这个方法基本能生效,你最好用这个。
|
||||
|
||||
要开始了,按下 **Ctrl – Alt – T** 组合键,打开终端。然后运行下面的命令打开 logind.conf 文件。你的所有修改都在这个文件内。
|
||||
|
||||
sudo gedit /etc/systemd/logind.conf
|
||||
|
||||
打开文件后修改下面这行:
|
||||
|
||||
#HandleLidSwitch=suspend
|
||||
|
||||
改成这副德行:
|
||||
|
||||
HandleLidSwitch=ignore
|
||||
|
||||
保存文件,重启 Login Manager 服务:
|
||||
|
||||
sudo restart systemd-logind
|
||||
|
||||
工作完成!
|
||||
|
||||
配置文件的 “ignore” 值告诉 Ubuntu 当笔记本合上后不要睡眠或挂起。不要动其它设置然后保存文件。
|
||||
|
||||
![](http://www.liberiangeek.net/wp-content/uploads/2013/12/photo.jpg)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.liberiangeek.net/2013/12/daily-ubuntu-tips-do-nothing-when-laptop-lid-is-closed/
|
||||
|
||||
译者:[bazz2](https://github.com/bazz2) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
112
translated/How to set password policy on Linux.md
Normal file
112
translated/How to set password policy on Linux.md
Normal file
@ -0,0 +1,112 @@
|
||||
Linux 上的密码设置策略
|
||||
================================================================================
|
||||
用户帐号管理是系统管理员最重要的工作之一。而密码安全是系统安全中最受关注的一块。在本教程中,我将为大家介绍**如何在 Linux 上设置密码策略**。
|
||||
|
||||
假设你已经在你的 Linux 系统上使用了 [PAM (Pluggable Authentication Modules,插入式验证模块)][1],因为这些年所有的 Linux 发行版都在用它。
|
||||
|
||||
### 准备工作 ###
|
||||
|
||||
安装 PAM 模块,获得 cracklib 的支持。cracklib 能提供额外的密码检查能力。
|
||||
|
||||
Debian、Ubuntu 或 Linux Mint 系统上:
|
||||
|
||||
$ sudo apt-get install libpam-cracklib
|
||||
|
||||
CentOS、Fedora、RHEL 系统已经安装了 cracklib PAM 模块,所以在这些系统上无需执行上面的操作。
|
||||
|
||||
为了强制实施密码策略,我们需要修改 /etc/pam.d 目录下的 PAM 配置文件。一旦修改,策略会马上生效。
|
||||
|
||||
注意:此教程中的密码策略只对非 root 用户有效,对 root 用户无效。
|
||||
|
||||
### 禁止使用老的密码 ###
|
||||
|
||||
看下同时有 “password” 和 “pam_unix.so” 字段并且附加有 “remember=5” 的那行,它表示禁止使用最近用过的5个密码(己使用过的密码会被保存在 /etc/security/opasswd 下面)。
|
||||
|
||||
Debian、Ubuntu 或 Linux Mint 系统上:
|
||||
|
||||
$ sudo vi /etc/pam.d/common-password
|
||||
|
||||
> password [success=1 default=ignore] pam_unix.so obscure sha512 remember=5
|
||||
|
||||
CentOS、Fedora、RHEL 系统上:
|
||||
|
||||
$ sudo vi /etc/pam.d/system-auth
|
||||
|
||||
> password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=5
|
||||
|
||||
### 设置最短密码长度 ###
|
||||
|
||||
找到同时有 “password” 和 “pam_cracklib.so” 字段并且附加有 “minlen=10” 的那行,它表示最小密码长度为(10 - <# of types>)。这里的 <# of types> 表示类型数量。PAM 提供4种类型符号作为密码(大写字母、小写字母、数字和标点符号)。如果你的密码同时用上了这4种类型的符号,并且你的 minlen 设为10,那么最短的密码长度允许是6个字符。
|
||||
|
||||
Debian、Ubuntu 或 Linux Mint 系统上:
|
||||
|
||||
$ sudo vi /etc/pam.d/common-password
|
||||
|
||||
> password requisite pam_cracklib.so retry=3 minlen=10 difok=3
|
||||
|
||||
CentOS、Fedora、RHEL 系统上:
|
||||
|
||||
$ sudo vi /etc/pam.d/system-auth
|
||||
|
||||
> password requisite pam_cracklib.so retry=3 difok=3 minlen=10
|
||||
|
||||
### 设置密码复杂度 ###
|
||||
|
||||
找到同时有 “password” 和 “pam_cracklib.so” 字段并且附加有 “ucredit=-1 lcredit=-2 dcredit=-1 ocredit=-1” 的那行,它表示密码必须至少包含一个大写字母(ucredit),两个小写字母(lcredit),一个数字(dcredit)和一个标点符号(ocredit)。
|
||||
|
||||
Debian、Ubuntu 或 Linux Mint 系统上:
|
||||
|
||||
$ sudo vi /etc/pam.d/common-password
|
||||
|
||||
> password requisite pam_cracklib.so retry=3 minlen=10 difok=3 ucredit=-1 lcredit=-2 dcredit=-1 ocredit=-1
|
||||
|
||||
CentOS、Fedora、RHEL 系统上:
|
||||
|
||||
$ sudo vi /etc/pam.d/system-auth
|
||||
|
||||
> password requisite pam_cracklib.so retry=3 difok=3 minlen=10 ucredit=-1 lcredit=-2 dcredit=-1 ocredit=-1
|
||||
|
||||
### 设置密码过期期限 ###
|
||||
|
||||
编辑 /etc/login.defs 文件,可以设置当前密码的有效期限,具体变量如下所示:
|
||||
|
||||
$ sudo vi /etc/login.defs
|
||||
|
||||
> PASS_MAX_DAYS 150
|
||||
> PASS_MIN_DAYS 0
|
||||
> PASS_WARN_AGE 7
|
||||
|
||||
这些设置要求用户每6个月改变他们的密码,并且会提前7天提醒用户密码快到期了。
|
||||
|
||||
如果你想为每个用户设置不同的密码期限,使用 chage 命令。下面的命令可以查看某个用户的密码限期:
|
||||
|
||||
$ sudo chage -l xmodulo
|
||||
|
||||
> Last password change : Dec 30, 2013
|
||||
> Password expires : never
|
||||
> Password inactive : never
|
||||
> Account expires : never
|
||||
> Minimum number of days between password change : 0
|
||||
> Maximum number of days between password change : 99999
|
||||
> Number of days of warning before password expires : 7
|
||||
|
||||
默认情况下,用户的密码永不过期。
|
||||
|
||||
下面的命令用于修改 xmodulo 用户的密码期限:
|
||||
|
||||
$ sudo chage -E 6/30/2014 -m 5 -M 90 -I 30 -W 14 xmodulo
|
||||
|
||||
上面的命令将密码期限设为2014年6月3日。另外,修改密码的最小周期为5天,最长周期为90天。密码过期前14天会提醒用户,过期后帐号会被锁住30天。
|
||||
|
||||
[![](http://farm4.staticflickr.com/3779/11640903324_474963b7bb.jpg)][2]
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://xmodulo.com/2013/12/set-password-policy-linux.html
|
||||
|
||||
译者:[bazz2](https://github.com/bazz2) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[1]:http://www.linux-pam.org/
|
||||
[2]:http://www.flickr.com/photos/xmodulo/11640903324/
|
125
translated/How to upgrade MySQL server on Debian or Ubuntu.md
Normal file
125
translated/How to upgrade MySQL server on Debian or Ubuntu.md
Normal file
@ -0,0 +1,125 @@
|
||||
教你在 Debian 和 Ubuntu 上升级 MySQL
|
||||
================================================================================
|
||||
系统管理员的一个日常任务就是升级服务,为服务打上补丁包或升级一些花哨的功能。今年早些时候,最新的 MySQL 5.6发布,目标是提供[更好的性能和扩展能力][1]。如果你对此有点兴趣,倒是可以看看我写的这篇 **如何在 Debian 和 Ubuntu 上升级 MySQL**。
|
||||
|
||||
在这篇教程中,我会假设你已经[通过 apt-get 安装了 MySQL][2]。写这篇文章的时候,大部分 Linux 发行版上部署的都是 MySQL 5.5。这里我将向你们介绍如何从 MySQL 5.5升级到5.6。
|
||||
|
||||
步骤1:备份 MySQL 配置文件。
|
||||
|
||||
$ sudo mkdir /backup
|
||||
$ sudo tar cvfvz /backup/mysql_conf.tgz /etc/mysql
|
||||
|
||||
步骤2:把数据库导出到一个 .sql 文件,并且把数据存放路径下面的数据也备份起来。
|
||||
|
||||
$ sudo sh -c 'mysqldump -u root -p -A --events > /backup/backup_db.sql
|
||||
$ sudo tar cvfvz /backup/mysql_data.tgz /var/lib/mysql
|
||||
|
||||
注意:如果你为你的在线 MySQL 系统提供了持续备份,强烈建议你在执行上面步骤时使用单事务选项,或显式使用锁(以保证数据一致性 —— 译注),详见[这个教程][3]。
|
||||
|
||||
步骤3:停止 MySQL 服务
|
||||
|
||||
$ sudo service mysql stop
|
||||
|
||||
步骤4:卸载 MySQL 软件包
|
||||
|
||||
$ sudo apt-get remove mysql-server mysql-client mysql-common
|
||||
$ sudo apt-get autoremove
|
||||
$ sudo apt-get autoclean
|
||||
|
||||
使用 apt-get 卸载时不要用 purge 选项,这会删除 MySQL 配置文件和其它一些以后要用到的数据。
|
||||
|
||||
步骤5: 安装 MySQL 依赖包(内核异步 IO 访问库),MySQL 5.5以后都依赖它。
|
||||
|
||||
$ sudo apt-get install libaio1
|
||||
|
||||
步骤6:从官网下载 Debian 版的 MySQL 软件包
|
||||
|
||||
32位系统:
|
||||
|
||||
$ wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15-debian6.0-i686.deb
|
||||
|
||||
64位系统:
|
||||
|
||||
$ wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15-debian6.0-x86_64.deb
|
||||
|
||||
步骤7:安装 MySQL 软件包
|
||||
|
||||
$ sudo dpkg -i mysql-5.6.15-debian6.0-*.deb
|
||||
|
||||
这个软件包会被安装在 /opt/mysql 目录下面。
|
||||
|
||||
步骤8:将 MySQL 命令所在的路径添加到系统环境变量 PATH 内。
|
||||
|
||||
Debian 上:
|
||||
|
||||
$ sudo sh -c 'echo "PATH=$PATH:/opt/mysql/server-5.6/bin" >> /etc/profile'
|
||||
$ source /etc/profile
|
||||
|
||||
Ubuntu 或 Linux Mint 上:
|
||||
|
||||
$ sudo sh -c 'echo "PATH=${PATH}:/opt/mysql/server-5.6/bin" >> /etc/environment'
|
||||
$ source /etc/environment
|
||||
|
||||
步骤9:进入 MySQL 配置文件,修改下面两行配置。
|
||||
|
||||
$ sudo vi /etc/mysql/my.cnf
|
||||
|
||||
> basedir = /opt/mysql/server-5.6
|
||||
> lc-messages-dir = /opt/mysql/server-5.6/share
|
||||
|
||||
步骤10:复制 MySQL 启动脚本到 /etc/init.d 目录下,并且将脚本设置为开机启动,这样一来 MySQL 就能在系统启动的时候自动启动了。
|
||||
|
||||
$ sudo cp /opt/mysql/server-5.6/support-files/mysql.server /etc/init.d/mysql
|
||||
$ sudo update-rc.d mysql defaults
|
||||
|
||||
步骤11:(仅限 Ubuntu) MySQL 的上个版本安装时会为 AppArmor 服务创建一个配置文件,这个文件在 MySQL 卸载后会保留在系统中,但是它与现在安装好的 MySQL 版本不兼容。你需要重新编辑下这个配置文件,然后 MySQL 服务才能正常启动。
|
||||
|
||||
首先,建一个软链接。
|
||||
|
||||
$ sudo ln -s /opt/mysql/server-5.6/bin/mysqld /usr/sbin/mysqld
|
||||
|
||||
然后编辑 MySQL AppArmor 配置文件。
|
||||
|
||||
$ sudo vi /etc/apparmor.d/usr.sbin.mysqld
|
||||
|
||||
> /opt/mysql/server-5.6/lib/plugin/ r,
|
||||
> /opt/mysql/server-5.6/lib/plugin/*.so* mr,
|
||||
> /opt/mysql/server-5.6/share/** r,
|
||||
|
||||
最后重启 AppArmor 服务。
|
||||
|
||||
$ sudo service apparmor restart
|
||||
|
||||
步骤12:(还是仅限 Ubuntu)删除上个 MySQL 版本留下的自启动配置文件,这个版本的 MySQL 使用 SysVinit (就是 /etc/init.d/mysql)来代替。
|
||||
|
||||
$ sudo rm /etc/init/mysql.conf
|
||||
|
||||
步骤13:启动 MySQL 服务。
|
||||
|
||||
$ sudo service mysql start
|
||||
|
||||
步骤14:恢复 MySQL 数据库。
|
||||
|
||||
$ sudo mysql -u root -p < /backup/backup_db.sql
|
||||
|
||||
步骤15:最后,升级 MySQL 系统表。
|
||||
|
||||
$ sudo /opt/mysql/server-5.6/bin/mysql_upgrade -v -u root -p
|
||||
|
||||
### 解决升级过程产生的问题 ###
|
||||
|
||||
如果 Ubuntu 下的 MySQL 服务启动时出现如下错误,就是 AppArmor 服务引起的问题。你需要更新 AppArmor 的配置文件,参考第11步。
|
||||
|
||||
Dec 20 19:57:48 ubuntu kernel: [ 5856.960592] type=1400 audit(1387598268.807:39): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=25216 comm="apparmor_parser"
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://xmodulo.com/2013/12/upgrade-mysql-server-debian-ubuntu.html
|
||||
|
||||
译者:[bazz2](https://github.com/bazz2) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[1]:http://dev.mysql.com/tech-resources/articles/whats-new-in-mysql-5.6.html
|
||||
[2]:http://xmodulo.com/2013/06/how-to-install-mysql-server-and-client-on-linux.html
|
||||
[3]:http://xmodulo.com/2012/10/how-to-backup-mysql-server.html
|
Loading…
Reference in New Issue
Block a user