作者归档:Henry

Ubuntu18.04 Nvidia显卡驱动安装

首先删除旧的Nvidia驱动文件

sudo apt-get purge nvidia-*

加入PPA源

sudo add-apt-repository ppa:graphics-drivers/ppa

安装Nvidia驱动

sudo apt-get update
sudo apt-get upgrade
sudo apt-get search nvidia-
找到最新的一个版本后执行安装,比如当前最新版为nvidia-390
sudo apt-get install nvidia-390

安装完重启,即可在系统信息中看见被识别出型号的Nvidia显卡

系统日志DistributedCOM 10016错误解决办法

错误日志:

应用程序-特定 权限设置并未向在应用程序容器 不可用 SID (不可用)中运行的地址 LocalHost (使用 LRPC) 中的用户PC\Henry SID (S-1-5-21-2839826810-1363819373-3356516658-1001)授予针对 CLSID 为 {D63B10C5-BB46-4990-A94F-E40B9D520160}、APPID 为 {9CA88EE3-ACB7-47C8-AFC4-AB702511C276}的 COM 服务器应用程序的 本地 激活 权限。此安全权限可以使用组件服务管理工具进行修改。

解决办法:

Regedit Take Ownership

You will need to take ownership then set rights against two different keys.  The keys are:

HKEY_CLASSES_ROOT\AppID\{9CA88EE3-ACB7-47c8-AFC4-AB702511C276}
HKEY_CLASSES_ROOT\CLSID\{D63B10C5-BB46-4990-A94F-E40B9D520160}
  1. Open Regedit with Administrators privileges and navigate to the keys above (remember you have to do this twice)
    1. WinKey + X >> Command Prompt (Admin) >> Type in Regedit
  2. Right click the key >> permissions
  3. Click advanced
  4. At the top change the Owner to COMPUTERNAME\Administrators
    1. Please note if you are domain joined you’ll have to change where you are searching from to your local computer
  5. Look in the Permission Entries field
    1. If the local system administrators group is listed ensure it has full control
    2. if the administrators group is not listed add it and give it full control.  (note you can only do this if you are a member of the administrators group and it is now the owner)
  6. Click okay a lot >> Ensure you apply permissions to all child objects

Change DCOM Permissions

Need to ensure DCOM permissions are setup

  1. Open DCOMCNFG as an Administrator
    1. WinKey + X >> Command Prompt (Admin) >> Type in DCOMCNFG
  2. Navigate to Component Services >> Computers >> My Computer >> DCOM Config
  3. Find the RunTimeBroker  >> Right Click >> Properties >> SecurityTab
  4. Launch and Activation Permissions >> Edit >> Add System and give it full control
    1. I also added the Administrators group just for testing

While changing permissions I was prompted several times to remove bad account references.  I did this as the computer knows which accounts have been removed.

翻译:

第一步:先在注册表编辑器中找到报错的两个键,修改权限,给用户完全控制权限。

第二步:以管理员身份运行“组件服务”,找到对应的DCOM,修改权限,给用户完全控制权限。

参考:

MariaDB创建用户、数据库

目标:

用户名:sampleuser
数据库名:sampledb
密码:samplepass

命令:

# Step1: Install MariaDB

yum install mariadb
systemctl start mariadb
systemctl enable mariadb


# Step2: Initialize MariaDB

mysql_secure_installation
Set root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y


# Step3: Create user and database

mysql -u root -p
MariaDB [(none)]>CREATE DATABASE sampledb;
MariaDB [(none)]>CREATE USER 'sampleuser'@'%' IDENTIFIED BY 'samplepass';
MariaDB [(none)]>GRANT ALL on sampledb.* to 'sampleuser'@'%';
MariaDB [(none)]>FLUSH PRIVILEGES;
MariaDB [(none)]>exit

 

编译安装python3

从官网下载源码包

wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz

解压

tar xvzf Python-3.6.4.tgz

准备编译需要的依赖

yum install -y gcc zlib zlib-devel openssl openssl-devel

配置并编译

./configure --prefix=/usr/local/python3.6    # 设置安装位置
make
make install

添加环境变量。在/etc/profile文件末尾追加

PATH=$PATH:/usr/local/python3.6/bin
export PATH

使环境变量生效

source /etc/profile

测试,执行python3命令,查看输出

 

CentOS添加环境变量

