csatblogspotdotcom

Wednesday, May 17, 2017

关于apt-get安装与pip安装

python的package/lib可以使用python的包管理工具pip安装,也可以通过Linux系统的软件管理工具apt-get等安装,根据经验来说apt-get提供的版本没有pip新(例如安装pip本身,apt-get得到的版本太旧,只能用pip提供的get-pip.py安装),但apt-get比较强大可以安装相关的依赖,库也比较全,一条命令即可,不用操心依赖;pip虽然装的版本新,但缺少相关依赖,需要自己操心依赖,而且有些东西pip并不提供,必须apt-get,例如 tkinter ,参考: https://community.c9.io/t/installing-tkinter-library-in-python-2-7/10931 http://stackoverflow.com/questions/4783810/install-tkinter-for-python 必须 sudo apt-get install python-tk (此命令适用python2;python3需要用python3-tk)

Labels: , ,

Saturday, May 13, 2017

使Ubuntu默认启动进入命令行

Ubuntu 14.04 server,原无GUI,安装gnome之后,默认进入GUI,现需更改默认进入文本模式,进行如下操作:
1. 编辑/etc/default/grub,将 GRUB_CMDLINE_LINUX_DEFAULT="**" 更改为: GRUB_CMDLINE_LINUX_DEFAULT="text";
2. 更新grub: sudo update-grub 。
以后重启便直接进入 text mode 文本模式,如需开启GUI,直接在console运行 startx ,或者在远程(如putty)中运行 sudo startx ,注意 ~/.Xauthority 权限,需要本用户,如果为root,可直接删掉
参考:
https://askubuntu.com/questions/16371/how-do-i-disable-x-at-boot-time-so-that-the-system-boots-in-text-mode

Labels: ,

Wednesday, May 10, 2017

ubuntu server 14.04 安装 图形界面 gnome

Ubuntu server 14.04 安装默认无图形界面,通过如下命令安装gnome图形界面:

sudo apt-get install ubuntu-gnome-desktop(运行前先sudo apt-get update更新源)
安装后是gnome 3

安装ubuntu-gnome-desktop时自动安装相关依赖,包括gnome-shell,以及office软件等等,如需尽量少装其他软件,可用:sudo apt-get install --no-install-recommends ubuntu-gnome-desktop

Labels: ,

Friday, May 5, 2017

关于Python中的引号

Python中,字符串用单引号'或双引号",但有时遇到无法识别字符串等等情况,可以尝试三引号或引号嵌套:
'''****'''
'"****"'
三引号是把全部内容当做文本,引号嵌套可以识别路径中的空格,尤其是Windows中C:\Program Files\ 这些

Labels: , , , ,

Sunday, March 12, 2017

coursera-dl工具介绍

https://www.coursera.org 是在线学习网站,由Stanford University的 Daphne Koller 和 Andrew Ng(吴恩达) 创办,其中的课程比较不错,例如 Daphne Koller 的 Probabilistic Graphical Models,Andrew Ng 的 Machine Learning 不错,两门课程都是AI人工智能相关。课程内容托管在Amazon云服务上,由于大陆访问Amazon的云不是很顺畅,所以对课程学习有一些影响,解决方法可以用工具解析出正确的服务地址IP后,写到hosts文件中,或者下载课程内容,包括视频等。这里coursera-dl就是一个不错的download下载工具,它基于Python,建议Python3,使用pip安装好之后,直接运行: coursera-dl -u email(username) -p (password) --path=.(where to download) machine-learning(course name) 官方网址: https://github.com/coursera-dl/coursera-dl https://github.com/coursera-dl https://github.com/coursera-dl/coursera-dl/blob/master/README.md 里面还有另一个工具: https://github.com/coursera-dl/edx-dl 是针对另一个在线学习网址 edx 的。 下载的时候在目录下面生成文件 ****-syllabus-parsed.json (例如 machine-learning-syllabus-parsed.json) 下载如果卡住,可 Ctrl+C 强行终止后,在同一路径再次运行同一命令继续下载(程序错误退出也可以这样继续),之前已下载过的、重复的就不会下载

Labels: , , ,

Wednesday, February 15, 2017

putty color scheme(putty配色方案)

参考: https://darekkay.com/2015/03/21/my-putty-color-scheme/ putty自带配色不太好用,特别是紫色,时间长了闪瞎眼,手动设置可以在 window -> colours 里面调整,但是太麻烦,可以直接把相关的 **.reg 导入Windows注册表即可,于是上网搜了下网友给出的诸多 color scheme,发现如下方案比较好(https://darekkay.com/2015/03/21/my-putty-color-scheme/): Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\SESSION_NAME] ; Default Foreground "Colour0"="217,216,216" ; Default Bold Foreground "Colour1"="217,216,216" ; Default Background "Colour2"="28,28,28" ; Default Background "Colour3"="28,63,149" ; Cursor Text "Colour4"="28,28,28" ; Cursor Color "Colour5"="231,231,232" ; ANSI Black "Colour6"="115,113,113" ; ANSI Black Bold "Colour7"="115,113,113" ; ANSI Red "Colour8"="251,38,8" ; ANSI Red Bold "Colour9"="251,38,8" ; ANSI Green "Colour10"="167,226,46" ; ANSI Green Bold "Colour11"="167,226,46" ; ANSI Yellow "Colour12"="102,217,238" ; ANSI Yellow Bold "Colour13"="102,217,238" ; ANSI Blue "Colour14"="0,157,220" ; ANSI Blue Bold "Colour15"="0,157,220" ; ANSI Magenta "Colour16"="255,85,255" ; ANSI Magenta Bold "Colour17"="255,85,255" ; ANSI Cyan "Colour18"="255,210,4" ; ANSI Cyan Bold "Colour19"="255,210,4" ; ANSI White "Colour20"="217,216,216" ; ANSI White Bold "Colour21"="255,255,255" 其中的 SESSION_NAME 替换为session名,如果注入默认设置,可将 SESSION_NAME 替换为 Default%20Settings 以上是有注释的,去掉注释的版本为: Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\SESSION_NAME] "Colour0"="217,216,216" "Colour1"="217,216,216" "Colour2"="28,28,28" "Colour3"="28,63,149" "Colour4"="28,28,28" "Colour5"="231,231,232" "Colour6"="115,113,113" "Colour7"="115,113,113" "Colour8"="251,38,8" "Colour9"="251,38,8" "Colour10"="167,226,46" "Colour11"="167,226,46" "Colour12"="102,217,238" "Colour13"="102,217,238" "Colour14"="0,157,220" "Colour15"="0,157,220" "Colour16"="255,85,255" "Colour17"="255,85,255" "Colour18"="255,210,4" "Colour19"="255,210,4" "Colour20"="217,216,216" "Colour21"="255,255,255"

Labels: , , ,

Tuesday, February 14, 2017

MySQL的迁移

前天从原Ubuntu把某数据库迁移到新装Ubuntu虚拟机,开始以为每个数据库是一个独立文件夹,例如自带的 /var/lib/mysql/mysql/、/var/lib/mysql/performance_schema/,自己创建的数据库**,于是只迁移了**,其余没理,后来发现原来mysql中创建的用户没了,于是新建了用户: create user 'username'@'localhost' identified by 'password'; grant all privileges on name_of_db.* to 'username'@'localhost'; 接下来发现进去数据库**后能看到表,但是列不出表的内容,查了下,原来数据库内容不在**文件夹,仔细一看,**文件夹很小,几十万条数据不可能存在里面,一查原来mysql数据库默认都是放在 ibdata1 这个文件里面的,新ibdata1大小只有18M,原有ibdata1有90M。如果需要每个数据库单独存储,则需要设置,今天重新查了下,使用 show global variables; 里面显示的选项 innodb_file_per_table 默认 OFF,开启此项后默认存放在每个数据库的文件夹里,每个表单独一个文件。 于是将原有的 ibdata1 移动到新机,终于可以看到数据了,但是发现数据不全,前天睡前想了想,要仔细看下数据,看创建时间,以及对应的ID是否和log一致,昨天早上一看是OK的,之前吓了一跳,以为几个月来爬到的东西全没了。 总结下经验,移动数据库要么导出数据导入另一机器的数据库,或者使用mysql自带数据库迁移、复制之类的功能,要么将相关文件夹和文件全部移动或复制,包括 /var/lib/mysql/mysql/、/var/lib/mysql/performance_schema/、**自己的数据库、ibdata1、ib_logfile0、ib_logfile1,这些相关的文件都需要保留。

Labels: , ,

Monday, February 13, 2017

MySQL Connector/Python 的安装

MySQL Connector/Python 是Python的mysql驱动,安装这个驱动之后才能在Python中使用 import mysql.connector 并使用数据库,具体参见 https://dev.mysql.com/doc/connector-python/en/ 安装方法可以是apt,或者下载安装包。 先说说apt。Ubuntu默认是没有mysql-connector-python这些东西的,apt-cache search mysql-connector-python是没结果的,即使 sudo apt-get update 更新后也不行,mysql相关的东西需要安装 MySQL APT Repository 让apt知道mysql相关的东西后才能用apt安装 mysql-connector-python (参考 https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/ 、 https://dev.mysql.com/downloads/repo/apt/)。 另一种方式是下载安装包,Ubuntu是deb包(https://dev.mysql.com/downloads/connector/python/),命令 sudo dpkg -i PACKAGE.deb 安装。 以上两种是通过MySQL官网给出的安装方法,也可通过Python途径获取:使用Python安装工具pip安装。 不管是apt还是deb安装包,都有两种选择,一个是纯Python实现,另一种是C扩展实现,在操作数据量大的时候第二种效率高, import mysql.connector 默认使用第一种,连接数据库时 use_pure=False 表示使用第二种,或者直接 import _mysql_connector 使用第二种。参考(https://dev.mysql.com/doc/connector-python/en/connector-python-installation.html 、 https://dev.mysql.com/doc/connector-python/en/connector-python-example-connecting.html 、 https://dev.mysql.com/doc/connector-python/en/connector-python-cext.html)经过摸索,如果只装mysql-connector-python-cext,那么就只能使用 import _mysql_connector ,如果安装 mysql-connector-python ,则可使用 import mysql.connector ,两者都装,才可 import mysql.connector 后 设置 use_pure ,后面找了下,在这里有叙述对于Linux两个安装包是分开的,如需要则两个都要安装:https://dev.mysql.com/doc/connector-python/en/connector-python-installation-binary.html 由于自己的程序操作数据量暂不大,但考虑以后扩展性,最后选择 mysql-connector-python 和 mysql-connector-python-cext 都安装,但使用 import mysql.connector 且默认 use_pure

Labels: , , ,

Saturday, February 11, 2017

Ubuntu命令行以静默模式安装matlab