在Linux CentOS系统上安装完php和MySQL后,为了使用方便,需要将php和mysql命令加到系统命令中,如果在没有添加到环境变量之前,执行php -v命令查看当前php版本信息时时,则会提示命令不存在的错误,下面我们详细介绍一下在linux下将php和mysql加入到环境变量中的方法(假设php和mysql分别安装在/usr/local/webserver/php//usr/local/webserver/mysql/中)。

方法一:直接运行命令

export PATH=$PATH:/usr/local/webserver/php/bin
export PATH=$PATH:/usr/local/webserver/mysql/bin

使用这种方法,只会对当前会话有效,也就是说每当登出或注销系统以后,PATH 设置就会失效,只是临时生效。

方法二:执行vi ~/.bash_profile修改文件中PATH一行,将/usr/local/webserver/php/bin/usr/local/webserver/mysql/bin 加入到PATH=$PATH:$HOME/bin一行之后

这种方法只对当前登录用户生效

方法三:修改/etc/profile文件使其永久性生效,并对所有系统用户生效,在文件末尾加上如下两行代码

PATH=$PATH:/usr/local/webserver/php/bin:/usr/local/webserver/mysql/bin
export PATH

最后:执行 命令source /etc/profile或 执行点命令 ./profile使其修改生效,执行完可通过echo $PATH命令查看是否添加成功。

CentOS磁盘挂载

以下是一次完整的磁盘挂载、分区、格式化、LVM挂载等的过程

[root@centos ~]# fdisk -l

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbfe84878

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1  4294967295  2147483647+  ee  GPT

Disk /dev/sdb: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0001c0be

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     2099199     1048576   83  Linux
/dev/sdb2         2099200   250068991   123984896   8e  Linux LVM

Disk /dev/mapper/centos-root: 34.6 GB, 34615590912 bytes, 67608576 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 17.2 GB, 17179869184 bytes, 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-var: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@centos ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 1
Value out of range.
Partition number (2-4, default 2): q
Partition number (2-4, default 2): ^C
[root@centos ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n   
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p^H^C
[root@centos ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): m        
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): d
Selected partition 1
Partition 1 is deleted

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-250069679, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-250069679, default 250069679): 
Using default value 250069679
Partition 1 of type Linux and of size 119.2 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@centos ~]# fdisk -l

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbfe84878

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   250069679   125033816   83  Linux

Disk /dev/sdb: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0001c0be

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     2099199     1048576   83  Linux
/dev/sdb2         2099200   250068991   123984896   8e  Linux LVM

Disk /dev/mapper/centos-root: 34.6 GB, 34615590912 bytes, 67608576 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 17.2 GB, 17179869184 bytes, 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-var: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@centos ~]# l
Display all 155 possibilities? (y or n)
l.                           locate
l2ping                       lockdev
l2test                       logger
last                         login
lastb                        loginctl
lastcomm                     logname
lastlog                      logout
lchage                       logrotate
lchfn                        logsave
lchsh                        logview
ld                           look
ldattach                     losetup
ld.bfd                       lp
ldconfig                     lpadmin
ldd                          lpasswd
ld.gold                      lpc
ldns-chaos                   lpc.cups
ldns-compare-zones           lp.cups
ldnsd                        lpinfo
ldns-dane                    lpmove
ldns-dpa                     lpoptions
ldns-gen-zone                lppasswd
ldns-key2ds                  lpq
ldns-keyfetcher              lpq.cups
ldns-keygen                  lpr
ldns-mx                      lpr.cups
ldns-notify                  lprm
ldns-nsec3-hash              lprm.cups
ldns-read-zone               lprsetup.sh
ldns-resolver                lpstat
ldns-revoke                  lpstat.cups
ldns-rrsig                   ls
ldns-signzone                lsattr
ldns-test-edns               lsblk
ldns-testns                  lscgroup
ldns-update                  lscpu
ldns-verify-zone             lsinitrd
ldns-version                 lsipc
ldns-walk                    lslocks
ldns-zcat                    lslogins
ldns-zsplit                  lsmcli
--More--^C
[root@centos ~]# lsblk 
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
└─sda1            8:1    0 119.2G  0 part 
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos ~]# df -T
Filesystem              Type     1K-blocks    Used Available Use% Mounted on
/dev/mapper/centos-root xfs       33787784 3374740  30413044  10% /
devtmpfs                devtmpfs   8030912       0   8030912   0% /dev
tmpfs                   tmpfs      8042080       0   8042080   0% /dev/shm
tmpfs                   tmpfs      8042080    9136   8032944   1% /run
tmpfs                   tmpfs      8042080       0   8042080   0% /sys/fs/cgroup
/dev/sdb1               xfs        1038336  193472    844864  19% /boot
/dev/mapper/centos-home xfs       20961280   32956  20928324   1% /home
/dev/mapper/centos-var  xfs       52403200  315164  52088036   1% /var
tmpfs                   tmpfs      1608420      56   1608364   1% /run/user/0
[root@centos ~]# mkfs.
mkfs.btrfs   mkfs.ext2    mkfs.ext4    mkfs.minix   mkfs.vfat
mkfs.cramfs  mkfs.ext3    mkfs.fat     mkfs.msdos   mkfs.xfs
[root@centos ~]# mkfs.
mkfs.btrfs   mkfs.ext2    mkfs.ext4    mkfs.minix   mkfs.vfat
mkfs.cramfs  mkfs.ext3    mkfs.fat     mkfs.msdos   mkfs.xfs
[root@centos ~]# mkfs.xfs /dev/sda
sda   sda1  
[root@centos ~]# mkfs.xfs /dev/sda
sda   sda1  
[root@centos ~]# mkfs.xfs /dev/sda1
mkfs.xfs: /dev/sda1 appears to contain an existing filesystem (ntfs).
mkfs.xfs: Use the -f option to force overwrite.
[root@centos ~]# mkfs.xfs /dev/sda1 -f
meta-data=/dev/sda1              isize=512    agcount=4, agsize=7814614 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=31258454, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=15262, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@centos ~]# cd /
[root@centos /]# mkdir data
[root@centos /]# ll
total 28
lrwxrwxrwx.   1 root root    7 Mar  7 22:08 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 Mar  7 22:46 boot
drwxr-xr-x.   2 root root    6 Mar  8 09:43 data
drwxr-xr-x.  21 root root 3540 Mar  8 09:33 dev
drwxr-xr-x. 139 root root 8192 Mar  7 23:44 etc
drwxr-xr-x.   3 root root   19 Mar  7 22:12 home
lrwxrwxrwx.   1 root root    7 Mar  7 22:08 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 Mar  7 22:08 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 Nov  5  2016 media
drwxr-xr-x.   2 root root    6 Nov  5  2016 mnt
drwxr-xr-x.   3 root root   16 Mar  7 22:39 opt
dr-xr-xr-x. 308 root root    0 Mar  8 07:44 proc
dr-xr-x---.  19 root root 4096 Mar  8 09:23 root
drwxr-xr-x.  38 root root 1140 Mar  8 09:23 run
lrwxrwxrwx.   1 root root    8 Mar  7 22:08 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 Nov  5  2016 srv
dr-xr-xr-x.  13 root root    0 Mar  7 23:44 sys
drwxrwxrwt.  23 root root 4096 Mar  8 09:43 tmp
drwxr-xr-x.  13 root root  155 Mar  7 22:08 usr
drwxr-xr-x.  21 root root 4096 Mar  7 22:39 var
[root@centos /]# mount /dev/sda1 /data
[root@centos /]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        33G  3.3G   30G  10% /
devtmpfs                devtmpfs  7.7G     0  7.7G   0% /dev
tmpfs                   tmpfs     7.7G     0  7.7G   0% /dev/shm
tmpfs                   tmpfs     7.7G  9.0M  7.7G   1% /run
tmpfs                   tmpfs     7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sdb1               xfs      1014M  189M  826M  19% /boot
/dev/mapper/centos-home xfs        20G   33M   20G   1% /home
/dev/mapper/centos-var  xfs        50G  308M   50G   1% /var
tmpfs                   tmpfs     1.6G   56K  1.6G   1% /run/user/0
/dev/sda1               xfs       120G   33M  120G   1% /data
[root@centos /]# cd /etc/fstab^C
[root@centos /]# vi /etc/fstab 
[root@centos /]# 
[root@centos /]# lsblk 
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
└─sda1            8:1    0 119.2G  0 part /data
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# fdisk -l

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbfe84878

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   250069679   125033816   83  Linux

Disk /dev/sdb: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0001c0be

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     2099199     1048576   83  Linux
/dev/sdb2         2099200   250068991   123984896   8e  Linux LVM

Disk /dev/mapper/centos-root: 34.6 GB, 34615590912 bytes, 67608576 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 17.2 GB, 17179869184 bytes, 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-var: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@centos /]# fdisk -l

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbfe84878

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   250069679   125033816   83  Linux

Disk /dev/sdb: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0001c0be

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     2099199     1048576   83  Linux
/dev/sdb2         2099200   250068991   123984896   8e  Linux LVM