参考: https://zhuanlan.zhihu.com/p/23633624 (以此为准) http://m.sodocs.net/doc/3b1c7863a98271fe910ef927.html http://blog.csdn.net/wangpengfei163/article/details/47311041 虚拟机Ubuntu server无桌面,命令行静默模式(silent mode)安装matlab使用如下命令: sudo /media/cdrom/install -inputFile /home/alex/matlab/installer_input.txt 其中第一张(共两张)DVD sudo mount /dev/cdrom /media/cdrom/ 装入后,执行里面的/media/cdrom/install(网友建议不要在/media/cdrom目录执行install),inputFile为installer_input.txt,相关参数在里面,内容如下(井号为注释): ################################################################## ## ## Use this file to specify parameters required by the installer at runtime. ## ## Instructions for using this file. ## ## 1. Create a copy of this template file and fill in the required ## information. ## ## 2. Uncomment only those lines that start with a single '#' ## and set the desired values. All allowed values for the ## parameters are defined in the comments section for each ## parameter. ## ## 3. Launch the installer from the command line, using the -inputFile option ## to specify the name of your installer initialization file. ## ## (Windows) setup.exe -inputFile ## (Mac/Unix) install -inputFile ## ## NOTE: ## If you want to run the activation application in silent ## mode immediately after the installer completes, you must create ## an activation initialization file and specify its name as the ## value of the activationPropertiesFile= option. You can also ## pass the name of the activation initialization file to the ## installer using the -activationPropertiesFile command line ## option. ## ################################################################## ## ## ## SPECIFY INSTALLATION FOLDER ## ## Example: ## (Windows) destinationFolder=C:\Program Files\MATLAB\RXXXX ## (Unix) destinationFolder=/usr/local/RXXXX ## (Mac) destinationFolder=/Applications ## ## Set the desired value for destinationFolder and ## uncomment the line. # destinationFolder= ## ## SPECIFY FILE INSTALLATION KEY ## ## Example: fileInstallationKey=xxxxx-xxxxx-xxxxx-xxxxx..... ## ## Set the desired value for fileInstallationKey and ## uncomment the line. ## fileInstallationKey=09806-07443-53955-64350-21751-41297 ## ## ACCEPT LICENSE AGREEMENT ## ## You must agree to the license agreement to install MathWorks products. ## The license agreement can be found in the license_agreement.txt file at the ## root level of the installation DVD. ## ## Example: agreeToLicense=yes ## ## Set agreeToLicense value to yes or no and ## uncomment the line. agreeToLicense=yes ## ## SPECIFY OUTPUT LOG ## ## Specify full path of file into which you want the results of the ## installation to be recorded. ## ## Example: ## (Windows) outputFile=C:\TEMP\mathworks_.log ## (Unix/Mac) outputFile=/tmp/mathworks_.log ## ## Set the desired value for outputFile and ## uncomment the line. outputFile=/home/alex/matlab/mathworks_matlab_install.log ## SPECIFY INSTALLER MODE ## ## interactive: Run the installer GUI, waiting for user input on all ## dialog boxes. ## ## silent: Run the installer without displaying the GUI. ## ## automated: Run the installer GUI, displaying all dialog boxes, but only ## waiting for user input on dialogs that are missing required ## input. ## ## Set mode value to either interactive, silent, or automated and ## uncomment the line. mode=silent ## SPECIFY LENGTH OF TIME DIALOG BOXES ARE DISPLAYED ## ## Specify how long the installer dialog boxes are displayed, in milliseconds. ## ## NOTE: Use this value only if you set the installer mode to automated. ## ## By default, the dialog boxes display on the screen for one second. ## ## Example: (To specify a value of 1 second.) automatedModeTimeout=1000 ## ## Set the desired value for automatedModeTimeout and ## uncomment the line. # automatedModeTimeout= ## SPECIFY ACTIVATION PROPERTIES FILE (For non-network license types only) ## ## Enter the path to an existing file that contains properties to configure ## the activation process. activationPropertiesFile=/home/alex/matlab/activate.ini ########## Begin: Options for Network License Types ######### ## ## SPECIFY PATH TO LICENSE FILE (Required for network license types only) ## ## This value is required when installing either the License Manager or when ## installing as a Network End-User ## Example: ## (Windows) licensePath=C:\TEMP\license.dat ## (Unix) licensePath=/tmp/license.dat ## Set the desired value for licensePath and ## uncomment the line. # licensePath= ## CHOOSE TO INSTALL LICENSE MANAGER (For network license types only) ## ## Installs license manager files to disk. ## ## NOTE: You only need to install the license manager files ## on your license server. ## ## Set lmgrFiles value to true or false and ## uncomment the line. # lmgrFiles= ## INSTALL LICENSE MANAGER AS A SERVICE (For network license types only) ## ## Configure the license manager as a service on Windows. ## ## NOTE: Not applicable for Unix or Mac. ## ## NOTE: The lmgr_files option (set in previous step) must also be set to true. ## ## Set lmgrService value to true or false and ## uncomment the line. # lmgrService= ########## End: Options for Network License Types ######### ################# Begin - Windows Only Options ################ ## ## CHOOSE TO SET FILE ASSOCIATIONS ## ## Set to true if you want the installer to associate file types used by MathWorks ## products to this version of MATLAB, or false if you do not want the installer to ## associate MathWorks file types with this version of MATLAB. ## ## Default value is true. ## ## Set setFileAssoc value to true or false and ## uncomment the line. # setFileAssoc= ## ## CHOOSE TO CREATE WINDOWS DESKTOP SHORTCUT ## ## Set to true if you would like the installer to create a desktop shortcut icon ## when MATLAB is installed or false if you don't want the shortcut created. ## ## Set desktopShortcut value to true or false and ## uncomment the line. # desktopShortcut= ## CHOOSE TO ADD SHORTCUT TO WINDOWS START MENU ## ## Set to true if you would like the installer to create a Start Menu shortcut ## icon when MATLAB is installed or false if you don't want the shortcut created. ## ## Set startMenuShortcut value to true or false and ## uncomment the line. # startMenuShortcut= ## CREATE a MATLAB Startup Accelerator task ## ## The MATLAB Startup Accelerator installer creates a ## system task to preload MATLAB into the system▒s cache ## for faster startup. ## ## NOTE: By default, a MATLAB Startup Accelerator task will ## automatically be created. ## ## If you want a MATLAB Startup Accelerator task to be created, ## do not edit this section. ## ## Set createAccelTask value to false if you do not want to ## create an Accelerator task and uncomment the line. # createAccelTask= ## Enable Login Named User licensing ## ## Set to Yes to enable use of a Login Named User license for all users of this MATLAB installation ## Users must log in to their MathWorks Account when MATLAB starts. ## ## Example: enableLNU=yes ## ## NOTE: This flag is valid in silent installations only. # enableLNU=yes ################ End - Windows Only Options ################ ## SPECIFY PRODUCTS YOU WANT TO INSTALL ## ## By default, the installer installs all the products and ## documentation for which you are licensed. Products you are not licensed for ## are not installed, even if they are listed here. ## ## Note: ## 1. To automatically install all your licensed products, do not edit ## any lines in this section. ## ## 2. To install a specific product or a subset of products for ## which you are licensed, uncomment the line for the product(s) you want ## to install. #product.Aerospace_Blockset #product.Aerospace_Toolbox #product.Antenna_Toolbox #product.Audio_System_Toolbox #product.Bioinformatics_Toolbox #product.Communications_System_Toolbox #product.Computer_Vision_System_Toolbox #product.Control_System_Toolbox #product.Curve_Fitting_Toolbox #product.DO_Qualification_Kit #product.DSP_System_Toolbox #product.Data_Acquisition_Toolbox #product.Database_Toolbox #product.Datafeed_Toolbox #product.Econometrics_Toolbox #product.Embedded_Coder #product.Filter_Design_HDL_Coder #product.Financial_Instruments_Toolbox #product.Financial_Toolbox #product.Fixed_Point_Designer #product.Fuzzy_Logic_Toolbox #product.Global_Optimization_Toolbox #product.HDL_Coder #product.HDL_Verifier #product.IEC_Certification_Kit #product.Image_Acquisition_Toolbox #product.Image_Processing_Toolbox #product.Instrument_Control_Toolbox #product.LTE_System_Toolbox #product.MATLAB #product.MATLAB_Coder #product.MATLAB_Compiler #product.MATLAB_Compiler_SDK #product.MATLAB_Distributed_Computing_Server #product.MATLAB_Production_Server #product.MATLAB_Report_Generator #product.Mapping_Toolbox #product.Model_Predictive_Control_Toolbox #product.Model_Based_Calibration_Toolbox #product.Neural_Network_Toolbox #product.OPC_Toolbox #product.Optimization_Toolbox #product.Parallel_Computing_Toolbox #product.Partial_Differential_Equation_Toolbox #product.Phased_Array_System_Toolbox #product.Polyspace_Bug_Finder #product.Polyspace_Code_Prover #product.RF_Toolbox #product.Risk_Management_Toolbox #product.Robotics_System_Toolbox #product.Robust_Control_Toolbox #product.Signal_Processing_Toolbox #product.SimBiology #product.SimEvents #product.SimRF #product.Simscape #product.Simscape_Driveline #product.Simscape_Electronics #product.Simscape_Fluids #product.Simscape_Multibody #product.Simscape_Power_Systems #product.Simulink #product.Simulink_3D_Animation #product.Simulink_Code_Inspector #product.Simulink_Coder #product.Simulink_Control_Design #product.Simulink_Design_Optimization #product.Simulink_Design_Verifier #product.Simulink_Desktop_Real_Time #product.Simulink_PLC_Coder #product.Simulink_Real_Time #product.Simulink_Report_Generator #product.Simulink_Test #product.Simulink_Verification_and_Validation #product.Spreadsheet_Link #product.Stateflow #product.Statistics_and_Machine_Learning_Toolbox #product.Symbolic_Math_Toolbox #product.System_Identification_Toolbox #product.Trading_Toolbox #product.Vehicle_Network_Toolbox #product.Vision_HDL_Toolbox #product.WLAN_System_Toolbox #product.Wavelet_Toolbox 里面涉及的 activate.ini 内容为(同样的,井号为注释): ################################################################## # # Name: activate.ini # # Copyright 2008-2010 The MathWorks, Inc. # # Purpose: Activation application initialization file template. # Use this file to specify parameters required by the activation # application at runtime. This file provides the activation # application with required input without using the GUI. # # INSTRUCTIONS FOR RUNNING IN SILENT MODE # # To run the activation application in silent mode: # # 1. Create a copy of this template file and fill in the required # information. # # 2. Navigate to the folder containing the activation application. # (Windows) $MATLABROOT\bin\$ARCH # (Mac/Linux) $MATLABROOT/bin # # 3. Launch the activation application from the command line, # using the -propertiesFile option to specify the name of your # activation initialization file. # # (Windows) activate_matlab.exe -propertiesFile # (Mac/Linux) activate_matlab.sh -propertiesFile # # NOTE: If you want to perform silent activation automatically # after performing silent installation, specify the name of your # activation initialization file as the value of the # activationPropertiesFile= option in the installer initialization # file (installer_input.txt). This option causes the installer # to launch the activation application in silent mode. You can # also specify the activation initialization file as an argument # when you launch the installer, using the -activationPropertiesFile # option. # # NOTE: When run in silent mode, the activation application does # not display the activation dialog boxes. # ################################################################## # # SPECIFY ACTIVATION MODE # # Specify whether or not to run in silent mode. # # Valid values: true / false # # Default: isSilent=true. isSilent=true # # SPECIFY ACTIVATION TYPE (Required) # # Specify the type of activation you want to do. # # Valid values: activateDcAnon / activateOffline activateCommand=activateOffline # # SPECIFY LICENSE FILE LOCATION (Required if activateCommand=activateOffline) # # If you specified the activation type activateOffline, you # must specify the location of the License File that you want # to install. # # Mac/Linux example: # licenseFile=/Central/license.dat # # Windows example: # licenseFile=C:\license.dat licenseFile=/home/alex/matlab/crack/license_standalone.lic # # SPECIFY ACTIVATION KEY (Required if activateCommand=activateDcAnon) # # If you specified the activation type activateDcAnon,you must # specify a valid Activation Key. # # Example: activationKey=55555-55555-55555-55555 activationKey= # # SPECIFY LICENSE FILE DESTINATION DIRECTORY (Optional) # # Specify the directory into which you want to install the license file. # You must specify the full path of a directory that already exists. # # NOTE: This option is only for advanced users since it could make MATLAB # unable to start without specifying special options. # # Mac/Linux example: # installLicenseFileDir=/Central/LicenseDirectory # # Windows examples: # installLicenseFileDir=C:\License Directory installLicenseFileDir= # # SPECIFY NAME OF INSTALLED LICENSE FILE (Optional) # # Specify the name of the installed License File. The file name # must have with either .lic or .dat file extension. # # Example: installLicenseFileName=license.dat installLicenseFileName= 相关日志记录在 mathworks_matlab_install.log 中,中途换上第二张DVD: sudo umount /media/cdrom 以及 sudo mount /dev/cdrom /media/cdrom/ 接下来是激活,将crack/R2016b/bin/glnxa64/里的4个lib:libcufft.so.7.5.18、libinstutil.so、libmwlmgrimpl.so、libmwservices.so复制到/usr/local/MATLAB/R2016b/bin/glnxa64/(/usr/local/MATLAB/R2016b/是默认安装目录,注意复制后的文件权限),同时将crack/license_standalone.lic复制到/usr/local/MATLAB/R2016b/licenses/(licenses目录是自己创建的,注意目录权限,命令:sudo cp license_standalone.lic /usr/local/MATLAB/R2016b/licenses),即可运行matlab了:sudo /usr/local/MATLAB/R2016b/bin/matlab,但此时bin目录不在环境变量中,无法直接使用matlab。 后记20170212: 1.执行 sudo chmod -R a+rX R2016b/ (-R表示递归,a表示所有用户包括u(ser)、g(roup)、o(ther),+rX表示增加读权限、可执行权限,大写X表示在此条件下增加可执行权限:目标为目录或对某用户已经具有可执行权限execute/search only if the file is a directory or already has execute permission for some user),使所有用户均有权限访问matlab目录,并可使用matlab; 2.执行 sudo ln -s /usr/local/MATLAB/R2016b/bin/matlab /usr/local/bin/matlab 使matlab命令可直接执行,不用指定具体路径,因为/usr/local/bin已包含在环境变量$PATH中;或者将 /usr/local/MATLAB/R2016b/bin/ 添加至$PATH(可在~/.profile中添加)也可直接执行matlab;由于本机上 PATH="$HOME/bin:$PATH" 于是直接在~/bin/ 中创建软链接 ln -s /usr/local/MATLAB/R2016b/bin/matlab ~/bin/matlab 即可; 3.昨天在安装完matlab后,需root权限执行,于是给 /usr/local/MATLAB/R2016b/ 递归加上可读、可执行权限,但在加完r可读权限后,再看之前没权限的目录,例如ls -al **,内容全变为问号,开始以为出了啥差错,后来发现原来是文件夹有可读权限但没有可执行权限时,ls -al 该文件夹时,可以看到里面的文件,但显示出来的属性内容全为问号,只有该文件夹具备的可执行权限时,才看得到属性,也就是说,可读权限决定是否看得到内容,可执行权限决定是否看得到内容的属性; 4.安装完提示如下: Your installation may require additional configuration steps. 1. The following products require a supported compiler: Stateflow 8.8 Simulink Coder 8.11 MATLAB Coder 3.2 Simulink Test 2.1 2. Simulink requires a C compiler for simulation acceleration, model reference, and MATLAB Function Block capabilities. It is recommended that you install a supported compiler on your machine. 3. To accelerate computations with the following products, a supported compiler is required: SimBiology 5.5 Fixed-Point Designer 5.3 4. After this installation is complete, you should continue with your configuration of the MATLAB Distributed Computing Server as outlined in the instructions obtained from www.mathworks.com/distconfig. 5. MATLAB Compiler SDK 6.3 requires the following: ● a supported compiler for creation of C and C++ Shared libraries ● a Java JDK for creation of Java packages (Feb 11, 2017 22:16:24) Exiting with status 0 (Feb 11, 2017 22:16:39) End - Successful. VM Ubuntu 64 之前已安装好gcc、g++,Java也装了 (java -version 显示 : java version "1.7.0_121" OpenJDK Runtime Environment (IcedTea 2.6.8) (7u121-2.6.8-1ubuntu0.14.04.3) OpenJDK 64-Bit Server VM (build 24.121-b00, mixed mode) ) 使用如下两个命令重新配置下: /usr/local/MATLAB/R2016b/bin/mbuild -setup 输出: MBUILD configured to use 'gcc' for C language compilation. To choose a different language, execute one from the following: mex -setup C++ -client MBUILD mex -setup FORTRAN -client MBUILD 以及 /usr/local/MATLAB/R2016b/bin/mex -setup 输出: MEX configured to use 'gcc' for C language compilation. Warning: The MATLAB C and Fortran API has changed to support MATLAB variables with more than 2^32-1 elements. In the near future you will be required to update your code to utilize the new API. You can find more information about this at: http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html. To choose a different language, execute one from the following: mex -setup C++ mex -setup FORTRAN