Disk /dev/mapper/centos-root: 34.6 GB, 34615590912 bytes, 67608576 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 17.2 GB, 17179869184 bytes, 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-home: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-var: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@centos /]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xbfe84878

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   250069679   125033816   83  Linux

Command (m for help): ^C
[root@centos /]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
Selected partition 1
Partition 1 is deleted

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@centos /]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): m  
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-250069679, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-250069679, default 250069679): 
Using default value 250069679
Partition 1 of type Linux and of size 119.2 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@centos /]# fdisk /dev/sda^C
[root@centos /]# lsblk 
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
└─sda1            8:1    0 119.2G  0 part /data
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# unmount /dev/sda
bash: unmount: command not found...
[root@centos /]# yum install unmount
Loaded plugins: fastestmirror, langpacks
base                                        | 3.6 kB     00:00     
epel/x86_64/metalink                        | 7.1 kB     00:00     
extras                                      | 3.4 kB     00:00     
updates                                     | 3.4 kB     00:00     
Loading mirror speeds from cached hostfile
 * base: centos.ustc.edu.cn
 * epel: mirror01.idc.hinet.net
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
No package unmount available.
Error: Nothing to do
[root@centos /]# umount /dev/sda
umount: /dev/sda: not mounted
[root@centos /]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
└─sda1            8:1    0 119.2G  0 part /data
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# umount /data
[root@centos /]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
└─sda1            8:1    0 119.2G  0 part 
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# mkfs.xfs /dev/sda
mkfs.xfs: /dev/sda appears to contain a partition table (dos).
mkfs.xfs: Use the -f option to force overwrite.
[root@centos /]# mkfs.xfs /dev/sda -f
meta-data=/dev/sda               isize=512    agcount=4, agsize=7814678 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=31258710, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=15263, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@centos /]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk 
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# mount /dev/sda /data
[root@centos /]# lsblk 
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 119.2G  0 disk /data
sdb               8:16   0 119.2G  0 disk 
├─sdb1            8:17   0     1G  0 part /boot
└─sdb2            8:18   0 118.2G  0 part 
  ├─centos-root 253:0    0  32.2G  0 lvm  /
  ├─centos-swap 253:1    0    16G  0 lvm  [SWAP]
  ├─centos-home 253:2    0    20G  0 lvm  /home
  └─centos-var  253:3    0    50G  0 lvm  /var
[root@centos /]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x70b67fc3.

Command (m for help): d
No partition is defined yet!

Command (m for help): ^C 
[root@centos /]# umount /data
[root@centos /]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x181824cf.

Command (m for help): p  

Disk /dev/sda: 128.0 GB, 128035676160 bytes, 250069680 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x181824cf

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): ^C 
[root@centos /]# pvcreate /dev/sda
WARNING: xfs signature detected on /dev/sda at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/sda.
  Physical volume "/dev/sda" successfully created.
[root@centos /]# pvs
  PV         VG     Fmt  Attr PSize    PFree  
  /dev/sda          lvm2 ---   119.24g 119.24g
  /dev/sdb2  centos lvm2 a--  <118.24g      0 
[root@centos /]# vgcreate -s 4m datavg /dev/sda
  Volume group "datavg" successfully created
[root@centos /]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                4
  Open LV               4
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <118.24 GiB
  PE Size               4.00 MiB
  Total PE              30269
  Alloc PE / Size       30269 / <118.24 GiB
  Free  PE / Size       0 / 0   
  VG UUID               ykO7iD-Z2Vr-RnSN-nmdz-dDjx-AZlu-WGTO3L
   
  --- Volume group ---
  VG Name               datavg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <119.24 GiB
  PE Size               4.00 MiB
  Total PE              30525
  Alloc PE / Size       0 / 0   
  Free  PE / Size       30525 / <119.24 GiB
  VG UUID               2Vt33P-4wry-4CHm-fzFd-ivoL-6uLe-fPk8fz
   
[root@centos /]# vgdisplay datavbg
  Volume group "datavbg" not found
  Cannot process volume group datavbg
[root@centos /]# vgdisplay datavg
  --- Volume group ---
  VG Name               datavg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <119.24 GiB
  PE Size               4.00 MiB
  Total PE              30525
  Alloc PE / Size       0 / 0   
  Free  PE / Size       30525 / <119.24 GiB
  VG UUID               2Vt33P-4wry-4CHm-fzFd-ivoL-6uLe-fPk8fz
   
[root@centos /]# lvcreate -l 30525 -n lv_data datavg
  Logical volume "lv_data" created.
[root@centos /]# lvs
  LV      VG     Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home    centos -wi-ao----   20.00g                                                    
  root    centos -wi-ao----  <32.24g                                                    
  swap    centos -wi-ao----   16.00g                                                    
  var     centos -wi-ao----   50.00g                                                    
  lv_data datavg -wi-a----- <119.24g                                                    
[root@centos /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   33G  3.3G   30G  10% /
devtmpfs                 7.7G     0  7.7G   0% /dev
tmpfs                    7.7G     0  7.7G   0% /dev/shm
tmpfs                    7.7G  9.0M  7.7G   1% /run
tmpfs                    7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sdb1               1014M  189M  826M  19% /boot
/dev/mapper/centos-home   20G   33M   20G   1% /home
/dev/mapper/centos-var    50G  307M   50G   1% /var
tmpfs                    1.6G   56K  1.6G   1% /run/user/0
[root@centos /]# mkfs.xfs /dev/mapper/datavg-lv_data
meta-data=/dev/mapper/datavg-lv_data isize=512    agcount=4, agsize=7814400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=31257600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=15262, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@centos /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   33G  3.3G   30G  10% /
devtmpfs                 7.7G     0  7.7G   0% /dev
tmpfs                    7.7G     0  7.7G   0% /dev/shm
tmpfs                    7.7G  9.0M  7.7G   1% /run
tmpfs                    7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sdb1               1014M  189M  826M  19% /boot
/dev/mapper/centos-home   20G   33M   20G   1% /home
/dev/mapper/centos-var    50G  307M   50G   1% /var
tmpfs                    1.6G   56K  1.6G   1% /run/user/0
[root@centos /]# lvs
  LV      VG     Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home    centos -wi-ao----   20.00g                                                    
  root    centos -wi-ao----  <32.24g                                                    
  swap    centos -wi-ao----   16.00g                                                    
  var     centos -wi-ao----   50.00g                                                    
  lv_data datavg -wi-a----- <119.24g                                                    
[root@centos /]# mount /dev/mapper/datavg-lv_data /data
[root@centos /]# df -h
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/centos-root      33G  3.3G   30G  10% /
devtmpfs                    7.7G     0  7.7G   0% /dev
tmpfs                       7.7G     0  7.7G   0% /dev/shm
tmpfs                       7.7G  9.0M  7.7G   1% /run
tmpfs                       7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sdb1                  1014M  189M  826M  19% /boot
/dev/mapper/centos-home      20G   33M   20G   1% /home
/dev/mapper/centos-var       50G  307M   50G   1% /var
tmpfs                       1.6G   56K  1.6G   1% /run/user/0
/dev/mapper/datavg-lv_data  120G   33M  120G   1% /data
[root@centos /]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Wed Mar  7 22:08:19 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=b118055d-ded6-4cf2-9587-31f28414e5f9 /boot                   xfs     defaults        0 0
/dev/mapper/centos-home /home                   xfs     defaults        0 0
/dev/mapper/centos-var  /var                    xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
[root@centos /]# umount /data/
[root@centos /]# df -h 
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   33G  3.3G   30G  10% /
devtmpfs                 7.7G     0  7.7G   0% /dev
tmpfs                    7.7G     0  7.7G   0% /dev/shm
tmpfs                    7.7G  9.0M  7.7G   1% /run
tmpfs                    7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/sdb1               1014M  189M  826M  19% /boot
/dev/mapper/centos-home   20G   33M   20G   1% /home
/dev/mapper/centos-var    50G  307M   50G   1% /var
tmpfs                    1.6G   56K  1.6G   1% /run/user/0
[root@centos /]# lvremove /dev/mapper/
centos-home     centos-root     centos-swap     centos-var      datavg-lv_data  
[root@centos /]# lvremove /dev/mapper/
centos-home     centos-root     centos-swap     centos-var      datavg-lv_data  
[root@centos /]# lvremove /dev/mapper/datavg-lv_data 
Do you really want to remove active logical volume datavg/lv_data? [y/n]: y
  Logical volume "lv_data" successfully removed
[root@centos /]# vgremove /dev/sda
  Volume group "sda" not found
  Cannot process volume group sda
[root@centos /]# vgremove datavg
  Volume group "datavg" successfully removed
[root@centos /]# pvremove /dev/sda
  Labels on physical volume "/dev/sda" successfully wiped.

分区后,修改/etc/fstab文件保存目录挂载信息即可

再一次回归阿里云ECS

网站从三年前离开阿里云ECS后一直使用的是HK的服务器,虽然稳定而且支持外网访问,但是价格较高。经过三年的成长,阿里云的服务器价格下降十分明显。处于成本考虑,决定再次将网站迁移至阿里云。

目前使用的实例为ecs.xn4.small规格,配置为1C1G1M的最简配置。虽然配置不高,但只用于支持一个个人博客站还是足够了。目前的服务器放在广受好评的华东1区,从深圳访问速度也还是不错的。

 

TensorFlow学习笔记04

MNIST入门

import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'

import tensorflow as tf

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

x = tf.placeholder(tf.float32, [None, 784])

W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))