Labels: ,

Ubuntu安装C/C++编译环境

Ubuntu(包括其他版本Linux)安装C/C++编译器/编译环境只需要安装build-essential即可,build-essential依赖make、gcc、g++等库,安装build-essential后这些自动安装好了,具体命令:sudo apt-get install build-essential ****@****:~$ apt-cache depends build-essential build-essential |Depends: libc6-dev Depends: libc6-dev Depends: gcc Depends: g++ Depends: make make:i386 Depends: dpkg-dev Conflicts: build-essential:i386

Labels: , ,

lvm硬盘的挂载

原虚拟机硬盘是逻辑卷lvm,启用新虚拟机后需要把原硬盘数据迁移过来,可以scp,但是有效率问题和权限问题,于是考虑直接挂载。 1.在新虚拟机添加原有虚拟机硬盘 2.新虚拟机未使用lvm所以默认没有装lvm2工具,使用sudo apt-get install lvm2安装(原虚拟机使用lvm于是默认安装lvm2工具 3.使用pvs或pvdisplay查看物理卷,使用vgs查看卷组,使用lvdisplay查看逻辑卷,其中逻辑卷状态为not available,/dev/下没有相关设备,于是使用sudo vgchange -ay /dev/ubuntu-vg激活,一次性激活了ubuntu-vg中的两个分区:root和swap_1 4.挂载:sudo mount /dev/ubuntu-vg/root /mnt 进入查看,文件属性都没变,所属用户名也没变,所有信息完全一样。

Labels: , ,

Friday, January 13, 2017

Python exception的一个小问题

最近编写了一个小程序去爬某网站,挨个挨个ID查询信息,各种异常exception考虑了,但这段时间发现运行一段时间之后就停住了,进程还在,但是从网卡状态看就不再有像心跳一样的网络请求了,Linux用top命令显示的CPU占用率也为0了,log里面也停住了,仔细检查,怀疑是except语句没理解透:except **** as ****:之后就是else:语句了,之前想当然的把else认为是包含except **** as ****:这种情况之外的所有情况,但实际上是没有异常的情况,正确的语句应该是: try: **** except **** as ****:(捕获某个异常) **** except:(之前就是缺少了这个部分) ****(捕获某个异常之外的所有未知异常) else:(正常情况,即无异常的情况) **** 加上except:这个部分后继续运行程序 之前程序卡主估计是出现了未知异常没有被捕获,这个异常又不能像error一样被抛出使程序停止运行,程序就卡在了那里 另外附上exception相关类的关系: https://docs.python.org/2.7/library/exceptions.html#exception-hierarchy


后记20170117:
今天程序又停了,回来仔细观察了下,在可能有问题的地方都加了logging,另外注意到每次出现这种情况的时候,再手动去访问网站,都是未登录的,说明cookie过期了,但直接使用过期的cookie是能够得到一个页面显示的,说明是另一种情况,即是cookie使用过程中过期(而不是一开始就过期),那么怀疑到是timeout相关设置,于是注意到一个地方:opener.open的时候,是否有超时?一查果然默认timeout为无限制,就是说会永远超时下去,_GLOBAL_DEFAULT_TIMEOUT=object(),是空的。

于是加上了timeout=30:response = opener.open(request, timeout=30) ,其实共有3中方法设置超时:

import socket              #method 1 to set timeout
socket.setdefaulttimeout(0.01)

urllib2.socket.setdefaulttimeout(0.01) #method 2

response = opener.open(request, timeout=10) #method 3
接下来再试试

Labels: , , ,

Saturday, December 31, 2016

linux下MySQL的使用

Ubuntu 14.04 64位,装有MySQL服务端和客户端,执行MySQL语句可以先登录后执行: mysql -ualex -p******(alex is username & ****** is password)或者不填密码,执行此语句后输入密码 登录后执行语句,语句结尾加“;”回车胡执行 或者直接在shell里面执行一条语句: mysql -ualex -p****** -e 'SHOW VARIABLES LIKE "version%"'(alex is username & ****** is password)或者不填密码,执行此语句后输入密码 单引号和双引号可以互换,SQL语句后面加不加“;”都行

Labels: ,

Sunday, December 25, 2016

安装pip与Scrapy遇到的问题

安装pip与Scrapy(具体过程参考官网、与: http://cuiqingcai.com/912.html http://pip-cn.readthedocs.io/en/latest/installing.html https://raw.github.com/pypa/pip/master/contrib/get-pip.py(GitHub官网脚本) https://github.com/pypa/pip )后,发现root权限执行pip、scrapy正常,而普通用户报错: 执行python -m pip -V提示/usr/bin/python: No module named pip 执行scrapy提示: Traceback (most recent call last): File "/usr/local/bin/scrapy", line 7, in from scrapy.cmdline import execute ImportError: No module named scrapy.cmdline 执行python -c "import pip; print(pip.__version__)"提示: Traceback (most recent call last): File "", line 1, in ImportError: No module named pip 执行pip提示: Traceback (most recent call last): File "/usr/local/bin/pip", line 7, in from pip import main ImportError: No module named pip 而/usr/local/bin/pip的第七行是“from pip import main” 在自己的py程序中手动import pip也不行,于是查看路径,print sys.path显示: ['/home/****/py', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/home/****/py/mymod'] 看了下,主要是/usr/lib/和/usr/local/lib/,pip和scrapy装在/usr/local/lib/,而这个目录下的文件和文件夹权限有些异常: alex@ubuntu:~$ ls -al /usr/local/lib/python2.7/dist-packages/ total 1176 drwxrwsr-x 56 root staff 4096 Dec 25 20:11 . drwxrwsr-x 4 root staff 4096 Dec 4 22:04 .. drwx--S--- 2 root staff 4096 Dec 4 22:17 attr drwx--S--- 2 root staff 4096 Dec 4 22:17 attrs-16.3.0.dist-info drwx--S--- 2 root staff 4096 Dec 4 22:09 certifi drwx--S--- 2 root staff 4096 Dec 4 22:09 certifi-2016.9.26.dist-info drwx--S--- 2 root staff 4096 Dec 4 21:58 cffi drwx--S--- 2 root staff 4096 Dec 4 21:58 cffi-1.9.1.dist-info -rwx--x--x 1 root staff 733736 Dec 4 21:58 _cffi_backend.so drwx--S--- 2 root staff 4096 Dec 4 22:17 constantly drwx--S--- 2 root staff 4096 Dec 4 22:17 constantly-15.1.0.dist-info drwx--S--- 4 root staff 4096 Dec 4 22:06 cryptography drwx--S--- 2 root staff 4096 Dec 4 22:06 cryptography-1.6-py2.7.egg-info drwx--S--- 2 root staff 4096 Dec 4 22:17 cssselect drwx--S--- 2 root staff 4096 Dec 4 22:17 cssselect-1.0.0.dist-info -rw------- 1 root staff 126 Dec 4 20:57 easy_install.py -rw------- 1 root staff 315 Dec 4 20:57 easy_install.pyc drwx--S--- 2 root staff 4096 Dec 25 19:48 enum drwx--S--- 2 root staff 4096 Dec 4 21:58 enum34-1.1.6.dist-info drwx--S--- 2 root staff 4096 Dec 4 21:58 idna drwx--S--- 2 root staff 4096 Dec 4 21:58 idna-2.1.dist-info drwx--S--- 3 root staff 4096 Dec 4 22:17 incremental drwx--S--- 2 root staff 4096 Dec 4 22:17 incremental-16.10.1.dist-info drwx--S--- 2 root staff 4096 Dec 4 21:58 ipaddress-1.0.17.dist-info -rw------- 1 root staff 80176 Dec 4 21:58 ipaddress.py -rw------- 1 root staff 75654 Dec 4 21:58 ipaddress.pyc drwx--S--- 2 root staff 4096 Dec 4 21:58 .libs_cffi_backend drwx--S--- 6 root staff 4096 Dec 4 21:23 lxml drwx--S--- 2 root staff 4096 Dec 4 21:23 lxml-3.6.4.dist-info drwx--S--- 3 root staff 4096 Dec 4 21:31 ndg drwx--S--- 2 root staff 4096 Dec 4 21:31 ndg_httpsclient-0.4.2-py2.7.egg-info -rw------- 1 root staff 346 Dec 4 21:31 ndg_httpsclient-0.4.2-py2.7-nspkg.pth drwx--S--- 2 root staff 4096 Dec 4 22:06 OpenSSL drwx--S--- 2 root staff 4096 Dec 4 22:17 parsel drwx--S--- 2 root staff 4096 Dec 4 22:17 parsel-1.1.0.dist-info drwx--S--- 10 root staff 4096 Dec 25 19:49 pip drwx--S--- 2 root staff 4096 Dec 4 20:57 pip-9.0.1.dist-info drwx--S--- 4 root staff 4096 Dec 4 20:57 pkg_resources drwx--S--- 5 root staff 4096 Dec 4 21:31 pyasn1 drwx--S--- 2 root staff 4096 Dec 4 21:31 pyasn1-0.1.9.dist-info drwx--S--- 2 root staff 4096 Dec 4 22:17 pyasn1_modules drwx--S--- 2 root staff 4096 Dec 4 22:17 pyasn1_modules-0.0.8.dist-info drwx--S--- 3 root staff 4096 Dec 4 21:58 pycparser drwx--S--- 2 root staff 4096 Dec 4 21:58 pycparser-2.17-py2.7.egg-info drwx--S--- 2 root staff 4096 Dec 4 22:17 pydispatch drwx--S--- 2 root staff 4096 Dec 4 22:17 PyDispatcher-2.0.5-py2.7.egg-info drwx--S--- 2 root staff 4096 Dec 4 22:06 pyOpenSSL-16.2.0.dist-info drwx--S--- 3 root staff 4096 Dec 4 22:17 queuelib drwx--S--- 2 root staff 4096 Dec 4 22:17 queuelib-1.4.2.dist-info drwx--S--- 20 root staff 4096 Dec 4 22:17 scrapy drwx--S--- 2 root staff 4096 Dec 4 22:17 Scrapy-1.2.1.dist-info drwx--S--- 2 root staff 4096 Dec 4 22:17 service_identity drwx--S--- 2 root staff 4096 Dec 4 22:17 service_identity-16.0.0.dist-info drwx--S--- 4 root staff 4096 Dec 4 20:57 setuptools drwx--S--- 2 root staff 4096 Dec 4 20:57 setuptools-30.1.0.dist-info drwx--S--- 2 root staff 4096 Dec 4 21:58 six-1.10.0.dist-info -rw------- 1 root staff 30098 Dec 4 21:58 six.py -rw------- 1 root staff 29545 Dec 4 21:58 six.pyc drwx--S--- 26 root staff 4096 Dec 4 22:17 twisted drwx--S--- 2 root staff 4096 Dec 4 22:17 Twisted-16.6.0-py2.7.egg-info drwx--S--- 2 root staff 4096 Dec 4 22:17 w3lib drwx--S--- 2 root staff 4096 Dec 4 22:17 w3lib-1.16.0.dist-info drwx--S--- 5 root staff 4096 Dec 4 20:57 wheel drwx--S--- 2 root staff 4096 Dec 4 20:57 wheel-0.29.0.dist-info alex@ubuntu:~$ ls -al /usr/local/lib/python2.7/dist-packages/pip ls: cannot open directory /usr/local/lib/python2.7/dist-packages/pip: Permission denied alex@ubuntu:~$ sudo ls -al /usr/local/lib/python2.7/dist-packages/pip [sudo] password for alex: total 420 drwx--S--- 10 root staff 4096 Dec 25 19:49 . drwxrwsr-x 56 root staff 4096 Dec 25 20:11 .. -rw------- 1 root staff 11910 Dec 4 20:57 basecommand.py -rw------- 1 root staff 8874 Dec 4 20:57 basecommand.pyc -rw------- 1 root staff 10465 Dec 4 20:57 baseparser.py -rw------- 1 root staff 10596 Dec 4 20:57 baseparser.pyc -rw------- 1 root staff 16474 Dec 4 20:57 cmdoptions.py -rw------- 1 root staff 15486 Dec 4 20:57 cmdoptions.pyc drwx--S--- 2 root staff 4096 Dec 4 20:57 commands drwx--S--- 2 root staff 4096 Dec 4 20:57 compat -rw------- 1 root staff 32171 Dec 4 20:57 download.py -rw------- 1 root staff 24968 Dec 4 20:57 download.pyc -rw------- 1 root staff 8121 Dec 4 20:57 exceptions.py -rw------- 1 root staff 12182 Dec 4 20:57 exceptions.pyc -rw------- 1 root staff 39950 Dec 4 20:57 index.py -rw------- 1 root staff 34576 Dec 4 20:57 index.pyc -rw------- 1 root staff 11348 Dec 4 20:57 __init__.py -rw------- 1 root staff 9163 Dec 4 20:57 __init__.pyc -rw------- 1 root staff 5626 Dec 4 20:57 locations.py -rw------- 1 root staff 4734 Dec 4 20:57 locations.pyc -rw------- 1 root staff 584 Dec 4 20:57 __main__.py -rw------- 1 root staff 477 Dec 4 20:57 __main__.pyc drwx--S--- 2 root staff 4096 Dec 4 20:57 models drwx--S--- 2 root staff 4096 Dec 4 20:57 operations -rw------- 1 root staff 10980 Dec 4 20:57 pep425tags.py -rw------- 1 root staff 9431 Dec 4 20:57 pep425tags.pyc drwx--S--- 2 root staff 4096 Dec 4 20:57 req -rw------- 1 root staff 156 Dec 4 20:57 status_codes.py -rw------- 1 root staff 386 Dec 4 20:57 status_codes.pyc drwx--S--- 2 root staff 4096 Dec 4 20:57 utils drwx--S--- 2 root staff 4096 Dec 4 20:57 vcs drwx--S--- 12 root staff 4096 Dec 4 20:57 _vendor -rw------- 1 root staff 32010 Dec 4 20:57 wheel.py -rw------- 1 root staff 25061 Dec 4 20:57 wheel.pyc 在自己的py程序中手动import enum(与pip都在/usr/local/lib/)也不行,于是怀疑整个/usr/local/lib/python2.7/dist-packages/目录都有问题,查了下,参考: https://groups.google.com/forum/#!topic/comp.lang.python/CfBiVvvFOdY 执行“chmod -R a+rX 目录**”解决(-R递归,a表示u用户g组o其他 这些所有角色,X和可执行权限x相关但不是所有都加: execute/search only if the file is a directory or already has execute permission for some user (X)),执行后: alex@ubuntu:~/py$ ls -al /usr/local/lib/python2.7/dist-packages total 1176 drwxrwsr-x 56 root staff 4096 Dec 25 20:11 . drwxrwsr-x 4 root staff 4096 Dec 4 22:04 .. drwxr-sr-x 2 root staff 4096 Dec 4 22:17 attr drwxr-sr-x 2 root staff 4096 Dec 4 22:17 attrs-16.3.0.dist-info drwxr-sr-x 2 root staff 4096 Dec 4 22:09 certifi drwxr-sr-x 2 root staff 4096 Dec 4 22:09 certifi-2016.9.26.dist-info drwxr-sr-x 2 root staff 4096 Dec 4 21:58 cffi drwxr-sr-x 2 root staff 4096 Dec 4 21:58 cffi-1.9.1.dist-info -rwxr-xr-x 1 root staff 733736 Dec 4 21:58 _cffi_backend.so drwxr-sr-x 2 root staff 4096 Dec 4 22:17 constantly drwxr-sr-x 2 root staff 4096 Dec 4 22:17 constantly-15.1.0.dist-info drwxr-sr-x 4 root staff 4096 Dec 4 22:06 cryptography drwxr-sr-x 2 root staff 4096 Dec 4 22:06 cryptography-1.6-py2.7.egg-info drwxr-sr-x 2 root staff 4096 Dec 4 22:17 cssselect drwxr-sr-x 2 root staff 4096 Dec 4 22:17 cssselect-1.0.0.dist-info -rw-r--r-- 1 root staff 126 Dec 4 20:57 easy_install.py -rw-r--r-- 1 root staff 315 Dec 4 20:57 easy_install.pyc drwxr-sr-x 2 root staff 4096 Dec 25 19:48 enum drwxr-sr-x 2 root staff 4096 Dec 4 21:58 enum34-1.1.6.dist-info drwxr-sr-x 2 root staff 4096 Dec 4 21:58 idna drwxr-sr-x 2 root staff 4096 Dec 4 21:58 idna-2.1.dist-info drwxr-sr-x 3 root staff 4096 Dec 4 22:17 incremental drwxr-sr-x 2 root staff 4096 Dec 4 22:17 incremental-16.10.1.dist-info drwxr-sr-x 2 root staff 4096 Dec 4 21:58 ipaddress-1.0.17.dist-info -rw-r--r-- 1 root staff 80176 Dec 4 21:58 ipaddress.py -rw-r--r-- 1 root staff 75654 Dec 4 21:58 ipaddress.pyc drwxr-sr-x 2 root staff 4096 Dec 4 21:58 .libs_cffi_backend drwxr-sr-x 6 root staff 4096 Dec 4 21:23 lxml drwxr-sr-x 2 root staff 4096 Dec 4 21:23 lxml-3.6.4.dist-info drwxr-sr-x 3 root staff 4096 Dec 4 21:31 ndg drwxr-sr-x 2 root staff 4096 Dec 4 21:31 ndg_httpsclient-0.4.2-py2.7.egg-info -rw-r--r-- 1 root staff 346 Dec 4 21:31 ndg_httpsclient-0.4.2-py2.7-nspkg.pth drwxr-sr-x 2 root staff 4096 Dec 4 22:06 OpenSSL drwxr-sr-x 2 root staff 4096 Dec 4 22:17 parsel drwxr-sr-x 2 root staff 4096 Dec 4 22:17 parsel-1.1.0.dist-info drwxr-sr-x 10 root staff 4096 Dec 25 19:49 pip drwxr-sr-x 2 root staff 4096 Dec 4 20:57 pip-9.0.1.dist-info drwxr-sr-x 4 root staff 4096 Dec 4 20:57 pkg_resources drwxr-sr-x 5 root staff 4096 Dec 4 21:31 pyasn1 drwxr-sr-x 2 root staff 4096 Dec 4 21:31 pyasn1-0.1.9.dist-info drwxr-sr-x 2 root staff 4096 Dec 4 22:17 pyasn1_modules drwxr-sr-x 2 root staff 4096 Dec 4 22:17 pyasn1_modules-0.0.8.dist-info drwxr-sr-x 3 root staff 4096 Dec 4 21:58 pycparser drwxr-sr-x 2 root staff 4096 Dec 4 21:58 pycparser-2.17-py2.7.egg-info drwxr-sr-x 2 root staff 4096 Dec 4 22:17 pydispatch drwxr-sr-x 2 root staff 4096 Dec 4 22:17 PyDispatcher-2.0.5-py2.7.egg-info drwxr-sr-x 2 root staff 4096 Dec 4 22:06 pyOpenSSL-16.2.0.dist-info drwxr-sr-x 3 root staff 4096 Dec 4 22:17 queuelib drwxr-sr-x 2 root staff 4096 Dec 4 22:17 queuelib-1.4.2.dist-info drwxr-sr-x 20 root staff 4096 Dec 4 22:17 scrapy drwxr-sr-x 2 root staff 4096 Dec 4 22:17 Scrapy-1.2.1.dist-info drwxr-sr-x 2 root staff 4096 Dec 4 22:17 service_identity drwxr-sr-x 2 root staff 4096 Dec 4 22:17 service_identity-16.0.0.dist-info drwxr-sr-x 4 root staff 4096 Dec 4 20:57 setuptools drwxr-sr-x 2 root staff 4096 Dec 4 20:57 setuptools-30.1.0.dist-info drwxr-sr-x 2 root staff 4096 Dec 4 21:58 six-1.10.0.dist-info -rw-r--r-- 1 root staff 30098 Dec 4 21:58 six.py -rw-r--r-- 1 root staff 29545 Dec 4 21:58 six.pyc drwxr-sr-x 26 root staff 4096 Dec 4 22:17 twisted drwxr-sr-x 2 root staff 4096 Dec 4 22:17 Twisted-16.6.0-py2.7.egg-info drwxr-sr-x 2 root staff 4096 Dec 4 22:17 w3lib drwxr-sr-x 2 root staff 4096 Dec 4 22:17 w3lib-1.16.0.dist-info drwxr-sr-x 5 root staff 4096 Dec 4 20:57 wheel drwxr-sr-x 2 root staff 4096 Dec 4 20:57 wheel-0.29.0.dist-info alex@ubuntu:~/py$ ls -al /usr/local/lib/python2.7/dist-packages/pip total 420 drwxr-sr-x 10 root staff 4096 Dec 25 19:49 . drwxrwsr-x 56 root staff 4096 Dec 25 20:11 .. -rw-r--r-- 1 root staff 11910 Dec 4 20:57 basecommand.py -rw-r--r-- 1 root staff 8874 Dec 4 20:57 basecommand.pyc -rw-r--r-- 1 root staff 10465 Dec 4 20:57 baseparser.py -rw-r--r-- 1 root staff 10596 Dec 4 20:57 baseparser.pyc -rw-r--r-- 1 root staff 16474 Dec 4 20:57 cmdoptions.py -rw-r--r-- 1 root staff 15486 Dec 4 20:57 cmdoptions.pyc drwxr-sr-x 2 root staff 4096 Dec 4 20:57 commands drwxr-sr-x 2 root staff 4096 Dec 4 20:57 compat -rw-r--r-- 1 root staff 32171 Dec 4 20:57 download.py -rw-r--r-- 1 root staff 24968 Dec 4 20:57 download.pyc -rw-r--r-- 1 root staff 8121 Dec 4 20:57 exceptions.py -rw-r--r-- 1 root staff 12182 Dec 4 20:57 exceptions.pyc -rw-r--r-- 1 root staff 39950 Dec 4 20:57 index.py -rw-r--r-- 1 root staff 34576 Dec 4 20:57 index.pyc -rw-r--r-- 1 root staff 11348 Dec 4 20:57 __init__.py -rw-r--r-- 1 root staff 9163 Dec 4 20:57 __init__.pyc -rw-r--r-- 1 root staff 5626 Dec 4 20:57 locations.py -rw-r--r-- 1 root staff 4734 Dec 4 20:57 locations.pyc -rw-r--r-- 1 root staff 584 Dec 4 20:57 __main__.py -rw-r--r-- 1 root staff 477 Dec 4 20:57 __main__.pyc drwxr-sr-x 2 root staff 4096 Dec 4 20:57 models drwxr-sr-x 2 root staff 4096 Dec 4 20:57 operations -rw-r--r-- 1 root staff 10980 Dec 4 20:57 pep425tags.py -rw-r--r-- 1 root staff 9431 Dec 4 20:57 pep425tags.pyc drwxr-sr-x 2 root staff 4096 Dec 4 20:57 req -rw-r--r-- 1 root staff 156 Dec 4 20:57 status_codes.py -rw-r--r-- 1 root staff 386 Dec 4 20:57 status_codes.pyc drwxr-sr-x 2 root staff 4096 Dec 4 20:57 utils drwxr-sr-x 2 root staff 4096 Dec 4 20:57 vcs drwxr-sr-x 12 root staff 4096 Dec 4 20:57 _vendor -rw-r--r-- 1 root staff 32010 Dec 4 20:57 wheel.py -rw-r--r-- 1 root staff 25061 Dec 4 20:57 wheel.pyc 普通用户可执行pip、scrapy,而且原有/usr/local/lib/python2.7/dist-packages 整个目录及子目录均可让普通用户访问了,解决了之前一直存在但一直没发现的问题 后记20170211: 1.虚拟机安装新系统Ubuntu 14.04.5,/usr/local/lib/python2.7/dist-packages 和 /usr/local/lib/python3.4/dist-packages 均为空,且属性为root:staff 2.安装pip与scrapy时会有一些小问题,安装好相关的依赖就可以了,例如sudo apt-get install gcc、g++、libssl-dev、libffi-dev、python-dev,以及pip install pyopenssl、pyasn1、ndg-httpsclient、lxml、twisted 3.此次安装又遇到了另一个问题,运行scrapy提示: Traceback (most recent call last): File "/usr/local/bin/scrapy", line 7, in from scrapy.cmdline import execute File "/usr/local/lib/python2.7/dist-packages/scrapy/cmdline.py", line 9, in from scrapy.crawler import CrawlerProcess File "/usr/local/lib/python2.7/dist-packages/scrapy/crawler.py", line 7, in from twisted.internet import reactor, defer File "/usr/local/lib/python2.7/dist-packages/twisted/internet/reactor.py", line 38, in from twisted.internet import default File "/usr/local/lib/python2.7/dist-packages/twisted/internet/default.py", line 56, in install = _getInstallFunction(platform) File "/usr/local/lib/python2.7/dist-packages/twisted/internet/default.py", line 44, in _getInstallFunction from twisted.internet.epollreactor import install File "/usr/local/lib/python2.7/dist-packages/twisted/internet/epollreactor.py", line 24, in from twisted.internet import posixbase File "/usr/local/lib/python2.7/dist-packages/twisted/internet/posixbase.py", line 18, in from twisted.internet import error, udp, tcp File "/usr/local/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 28, in from twisted.internet._newtls import ( File "/usr/local/lib/python2.7/dist-packages/twisted/internet/_newtls.py", line 21, in from twisted.protocols.tls import TLSMemoryBIOFactory, TLSMemoryBIOProtocol File "/usr/local/lib/python2.7/dist-packages/twisted/protocols/tls.py", line 63, in from twisted.internet._sslverify import _setAcceptableProtocols File "/usr/local/lib/python2.7/dist-packages/twisted/internet/_sslverify.py", line 38, in TLSVersion.TLSv1_1: SSL.OP_NO_TLSv1_1, AttributeError: 'module' object has no attribute 'OP_NO_TLSv1_1' 查了下很有可能是twisted版本与scrapy不匹配导致,原有Ubuntu上scrapy是1.2.1,twisted是16.6.0,而新Ubuntu上scrapy是1.3.1,twisted是17.1.0,于是 sudo pip uninstall twisted(卸载) sudo pip install twisted==16.6.0(指定版本安装) sudo pip show twisted(查询) sudo chmod -R a+rX /usr/local/lib/python2.7/dist-packages/(更改相关文件夹权限) 后再次运行scrapy就OK 后记20170226: 昨天和今天继续整了下Python2、Python3以及pip、pip3 Python2和Python3可以看做两个独立的软件,pip作为Python的模块可以安装在Python2(/usr/local/lib/python2.7/dist-packages/)也可以安装在Python3(/usr/local/lib/python3.4/dist-packages/),执行pip和pip3分别为Python何Python3安装模块,也会默认安装到对应的这两个不同路径中,而查询的时候,例如pip/pip3 show coursera-dl,pip和pip3显示的结果是一样的,不管是2还是3版本的模块都能显示。默认安装模块后普通用户没有权限,主要是/usr/local/lib/python2.7/dist-packages/、/usr/local/lib/python3.4/dist-packages/,以及/usr/local/bin/这几个路径里的文件没权限,使用这些命令增加权限:sudo chmod -R a+rx /usr/local/bin/ 、 sudo chmod -R a+rX 目录 ,sudo chmod -R a+x *py 、sudo chmod -R a+x *pyc ,注意小写x是所有全加可执行权限,大写X是如果owner有x或者是目录,则加x;而 sudo chmod -R a+x *py 只能对当前目录的*py增加x,如果下一级子目录,需要 sudo chmod -R a+x */*py ,再下一级则需 sudo chmod -R a+x */*/*py ,增加权限后就可以不加sudo执行/查看了。另外需要注意的是apt-get安装的python3-pip版本太旧没法用,需要用官方的get-pip.py或者源码编译。而且Ubuntu14.04自带Python3.4但没见有pip3需手动装。整好后 python -m pip 和 python3 -m pip 都可以用了,python -m pip list 和 python3 -m pip list 可以分别列出2和3版本安装的模块。 理一下过程: coursera-dl作为Python模块,建议装在Python3目录,而自己的系统默认Python2,直接把Python命令指向Python3就可以直接安装pip到Python3对应路径,但会影响全局,影响其他程序,更好的方法是下载get-pip.py(https://bootstrap.pypa.io/get-pip.py),修改第一行 #!/usr/bin/env python 为 #!/usr/bin/env python3 (加一个3),这样 sudo ./get-pip.py 即可作为Python3的模块安装到 /usr/local/lib/python3.4/dist-packages/ ,接下来使用pip3安装coursera-dl:sudo pip3 install coursera-dl (或者 sudo python3 -m pip install ** 指定Python3的模块pip去install),也是直接装到 /usr/local/lib/python3.4/dist-packages/ ,注意增加相关目录权限。接下来就可以使用Python3的模块coursera-dl了(命令在/usr/local/bin/coursera-dl,相关文件在/usr/local/lib/python3.4/dist-packages/)。 后记20170516: 这几天安装TensorFlow遇到一些问题,走了一大圈弯路,细节省略了,大致过程如下: Ubuntu14.04装了Python2.7.6想安装最新的2.7.13,apt-get源里面没有,于是从源码安装,哪知道安装的路径不一致,原有在/usr/bin/、/usr/lib/ 这些目录里,新装的在/usr/local/bin/、/usr/local/lib/里面,导致一系列问题,源码命令没有卸载命令,只能手动一点点删,删完再重新试着安装2.7.6,重新pip: 起因是想装TensorFlow,因为主用Python2.7(2.7.6,虽然也装了Python3),所以想把2.7.6升到最新的2.7.13,以为这样可以避免Python的SNIMissingWarning和InsecurePlatformWarning告警(事实上怎么折腾还是没法避免)。但是apt源里面最新的就是2.7.6没法升,于是就下载了2.7.13源码编译安装,装好之后用pip安装TensorFlow,装好后import tensorflow告警: No module named tensorflow /usr/local/lib/python2.7/dist-packages/tensorflow 查看/usr/local/lib/python2.7/dist-packages/里面明明是有这个tensorflow文件夹啊,于是 print sys.path : ['/home/****', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages'] (或者 #!/usr/bin/env python # -*- coding: utf-8 -*- import sys print '\n'.join(sys.path) 分行显示 而使用 #!/usr/bin/env python 与 #!/usr/local/bin/python 与 #!/usr/bin/python 与 #!/usr/bin/python3 的结果不尽相同,/usr/bin/ 里是原来装的python,/usr/local/bin/ 里是新的、源码安装的python。 ) sys.path和原来不一样,/usr/lib/ 变为了 /usr/local/lib/ 而且 dist-packages 变为了 site-packages ,这就是源码安装和apt-get安装造成的差异,怎么办? 有人建议装 virtualenv (参考:https://github.com/tensorflow/tensorflow/issues/647),这个 virtualenv 帮助管理路径,但我不想装,想自己掌握操作,于是试着添加路径到sys.path,不是在**.py里面临时sys.path.append,而是永久增加,参考: https://askubuntu.com/questions/798382/cant-import-installed-packages-in-python https://leemendelowitz.github.io/blog/how-does-python-find-packages.html https://docs.python.org/2/tutorial/modules.html (里面搜索 sys.path) https://docs.python.org/2/library/sys.html#sys.path https://docs.python.org/2/library/site.html#module-site http://www.tuicool.com/articles/EB3miqr http://www.jb51.net/article/42183.htm 选择在 site-packages 目录下加 ****.pth 文件的方法,创建 mypath.pth 里面写上目录,路径可以用相对路径,如果同一目录,直接文件名也可,添加之后 sys.path 确实有增加****.pth里的内容,现在sys.path的问题看起来解决了,但是import tensorflow仍然有问题: ImportError: Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy. If you're working with a numpy git repo, try `git clean -xdf` (removes all files not under version control). Otherwise reinstall numpy. 参考: https://github.com/tensorflow/tensorflow/issues/559 http://stackoverflow.com/questions/34051737/numpy-core-multiarray-failed-to-import http://stackoverflow.com/questions/20518632/importerror-numpy-core-multiarray-failed-to-import 还是版本冲突的问题,一下也找不出哪儿装了两个版本的numpy了,于是考虑卸载源码安装的Python2.7.13,但是源码目录里面没有卸载选项,只能手动删除: /usr/local/bin/python* /usr/local/bin/pydoc2 /usr/local/lib/python2 /usr/local/include/python2 /usr/local/lib/pkgconfig/python2.pc /usr/local/lib/libpython2 删除和以上类似的路径和文件后,/usr/local/bin/ 里面仍有一些文件,看了下有些是pip安装的Python包,例如pillow(PIL),产生的,于是直接删掉,找了会也没法100%确认干净,算了(期间误删了一些lib、pip文件,只好从另一个系统里复制过来一遍) 接下来,恢复安装Python2.7.6(其实原本就有,现在是重新安装、修复下,以免缺少文件之类的),这之前要添加第三方apt源(ppa),参考: https://www.zhihu.com/question/37021474?sort=created https://launchpad.net/ubuntu/+ppas?name_filter=python https://launchpad.net/~fkrull/+archive/ubuntu/deadsnakes https://askubuntu.com/questions/865554/how-do-i-install-python-3-6-using-apt-get 执行: sudo add-apt-repository ppa:fkrull/deadsnakes sudo apt-get update 再执行: sudo apt-get install --reinstall python2.7 sudo apt-get install --only-upgrade python2.7 sudo apt-get -f install python2.7 然后再apt-get装Python3.6,再从 https://pip.pypa.io/en/stable/installing/ 下载get-pip.py安装pip: python2 get-pip.py,下载 https://bootstrap.pypa.io/3.4****(try3.2、3.3/3.4、etc)/get-pip.py 来安装pip3: python3 get-pip.py(将get-pip.py首行改为:#!/usr/bin/env python3,注意写明python3而不是python),接下来又出现: File "get-pip.py", line 20061, in lsb_release ****的问题,查了下是lsb_release的问题,看到某网友 which lsb_release (查看lsb_release程序所在位置),于是 vi lsb_release 进去看了看,第一行是: #! /usr/bin/python3 -Es 修改Python3为python,再执行就OK了,看来还是安装Python3或者pip3时把 lsb_release 覆盖了,还是版本2和3的冲突。参考: https://github.com/pypa/setuptools/issues/937 https://discourse.mailinabox.email/t/unable-to-run-mailinabox-command/1840/11 (居然有网友卸载了重装来解决。。。。) 这个问题解决后接下来把pip和python指向2版本的可执行文件(通过强制修改软链接 ln -sf),但是每次pip之后还是需要修改 /usr/local/lib/python2.7/dist-packages 目录的权限很麻烦,查了下解决方法: http://stackoverflow.com/questions/23629898/problems-installing-matplotlib-in-linux http://caligari.treboada.net/2014/09/23/python-pip-and-the-staff-group/ https://askubuntu.com/questions/736738/i-tried-to-install-python-package-then-some-error-is-showing-like-exeption https://github.com/sindresorhus/weechat-notification-center/issues/1 https://superuser.com/questions/272061/reload-a-linux-users-group-assignments-without-logging-out https://arkaitzj.wordpress.com/2010/03/08/linux-add-user-to-a-group-without-logout/ 有把当前用户加入staff组的、有修改目录所有者、修改目录权限的,有用apt-get代替pip安装的,还有使用 virtualenv 的,试了下加入staff组然后 newgrp staff 不logout就即时生效,不好使,还是用 sudo pip **** 然后 sudo chmod -R a+rX /usr/local/lib/python2.7/dist-packages/ 。 最终的 sys.path 是(分行显示): /home/**** /usr/lib/python2.7 /usr/lib/python2.7/plat-x86_64-linux-gnu /usr/lib/python2.7/lib-tk /usr/lib/python2.7/lib-old /usr/lib/python2.7/lib-dynload /usr/local/lib/python2.7/dist-packages /usr/lib/python2.7/dist-packages 而 from distutils.sysconfig import get_python_lib print(get_python_lib()) 是 /usr/lib/python2.7/dist-packages 最后参考 https://github.com/martin-gorner/tensorflow-mnist-tutorial/blob/master/INSTALL.txt 进行测试: git clone https://github.com/martin-gorner/tensorflow-mnist-tutorial.git cd tensorflow-mnist-tutorial python mnist_1.0_softmax.py 提示 ImportError: No module named _tkinter, please install the python-tk package 缺少tkinter库于是执行sudo apt-get install python-tk,OK 终于基于python2.7.6成功安装TensorFlow,同时保持了python2和python3并存,pip2和pip3并存 中间的小问题省略了,最后总结的经验就是: 尽量别源码安装python,可以用第三方源加入PPA后(可用ppa:fkrull/deadsnakes),用apt-get等工具安装新版本,没有最新的就算了。装好python再用pip安装package或lib,装完 sudo chmod -R a+rX /****/lib/****/dist-packages/ tensorflow的安装可参考: https://github.com/martin-gorner/tensorflow-mnist-tutorial/blob/master/INSTALL.txt sudo -H apt-get install git sudo -H pip install --upgrade matplotlib sudo -H pip install --upgrade tensorflow (缺少tkinter库需执行sudo apt-get install python-tk)

Labels: , , ,

Saturday, December 24, 2016

VMware的vmem文件失效清理

VMware guestOS从一台电脑挪到另一台电脑后,发现原有vmem文件(大小和当时所分配的内存一样)及对应文件夹很久都没有被修改过了,而另外有一个**.vmem和文件夹 是实时被修改的,怀疑原有的失效,而且在很久以前,于是尝试着删除并运行虚拟机,一切正常 总结:由于种种原因(例如怀疑重装VMware等)VMware会产生vmem及文件夹垃圾文件,vmem占用大小和内存一样,这时可删除之 后记20170220: 除vmem文件外,wmdk文件也容易产生垃圾,虽然并不一定占用空间。例如在删除虚拟机附带的另一个虚拟磁盘(虚拟机名为 Ubuntu 64 ,虚拟机自带的第一个虚拟磁盘是虚拟文件,对应的文件为 Ubuntu 64.vmdk 和 Ubuntu 64-s001.vmdk、Ubuntu 64-s002.vmdk、Ubuntu 64-s003.vmdk 等,而另一个虚拟盘为计算机硬盘的最后一个物理分区,对应配置文件为 Ubuntu 64-0.vmdk 和 Ubuntu 64-0-pt.vmdk ,可在虚拟机里自由删除和添加 )后,对应的文件 Ubuntu 64-0.vmdk 和 Ubuntu 64-0-pt.vmdk 并没有被删除,下次添加时会从下一个编号开始,例如 Ubuntu 64-1.vmdk 和 Ubuntu 64-1-pt.vmdk ,删除/添加操作一次就产生了多余的两个文件,虽然文件很小。可以在虚拟机删除盘后手动删除这两个文件,再添加新盘,新的配置文件就和原来的名字一样 Ubuntu 64-0.vmdk 和 Ubuntu 64-0-pt.vmdk ,不会产生垃圾文件。

Labels: , , ,

swap性能调优

hostOS为win7SP1 64位8G内存,guestOS为Ubuntu14.04 64位,分配2G内存,足够使用,原本不想分配swap,但当初在创建逻辑卷时分配了2G空间swap,想想还是挂载上吧,万一需要用到呢?但是普通情况下直接使用也不好,会降低速度,那就尽量先用内存吧,如何设置呢? 在/etc/sysctl.conf中,使用vm.swappiness,设置成5吧,意味着内存使用了95%剩余5%的时候开始使用swap空间,重启系统生效,或者命令 sudo sysctl -p 重新加载配置文件后生效; 另外sudo sysctl vm.swappiness=10 或者 sudo su 后 echo 10 > /proc/sys/vm/swappiness 是临时修改swappiness值 而cat /proc/sys/vm/swappiness是查看swappiness值

Labels: , ,

Ubuntu swap分区无法加载的解决

win7 VMware下Ubuntu 14.04 64位系统,guestOS挪到另一电脑后磁盘重新删除、添加,发现sudo fdisk -l结果中显示: ... Disk /dev/mapper/ubuntu--vg-root doesn't contain a valid partition table ... Disk /dev/mapper/ubuntu--vg-swap_1 doesn't contain a valid partition table 查了下据说逻辑卷都会被这样提示,不影响(从后面测试折腾来看,确实不影响,这个提示一直有) 进一步折腾发现 sudo parted /dev/sda print all 显示: ... Error: /dev/mapper/ubuntu--vg-swap_1: unrecognised disk label 这个就有问题了,继续执行free显示: ... Swap: 0 0 0 确实有问题,swap为0,没能被加载,sudo blkid结果里面也没有swap,而且/etc/fstab里面swap也没被注释掉,各种结果都正式swap加载有问题 继续用sudo pvdisplay、sudo vgdisplay、sudo lvdisplay(查询逻辑卷信息)查询一下,得知系统空间用的是逻辑卷,大小大概20G,其中18G用作Ubuntu存储目录,另外2G分给了swap,尝试手动挂载swap: sudo swapon /dev/mapper/ubuntu--vg-swap_1 和 sudo swapon /dev/ubuntu-vg/swap_1 (其实/dev/mapper/ubuntu--vg-swap_1和/dev/ubuntu-vg/swap_1是两个链接,均指向/dev/dm-1),均提示:swapon: /dev/mapper/ubuntu--vg-swap_1: read swap header failed: Invalid argument 继续查,网上有不少记录,Ubuntu官网就有两个相关问题贴:953875和1310058, https://bugs.launchpad.net/ubuntu/+source/ecryptfs-utils/+bug/953875/ https://bugs.launchpad.net/ubuntu/+source/ecryptfs-utils/+bug/1310058/comments/22 指出是Ubuntu的一个bug,和加密软件有关,它把swap的UUID改变了 sudo blkid结果里面没swap的UUID,手动执行:sudo mkswap /dev/mapper/ubuntu--vg-swap_1,创建swap分区,执行结果显示了UUID,接下来将/etc/crypttab里面的UUID修改为正确的UUID(或者直接加-U参数指定UUID),另外在行的最后加一个“,offset=8”(8个512字节,网友测试6就可以了,有人建议8,有人1024;根据网友描述,按我的理解,前面那部分存储了UUID,而加密软件正好对这部分进行写操作,于是会改变UUID,所以swap从后面一点开始,避免被写导致,保持UUID不变),立马OK(不加offset也成功加载swap,结果和下面一样): sudo swapon -a 后 free显示: ... Swap: 2093052 0 2093052 但又出现新提示: swapon: /dev/mapper/cryptswap1: stat failed: No such file or directory locate cryptswap无结果,后来发现在/etc/fstab里面有两行关于swap的,开始我以为两行是相互配合的,现在看来是冲突了: /dev/mapper/ubuntu--vg-swap_1 none swap sw 0 0 /dev/mapper/cryptswap1 none swap sw 0 0 查看/dev/mapper/下面并无cryptswap1文件或文件夹,想了想,也没有加密的计划,越简单越好,于是注释掉后面行,执行: sudo swapoff -a sudo swapon -a free结果显示正常 Ubuntu官网那两个贴还建议:sudo update-initramfs -u,于是也执行了(虽然不懂有什么用) 另外fstab里面直接用UUID指定分区: UUID=185ed9d3-bb19-4a8c-bc86-e57b226e9676 none swap sw 0 0 也可以; 后面继续摸索:sudo /etc/init.d/cryptdisks reload 之后 再 sudo fdisk -l,结果多了一个/dev/mapper/cryptswap1, (执行sudo /etc/init.d/cryptdisks reload的时候swapoff一下,不然出现分区已经挂载之类的提示,可能和这个有关) 这时修改/etc/fstab,使能:/dev/mapper/cryptswap1 none swap sw 0 0 挂载:sudo swapoff -a 后 sudo swapon -a,成功,说明之前的/etc/init.d/cryptdisks是没有加载或者有冲突(可能是fstab里两个swap项冲突),fstab只保留一个cryptswap1重启后OK 简单总结下swap挂载不上的解决: 最简单的可以直接在/etc/fstab里添加:UUID=**** none swap sw 0 0,并删除其余swap项(获取UUID可通过:sudo blkid,结合ls -al /dev/disk/by-uuid/查看现有磁盘设备的UUID;sudo lvdisplay查看逻辑卷UUID即LV UUID,与UUID不一样),普通磁盘时建议此方式; 磁盘加密时建议此方式: 如果有装cryptdisks加密磁盘的工具(Ubuntu默认有),有/etc/crypttab,则检查里面UUID,或直接指定UUID重新创建swap分区:sudo mkswap -U **** /dev/mapper/ubuntu--vg-swap_1,或者sudo mkswap /dev/mapper/ubuntu--vg-swap_1后将结果中正确的UUID添加至crypttab对应的项;接下来在crypttab对应项后面加上“,offset=8”(避免UUID写在太前而被加密软件写操作覆盖改变);然后fstab中保留唯一的swap项:/dev/mapper/ubuntu--vg-swap_1 none swap sw 0 0,或者确保/etc/init.d/cryptdisks开机启动能正常加载后保留fstab里swap唯一项:/dev/mapper/cryptswap1 none swap sw 0 0;最后sudo update-initramfs -u。如果偶尔系统启动后swap不加载的情况,执行sudo /etc/init.d/cryptdisks reload 后 重新加载 sudo swapon -a 即可。 今天20161224,看了下系统文件大概是20160101凌晨装的系统,大概就是2015末2016初吧,整整一年,把guestOS从一台电脑挪到另一台电脑后,今天才发现swap问题,并于今天内解决 参考: Ubuntu官方bug贴953875和1310058: https://bugs.launchpad.net/ubuntu/+source/ecryptfs-utils/+bug/953875/ https://bugs.launchpad.net/ubuntu/+source/ecryptfs-utils/+bug/1310058/comments/22 以及: http://askubuntu.com/questions/462775/swap-not-working-on-clean-14-04-install-using-encrypted-home http://askubuntu.com/questions/462739/14-04-with-fde-and-swap-is-missing 后记: 刚才重新运行了一会,发现sudo init 6重启后OK,但sudo init 0后开机就挂载不了swap,/var/log/boot.log中出现: device-mapper: rename ioctl on cryptswap1_unformatted failed: Device or resource busy 手动sudo /etc/init.d/cryptdisks reload 后 sudo swapon -a 又能挂载,不想折腾了,也没必要加密了,于是直接不用加密了,参考: https://www.logilab.org/blogentry/29155 https://webcache.googleusercontent.com/search?q=cache%3awww.logilab.org/blogentry/29155&hl=en&tbo=d&strip=1 (启用加密用 sudo ecryptfs-setup-swap )其中的描述: sudo swapoff -a sudo cryptsetup remove /dev/mapper/cryptswap1 sudo vim /etc/crypttab *remove the /dev/sda5 line* sudo /sbin/mkswap /dev/sda5 sudo swapon /dev/sda5 sudo vim /etc/fstab *replace /dev/mapper/cryptswap1 with /dev/sda5* 至于cryptdisks开机启动就不管了,没精力,也没必要,耗不了多少资源,而且万一以后要用呢 后记2(20161225): /etc/crypttab 里面直接用#注释掉就可以了,也可以删除行 刚发现/etc/rc2.d/和/etc/rc5.d/是一样的,执行runlevel显示是2,在/etc/rc2.d/里面没有cryptdisks而/etc/rc6.d/里面有S59cryptdisks-early,说明关机后启动系统进入runlevel 2是没有运行cryptdisks的,所以/dev/mapper/cryptswap1没法正常加载,而如果重启则是进入runlevel 6,有执行S59cryptdisks-early,所以能正常加载/dev/mapper/cryptswap1,swap正常挂载。 小结一下: 如果不需要磁盘加密(不运行cryptdisks),/etc/fstab里直接 UUID=**** none swap sw 0 0 或 /dev/mapper/ubuntu--vg-swap_1 none swap sw 0 0 并注释掉其余swap项; 如果有磁盘加密(运行cryptdisks),/etc/fstab里 /dev/mapper/cryptswap1 none swap sw 0 0 并注释掉其余swap项,同时保证开机启动项/etc/rc*.d/里面cryptdisks正常启动,而且cryptdisks配置正常:/etc/crypttab里面UUID正确而且行末加“,offset=8”避免前几个写有UUID的地方被写覆盖;如果cryptdisks异常则执行sudo /etc/init.d/cryptdisks reload 后 重新加载 sudo swapon -a 磁盘加密或不加密两种情况下如有修改系统文件则执行sudo update-initramfs -u更新一下 后记20170212: 修改/etc/fstab后重新加载生效的命令是mount -a即挂载所有,umount -a是卸载所有

Labels: , ,

Monday, December 19, 2016

关于python官网urllib2实例的问题

python官网Docs有介绍urllib2,里面有实例,对于python2.7版本,页面是: https://docs.python.org/2/howto/urllib2.html 在“Wrapping it Up”这一节,有number1和number2两个例子,其中第二个例子有些问题: if拦截了URLError,后面的elif永远不会执行,因为e永远有reason值,如果是普通URLError,reason就是给出的描述,如果是HTTPError(属于URLError里面一个子集),那么print出来是“OK”,所以如果是有URLError,hasattr(e, 'reason')总是成立,轮不到后面的elif部分执行;应该像前面的number1一样调整下顺序,先处理HTTPError再考虑URLError。 附: 下面是原文档: Wrapping it Up So if you want to be prepared for HTTPError or URLError there are two basic approaches. I prefer the second approach. Number 1 from urllib2 import Request, urlopen, URLError, HTTPError req = Request(someurl) try: response = urlopen(req) except HTTPError as e: print 'The server couldn\'t fulfill the request.' print 'Error code: ', e.code except URLError as e: print 'We failed to reach a server.' print 'Reason: ', e.reason else: # everything is fine Note The except HTTPError must come first, otherwise except URLError will also catch an HTTPError. Number 2 from urllib2 import Request, urlopen, URLError req = Request(someurl) try: response = urlopen(req) except URLError as e: if hasattr(e, 'reason'): print 'We failed to reach a server.' print 'Reason: ', e.reason elif hasattr(e, 'code'): print 'The server couldn\'t fulfill the request.' print 'Error code: ', e.code else: # everything is fine

Labels: , , , , ,

Saturday, December 17, 2016

手动更新hosts

GFW主要手段之一就是dns污染或屏蔽,通过修改hosts强制指定域名对应的DNS可以解决,网上有些博客会发布一些hosts记录,也有工具自动更新(如huhamhire的hoststool),不过有时候工具维护如果不到位就不太好使,可以自己手动修改解决。 关键是找到正确的IP,可以通过google的8.8.8.8或8.8.4.4或OpenDNS的208.67.222.222或208.67.220.220,查询IP,如“nslookup github.com 8.8.8.8”,不过这样直接查毕竟没加密,可能被篡改,所以也可以直接到第三方网站查询(虽然也可能有问题),如国外的:http://ipaddress.com/、https://www.whatismyip.com/dns-lookup/、https://dnsquery.org/、http://network-tools.com/,另外:https://www.whois.com/ 这个网站虽然解析不了DNS但可以查询网站信息;国内有ip.cn 另一种方法是通过第三方网站去ping测,这种方法的好处是可以在世界不同地方去测试服务IP,找一个既没被封又有小延时的IP(可以考虑香港的IP); 通过以上方法可以查到对应IP,例如有两个:IP1、IP2,大部分给出两个结果,不断刷新时两个结果先后顺序也会变化,IP1、IP2,或IP2、IP1;少数只给出一个结果,不断刷新时可能给出IP1也可能给出IP2 接下来可以ping一下IP是不是有回显(虽然有些服务器运行正常但没回显) 然后在hosts文件中添加对应的记录,IP1不行就IP2(解析出来的IP不可用可能是因为被GFW屏蔽了) 一个网页会连很多资源,可以F12监控下网页连了哪里,加载不进来的,可以把对应的网址的IP查出来,添加到hosts里面 简单说:nslookup或网页查到正确的IP,手动加到hosts试一下,F12加载网页看下需要哪些更多的资源再手动添加

Labels: , , ,

Sunday, December 11, 2016

转:如何访问维基百科

转自: https://zh.m.wikipedia.org/zh-sg/Help:如何访问维基百科 编辑本页 其他语言 帮助:如何访问维基百科 本文旨在为访问维基百科及维基媒体基金会其他计划有困难障碍的中文用户,提供有效安全的访问方法。 快捷方式: H:VISIT 微笑欢迎 新手工具箱 目录 常用页面列表 帮助页面 欢迎!新来者 新手索引大全 关于维基百科 新手上路 请求帮助 新手入门 社区首页 致其他百科用户 新手入门简明指南 新手版在线训练 使用教学材料库 寻求他人协助 互助客栈 联系我们 IRC即时求助 知识问答 小天使 问与答 如何创建新条目? 如何访问维基百科? 到哪里发问或提建议? 导师计划 传扬维基百科 宣传片 分享你的感受 第一印象 与维基的相识 为什么写维基 首次编辑感觉 简而言之 简而言之:目前对于中国大陆用户,如果想正常访问维基百科,可以使用未受污染的Hosts或者DNS,也可以使用免费的翻墙软件或者考虑购买收费的代理服务,在使用代理编辑维基百科时可能需要获取IP封禁例外权。在使用上述措施时请注意安全以免个人信息泄露。 直接访问 当您在访问经过加密(HTTPS)的页面时,地址栏中应当出现一个锁形图标。 维基百科的网址如下: https://zh.wikipedia.org (中文维基百科桌面版) https://zh.m.wikipedia.org (中文维基百科移动版) https://www.wikipedia.org (多语言入口,可以通过链接访问或搜索任意语言版本的维基百科) 自2015年6月中旬起,维基媒体基金会对旗下项目进行了强制性加密(HTTPS),未加密的明文页面(HTTP)会被强制跳转到对应的加密页面。如果访问中浏览器出现证书错误等提示,说明连接极有可能已经受到了干扰,请停止访问,不要添加例外,以免传输的数据被窃听。 目前,在中国大陆直接访问维基媒体基金会的不同项目可能会遇到如下情况: 项目 加密(HTTPS) 明文(HTTP)[注 1] 桌面版 移动版 桌面版 移动版 维基百科 中文 ✗ ✗ ✗ ✗ 英文 ✓ ✓ Yes Yes 粤文 ✗ ✓ ✗ Yes 赣语 ✓ ✓ Yes Yes 吴语 ✗ ✓ ✗ Yes 闽南语 ✓ ✓ Yes Yes 闽东语 ✓ ✓ Yes Yes 客家语 ✓ ✓ Yes Yes 藏文 ✓ ✓ Yes Yes 维吾尔文 ✓ ✓ Yes Yes 文言文 ✓ ✓ Yes Yes 其它中文项目 维基文库 ✓ ✓ ✗ Yes 维基教科书 ✓ ✓ Yes Yes 维基词典 ✓ ✓ Yes Yes 维基新闻 ✓ ✓ ✗ Yes 维基语录 ✓ ✓ Yes Yes 维基导游 ✓ ✓ Yes Yes 其它多语言项目 维基学院 ✓ ✓ Yes Yes 维基物种 ✓ ✓ Yes Yes 维基共享资源 ✓ ✓ Yes Yes 维基孵育场 ✓ ✓ Yes Yes 元维基 ✓ ✓ Yes Yes 维基数据 ✓ ✓ Yes Yes MediaWiki官网 ✓ ✓ Yes Yes 后台支持性服务 图片服务器[注 2] ✓ Yes 后台代码维护 ✓ Yes 技术文档 ✓ Yes 邮件列表 ✓ Yes 上标注释: ^ 明文版页面会自动跳转至加密版。不考虑HSTS的影响,如果该跳转步骤能顺利完成,则视为可用,标记为黄色勾号。 ^ 根据维基媒体基金会的设置,该站首页没有任何内容。 该表格反映的情况仅适用于IPv4连接。最近修订日期:2016-12-05。 查 论 编 如果你在直接连接(未使用代理、VPN等手段)维基百科时遇到的情况和上文描述不尽相同,也欢迎留下反馈信息。 维基百科应用程序 主条目:维基百科应用程序 Get it on Google play.svg Download on iTunes.svg Windows 8及Windows RT用户:到Windows Store下载 黑莓用户:从BlackBerry World下载 IPv6连接 维基媒体基金会旗下项目均支持IPv6连接,由于目前对于IPv6连接的过滤技术尚不成熟,故所以在IPv4访问受限时,拥有IPv6地址的用户(例如教育网)可能仍然可以访问维基媒体项目。 修正域名解析 维基媒体旗下的部分项目目前被GFW通过DNS污染的方式封锁,通过修正域名解析的方式可以恢复访问。 修正域名解析后,用户在首次访问中文维基百科时,需输入以https://打头的网址方可成功连接,否则仍会遭到屏蔽。由于应用了HTTP严格传输安全技术,使用较新版本浏览器的用户如果成功进入了维基媒体基金会旗下项目的页面,在之后的两周(1209600秒)内再次访问相同项目时浏览器会自动将“http://”改为“https://”来访问加密版页面而无须通过服务器进行该跳转。 Hosts文件 Hosts文件存在于电脑本地,通过修改该文件可以改变域名—IP地址的映射。 修改Hosts文件的具体做法是: 用文本编辑器打开Hosts文件(若要编辑,电脑用户需要获取管理员权限,手机和平板电脑用户需要进行root或越狱操作)。对于Windows用户,该文件默认情况下位于C:\Windows\system32\drivers\etc\目录中。其他系统用户请参见hosts文件。 在该文件中加入下列内容(维基媒体基金会有多个IP地址,你可以根据实际情况选择填写不同的IP地址)。需要注意的是,Hosts文件不支持通配符,因此需要逐个添加地址。 208.80.154.224 zh.wikipedia.org #中文维基百科 208.80.154.224 zh.m.wikipedia.org #中文维基百科移动版 208.80.154.224 zh-yue.wikipedia.org #粤文维基百科 208.80.154.224 wuu.wikipedia.org #吴语维基百科 保存文件。如果保存的时候出现任何错误提示,如“权限不足”等,请允许电脑保存;如果杀毒软件提示这一举动存在安全风险,请您忽视。按照本教程的方式修改Hosts文件不会对您的电脑造成损害。修改后的Hosts记录通常可以立即生效,但若保存之后如果还不能正常访问,您可以通过清除DNS缓存来实现,包括: 重新启动设备 执行下列指令 ipconfig /flushdns(Windows) lookupd -flushcache或dscacheutil -flushcache(Mac OS X) /etc/rc.d/init.d/nscd restart或/etc/init.d/nscd restart(Linux)、sudo /etc/init.d/dns-clean start(Ubuntu) 开启再关闭飞行模式(Android) 维基媒体基金会拥有下列IP地址,您可以使用下面的IP地址替换前面教程中的提供的IP地址。在中国大陆,建议使用美国数据中心的IP,因为通常情况下访问速度更快且网络延迟较低。 IP地址 对应项目 数据中心名 位置 198.35.26.96 大部分项目 ulsfo 美国旧金山 208.80.154.224 大部分项目 eqiad 美国阿什本(英语:Ashburn, Virginia) 91.198.174.192 大部分项目 esams 荷兰阿姆斯特丹 在中国大陆可直接连接的IP地址 通过查询 text-lb.(数据中心名).wikimedia.org (lb是load balancer的缩写)、mobile-lb.(数据中心名).wikimedia.org 可以获得上述的IP地址。 DNS设置 参见:域名系统 通常情况下无论使用设置在中国大陆的DNS服务还是使用设置在外国的DNS服务,因为解析结果都需要穿过GFW,所以都会被GFW污染。但是仍有一些设置在中国大陆的小型DNS使用技术手段回避GFW的污染并提供不受污染的结果,通常使用这些小型DNS也能够访问其他被封锁的网站,此类DNS服务包括: 服务提供者 首选IP地址 备选IP地址 Panda DNS 115.159.157.26 Udns 115.159.157.26 115.159.158.38 ORZDNS 59.46.81.50 值得注意的是,使用DNS可能会产生安全问题,DNS服务器的控制者尽管无法监视您与网站之间传输的内容,但是却有能力记录您的IP地址和您试图访问的网站域名。DNS服务商可能会将这些信息分享给第三方(例如政府和广告商)。上面提到的DNS都使用了开源的程序获取不受污染的结果,这些程序可以在Github上获取。此外,在首选和备选IP地址中填入不同DNS服务提供者的地址也是可以的。 欲更换DNS服务,首先需要获得新服务商的DNS服务器的IP地址,这通常可以在它们的官网找到。获得DNS服务商的IP地址后,更改DNS服务的方法如下: Windows 7 / Vista OS X 10.10 Yosemite Android(第三方教程,不同设备的操作方法可能不同,请参考设备厂商的说明) iOS(第三方教程) 一些路由器等网络硬件设备也允许用户修改DNS,详情请参阅设备说明书。 代理服务器 通过代理服务器来中转数据流量,用户可以绕过绝大多数类型的网络封锁。 注意: 由于维基媒体基金会封禁了大部分公共代理服务器以避免破坏,若要通过代理服务器编辑维基百科,您可能需要有一个拥有IP封禁例外权的账户。 由于用户与代理服务器之间的连接未必被加密且用户通常无法掌握代理服务器的运行细节,因此用户数据可能被第三方监听(例如政府或网络运营商)或被代理服务提供者收集甚至共享给第三方(例如政府或广告商)。对此,用户应避免通过代理服务器进入网上银行等涉及隐私和财务的网站并尽可能地使用https加密连接。 本章节主要讨论相关的技术并举出一些知名度较高的例子。在配置代理服务器前,用户需要联系代理服务器的提供者来获取相关参数。 翻墙软件 翻墙软件是一种代理软件,您电脑和目标服务器之间的流量都将通过其指定的代理服务器中转。常见的翻墙软件有赛风、蓝灯、自由门等。使用翻墙软件编辑维基百科,通常情况下需要申请IP封禁例外权。在这里可以获取常见的翻墙软件。 HTTP代理 操作系统设置 Windows 7 / Vista(对Windows的代理设置进行的修改可以影响到包括Internent Explorer在内的大部分软件的代理设置) OS X 10.10 Yosemite 浏览器设置 部分浏览器允许用户独立设置代理服务,所做的修改仅在该浏览器中有效。 Firefox:设置方法 Chrome:跟随操作系统的代理设置 大部分中国公司开发的浏览器:跟随操作系统的代理设置 浏览器扩展程序 Firefox和Chrome等浏览器支持扩展程序,通过安装代理类的扩展程序可以也可以使用代理服务,部分代理扩展程序还可以根据网址进行匹配。通过浏览器扩展程序进行的代理设置通常只在该浏览器中有效,不会影响其它程序。 Firefox AutoProxy:该扩展程序根据网址匹配代理服务器,也可以设置多个代理并可以配合代理软件(本章节也会有所介绍)工作。此外,用户还可以订阅网址列表(由开发小组维护,用户可直接调用)。下载地址 配置脚本 自动配置脚本范例一(感谢super1提供) function FindProxyForURL(url, host){ host=host.toLowerCase(); if( dnsDomainIs(host,"wikipedia.org") ||dnsDomainIs(host,"wikisource.org") ||dnsDomainIs(host,"wikibooks.org") ||dnsDomainIs(host,"wikimedia.org") ||dnsDomainIs(host,"wiktionary.org") ||dnsDomainIs(host,"wikinews.org") ||dnsDomainIs(host,"wikimediafoundation.org") ||dnsDomainIs(host,"mediawiki.org") ||dnsDomainIs(host,"wikiquote.org") ) return "PROXY 91.198.174.2:80"; else return "DIRECT"; } 注1:91.198.174.2:80可改为任何可用代理服务器 注2:PAC用途是自动配置,只有维基网站用代理91.198.174.2:80,其他均不用代理 注3:将它保存为后缀pac的文件备用,如存为C:\wikimedia.pac,注意:设置直接写此路径无效 Internet Explorer 本机地址范例如下: file://E:\GSW\wikipediaIE.pac 一个可用的在线脚本地址: http://androidgao.googlepages.com/wikipediaIE.pac 设置自动配置脚本 Internet选项-连接 如果您是通过局域网上网请选择局域网设置,如果您是拨号上网(包括ADSL虚拟拨号),请选择您正在使用的拨号连接,然后点设置 无论以上哪种,接下来都选择使用自动配置脚本(打勾),并填入匹配以上本机地址格式范例的本机脚本地址或者一个可用的在线脚本地址 Firefox 本机地址范例如下: file:///E:/GSW/wikipedia.pac 一个可用的在线脚本地址: http://androidgao.googlepages.com/wikipedia.pac 未使用扩展 工具->选项->常规->连接设置->自动代理配置(URL)->填入匹配以上格式范例的脚本地址 已使用扩展 SwitchProxy扩展 设置:工具->SwitchProxy->Manage Proxies->Add->Standard->Next->Proxy Label填入:任意,如:PacForWikipedia->Automatic proxy configuration URL->填入地址(参考未使用扩展的情况) 使用:工具->SwitchProxy->PacForWikipedia 不用:工具->SwitchProxy->None xyzProxy扩展 Chrome 使用Proxy SwitchyOmega扩展 该扩展工具一般内置于GoAgent压缩包的Local文件夹里,也可以从Chrome线上应用程序商店中获得:https://chrome.google.com/webstore/detail/proxy-switchyomega/padekgcemlokbadohgkifijomclgjgif 该工具可设置HTTP、HTTPS、FTP、SOCKS 代理端口。其无法自行代理,需要配合其他软件一起使用。 VPN VPN是一种网络隧道,通过它可以连接到代理服务器,VPN的连接通常是加密的。 各种操作系统的设置方法如下: Windows 8 / 8.1 Windows7 / Vista OS X 10.10 Yosemite Android(对于非原生系统,操作方法可能不同,请参考设备厂商的说明) iOS 注意:对于系统不支持的VPN协议,需要通过安装第三方软件来实现。 Shadowsocks Shadowsocks是一种基于socks5的开源代理软件,支持Windows、Mac OS X、Linux、Android、iOS、OpenWRT平台,下载对应平台的客户端后仅需简单的配置即可使用。Shadowsocks的连接是被高度加密的,所以相对于HTTP代理更加安全且能避开关键字封锁。其原作者clowwindy因被有关部门约谈已停止开发、删除Github上的源代码,但另有开发者志愿进行后续开发。 Shadowsocks分为服务器端和客户端。在使用之前,需要先将服务器端部署在支持Python(且未被GFW封禁)的服务器上,然后通过客户端连接并创建本地代理。此外,用户也可以选择购买基于Shadowsocks的商业服务,以免去自行部署的麻烦。但提供服务的Shadowsocks服务器通常不为用户所控制,所以安全问题仍然不能忽视。 客户端下载地址:https://shadowsocks.org/en/download/clients.html 服务器端部署可参考:https://github.com/shadowsocks/shadowsocks/tree/master Tor Tor的全称是“The Onion Router”(洋葱路由器),本为匿名软件,亦可作翻墙之用。其通过三重代理链隐匿路由信息,反制现阶段大量存在的流量过滤、嗅探分析等工具,难以追踪,有效地保证了安全性。 Tor项目的官方网站提供了Tor浏览器——集成了Tor且经过安全性定制的Firefox,并针对封锁了Tor的地区提供了流量混淆工具。中国大陆地区目前可选择obfs4和meek-azure网桥接入Tor网络,也可以配置其他翻墙工具作为其前置代理。Tor浏览器连接成功后,将提供SOCKS5代理127.0.0.1:9150以供其他应用程序使用。 为防止滥用,维基媒体项目以扩展TorBlock查封了大多数Tor出口节点,Tor用户只能阅读但无法编辑维基百科。要突破该限制,用户需申请IP封禁例外权限。 网页代理 一个网页代理的截图,可以看出浏览器地址栏中输入的是网页代理的网址,而网页代理的输入框中才是需要访问的网站的地址,此外页面顶部存在轻微的排版错乱现象 网页代理或在线代理是一种在网页上运行的代理服务器程序(本质上是一种网站),用户无需在本地进行任何设置,输入网页代理服务的网址即可开始使用,相对方便。使用时,用户需要在网页代理服务提供的网址输入框(而不是浏览器的地址栏)中输入需要访问的地址,网页代理服务会为用户加载内容。 由于网页代理服务的传输原理和一般的网站类似,故封锁网页代理比封锁其他类型的代理工具要更加容易,因此网页代理也更容易失效。而且不加密(HTTP)的网页代理服务同样会受到关键字过滤的干扰,建议用户使用支持加密(HTTPS)的在线代理服务。另外,对于内容较复杂的网页,使用网页代理可能会出现排版错乱、乱码等问题。 镜像网站 镜像网站普遍只是邮递员,内容与官方的维基百科实时同步。 Wikiwand(英文、中文) 短网址服务 鉴于一些网络论坛中存在的地址过滤和发言字数限制,用户可以使用短网址服务压缩链接长度并绕开过滤规则,不过这些服务并不能用来绕过网络封锁。另外维基百科为了避免用户绕过垃圾链接过滤器,禁止用户添加主要短网址服务的链接,所以这些链接(除第一个外)都不能添加到维基百科中。 http://zhwp.org:访问时只需输入“http://zhwp.org/页面名”即可直接访问中文维基百科的对应页面,详见说明书。 http://t.cn:新浪微博的短网址服务,通过第三方提供的短链接生成器可以压缩任意网址。该服务在中国大陆境内较为稳定。 http://dwz.cn/:百度的短网址服务,可自定义短网址。该服务在大陆境内较稳定。 https://bit.ly:将需要压缩的地址输入其官网即可获得短链接。该服务在中国大陆境内容易受到干扰。 https://goo.gl/:Google的短网址服务。该服务于大陆境内不稳定。 外部链接 由techyan撰写的翻墙教程 讨论 Lt2818最后编辑于3天前 Wikipedia® 除非另有声明,本网站内容采用CC BY-SA 3.0授权。 隐私桌面版

Labels: , , , ,