y = tf.nn.softmax(tf.matmul(x, W) + b)

y_ = tf.placeholder(tf.float32, [None, 10])

cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))

train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)

sess = tf.InteractiveSession()

tf.global_variables_initializer().run()

for _ in range(1000):
  batch_xs, batch_ys = mnist.train.next_batch(100)
  sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})

correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))

accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))

修改系统错误级别排除以下错误告警:Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX

import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'

引入MNIST数据集

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

建立回归模型

y = tf.nn.softmax(tf.matmul(x,W) + b)

 

TensorFlow学习笔记03

来自于官方教程中的一个例子,使用梯度下降算法进行线性逼近

import tensorflow as tf

# Model parameters
W = tf.Variable([.3], dtype=tf.float32)
b = tf.Variable([-.3], dtype=tf.float32)
# Model input and output
x = tf.placeholder(tf.float32)
linear_model = W*x + b
y = tf.placeholder(tf.float32)

# loss
loss = tf.reduce_sum(tf.square(linear_model - y)) # sum of the squares
# optimizer
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(loss)

# training data
x_train = [1, 2, 3, 4]
y_train = [0, -1, -2, -3]
# training loop
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init) # reset values to wrong
for i in range(1000):
  sess.run(train, {x: x_train, y: y_train})

# evaluate training accuracy
curr_W, curr_b, curr_loss = sess.run([W, b, loss], {x: x_train, y: y_train})
print("W: %s b: %s loss: %s"%(curr_W, curr_b, curr_loss))

训练集

x_train = [1, 2, 3, 4]
y_train = [0, -1, -2, -3]

使用梯度下降算法,步进0.01,求方差最小化

optimizer = tf.train.GradientDescentOptimizer(0.01)
train = optimizer.minimize(loss)

结果

W: [-0.9999969] b: [ 0.99999082] loss: 5.69997e-11

TensorFlow学习笔记02

在TensorFlow中文社区文档中,有一个使用TensorFlow API进行拟合的事例。但代码注释比较简略,导致学习的时候有些不明白,这里给出详细的注释。

import tensorflow as tf
import numpy as np

# 使用 NumPy 生成假数据(phony data), 总共 100 个点.
# np.random.rand(x, y)生成1个含有x个长度为y的array的array
x_data = np.float32(np.random.rand(2, 100)) 
# np.dot(x, y)对矩阵x和y进行矩阵乘运算
y_data = np.dot([0.100, 0.200], x_data) + 0.300

# 构造一个线性模型
# tf.zeros(shape)生成尺寸为shape的张量,值为0的张量
b = tf.Variable(tf.zeros([1]))
# tf.random_uniform(shape, min, max)生成尺寸为shape,值为min~max之间随机数的张量
W = tf.Variable(tf.random_uniform([1, 2], -1.0, 1.0))
y = tf.matmul(W, x_data) + b

# 最小化方差
'''
A loss function measures how far apart the current model is from the provided data. We'll use a standard loss model for linear regression, which sums the squares of the deltas between the current model and the provided data. linear_model - y creates a vector where each element is the corresponding example's error delta. We call tf.square to square that error. Then, we sum all the squared errors to create a single scalar that abstracts the error of all examples using tf.reduce_sum
'''
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)

# 初始化变量
# 新版本中已经更新为tf.global_variables_initializer()
init = tf.initialize_all_variables()

# 启动图 (graph)
sess = tf.Session()
sess.run(init)

# 拟合平面
# python3中为range(min, max)
for step in xrange(0, 201):
    sess.run(train)
    if step % 20 == 0:
        #python3中为print()
        print step, sess.run(W), sess.run(b)

# 得到最佳拟合结果 W: [[0.100  0.200]], b: [0.300]

这个文档中使用的python版本为2.x,所以使用python3时会出现不兼容的情况。另外文档也比较老了,很多函数都已经更新。建议直接阅读官方文档。