首页 文章 精选 留言 我的

精选列表

搜索[EdgeOneMakersAgent案例],共10000篇文章
优秀的个人博客,低调大师

关于limits生效的四个案例

第一个问题limits.conf的限制在/proc/pid/limits中未生效 # cat /proc/3606/limits Limit Soft Limit Hard Limit Units Max processes 31202 31202 processes Max open files 1024 4096 files 在Centos7 & ubuntu 系统中,使用Systemd替代了之前的SysV。/etc/security/limits.conf文件的配置作用域缩小了。/etc/security/limits.conf的配置,只适用于通过PAM认证登录用户的资源限制,它对systemd的service的资源限制不生效。因此登录用户的限制,通过/etc/security/limits.conf与/etc/security/limits.d下的文件设置即可。 对于systemd service的资源设置,则需修改全局配置,全局配置文件放在/etc/systemd/system.conf和/etc/systemd/user.conf,同时也会加载两个对应目录中的所有.conf文件/etc/systemd/system.conf.d/.conf和/etc/systemd/user.conf.d/.confsystem.conf是系统实例使用的,user.conf是用户实例使用的。 vim /etc/systemd/system.conf DefaultLimitNOFILE=100000 DefaultLimitNPROC=65535 修改并重启即可 # cat /proc/3613/limits Limit Soft Limit Hard Limit Units Max processes 65535 65535 processes Max open files 100000 100000 files 第二个问题在服务里面设置LimitNOFILE=infinity为什么不是无穷大?在服务里面设置LimitNOFILE=infinity 后,通过查看pid的limit发现openfile是65536 ,而不是无穷大查看服务配置 [root@iZwz98aynkjcxvtra0f375Z ~]# cat /etc/systemd/system/multi-user.target.wants/docker.service |grep -vi "^#"|grep -vi "^$" [Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com BindsTo=containerd.service After=network-online.target firewalld.service containerd.service Wants=network-online.target Requires=docker.socket [Service] Type=notify ExecStart=/usr/bin/dockerd -H fd:// ExecStartPost=/usr/sbin/iptables -P FORWARD ACCEPT ExecReload=/bin/kill -s HUP $MAINPID TimeoutSec=0 RestartSec=2 Restart=always StartLimitBurst=3 StartLimitInterval=60s LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity TasksMax=infinity Delegate=yes KillMode=process [Install] WantedBy=multi-user.target 查看配置效果 # cat /proc/11019/limits Limit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 8388608 unlimited bytes Max core file size 0 unlimited bytes Max resident set unlimited unlimited bytes Max processes 31202 31202 processes Max open files 65536 65536 files Max locked memory 65536 65536 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 31202 31202 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us 这个是systemd的bug,低于240的版本需要手动设置才可以生效LimitNOFILE=102400https://github.com/systemd/systemd/issues/6559 第三个问题为什么openfile不能设置为unlimited [root@iZwz98aynkjcxvtra0f375Z ~]# ulimit -n 65535 [root@iZwz98aynkjcxvtra0f375Z ~]# ulimit -n unlimited -bash: ulimit: open files: cannot modify limit: Operation not permitted 原因是 centos7里 openfile不能大于nr_open [root@iZwz98aynkjcxvtra0f375Z ~]# cat /proc/sys/fs/nr_open 1048576 [root@iZwz98aynkjcxvtra0f375Z ~]# ulimit -n 1048577 -bash: ulimit: open files: cannot modify limit: Operation not permitted [root@iZwz98aynkjcxvtra0f375Z ~]# ulimit -n 1048576 [root@iZwz98aynkjcxvtra0f375Z ~]# ulimit -n 1048576 关于file-max nr_open file_nr的解释 可参考https://www.kernel.org/doc/Documentation/sysctl/fs.txt 第四个问题使用supervisor管理进程(测试环境ubuntu 1604)启动进程后,maxfile是1024需要修改配置文件 #cat /etc/supervisor/supervisord.conf [supervisord] logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log) pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid) childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP) 下面这两行 minfds=655350 ; min. avail startup file descriptors; default 1024 minprocs=65535 ; min. avail process descriptors;default 200 # cat /proc/2423/limits Limit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 8388608 unlimited bytes Max core file size 0 unlimited bytes Max resident set unlimited unlimited bytes Max processes 65535 65535 processes Max open files 655350 655350 files ------------修改成功 Max locked memory 65536 65536 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 61946 61946 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us 外部文档https://www.cnblogs.com/zengkefu/p/5635153.htmlhttps://blog.csdn.net/google0802/article/details/52304776http://blog.cloud.360.cn/post/tuning-your-system-for-high-concurrency.htmlhttps://blog.csdn.net/qq_38165374/article/details/104881340

优秀的个人博客,低调大师

Nginx Linux详细安装部署教程(附带使用案例)

一、Nginx简介 Nginx是一个web服务器也可以用来做负载均衡及反向代理使用,目前使用最多的就是负载均衡,具体简介我就不介绍了百度一下有很多,下面直接进入安装步骤。安装Nginx是在云服务器Linux操作系统环境上操作的,因为在Linux操作系统上进行web应用开发是最常见的。也是企业用的最多的。这里我选的是阿里云。 二、Nginx安装 1、下载Nginx及相关组件 Linux系统是Centos 6.5 64位,我直接切换到root用户下安装 进入用户目录下载程序 下载相关组件 [root@localhost src]# wget http://nginx.org/download/nginx-1.10.2.tar.gz 省略安装内容... [root@localhost src]# wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz 省略安装内容... [root@localhost src]# wget http://zlib.net/zlib-1.2.11.tar.gz 省略安装内容... [root@localhost src]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz 省略安装内容... 安装c++编译环境,如已安装可略过 [root@localhost src]# yum install gcc-c++ 省略安装内容... 期间会有确认提示输入y回车 Is this ok [y/N]:y 省略安装内容... 2、安装Nginx及相关组件 openssl安装 [root@localhost src]# tar zxvf openssl-fips-2.0.10.tar.gz 省略安装内容... [root@localhost src]# cd openssl-fips-2.0.10 [root@localhost openssl-fips-2.0.10]# ./config && make && make install 省略安装内容... pcre安装 [root@localhost src]# tar zxvf pcre-8.40.tar.gz 省略安装内容... [root@localhost src]# cd pcre-8.40 [root@localhost pcre-8.40]# ./configure && make && make install 省略安装内容... zlib安装 [root@localhost src]# tar zxvf zlib-1.2.11.tar.gz 省略安装内容... [root@localhost src]# cd zlib-1.2.11 [root@localhost zlib-1.2.11]# ./configure && make && make install 省略安装内容... nginx安装 [root@localhost src]# tar zxvf nginx-1.10.2.tar.gz 省略安装内容... [root@localhost src]# cd nginx-1.10.2 [root@localhost nginx-1.10.2]# ./configure && make && make install 省略安装内容... 3、启动Nginx 先找一下nginx安装到什么位置上了 进入nginx目录并启动 报错了,error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory,按照下面方式解决 1.用whereis libpcre.so.1命令找到libpcre.so.1在哪里 2.用ln -s /usr/local/lib/libpcre.so.1 /lib64命令做个软连接就可以了 3.用sbin/nginx启动Nginx 4.用ps -aux | grep nginx查看状态 [root@localhost nginx]# whereis libpcre.so.1 [root@localhost nginx]# ln -s /usr/local/lib/libpcre.so.1 /lib64 [root@localhost nginx]# sbin/nginx [root@localhost nginx]# ps -aux | grep nginx 进入Linux系统的图形界面,打开浏览器输入localhost会看到下图,说明nginx启动成功 nginx的基本操作 启动 [root@localhost ~]# /usr/local/nginx/sbin/nginx 停止/重启 [root@localhost ~]# /usr/local/nginx/sbin/nginx -s stop(quit、reload) 命令帮助 [root@localhost ~]# /usr/local/nginx/sbin/nginx -h 验证配置文件 [root@localhost ~]# /usr/local/nginx/sbin/nginx -t 配置文件 [root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf 4、简单配置Nginx 打开nginx配置文件位于nginx目录下的conf文件夹下 简单介绍一下vim的语法 默认vim打开后是不能录入的,需要按键才能操作,具体如下: 开启编辑:按“i”或者“Insert”键 退出编辑:“Esc”键 退出vim:“:q” 保存vim:“:w” 保存退出vim:“:wq” 不保存退出vim:“:q!” "#"代表注释,最重要的是server{}块这部分就代表每一个web站点,详细的配置介绍可以查阅我的另一片配置文章,此处我们先暂时设置三个站点 分别使用不同的端口80、81、82保存退出并且重启nginx 5、开启外网访问 在Linux系统中默认有防火墙Iptables管理者所有的端口,只启用默认远程连接22端口其他都关闭,咱们上面设置的80等等也是关闭的,所以我们需要先把应用的端口开启 方法一直接关闭防火墙,这样性能较好,但安全性较差,如果有前置防火墙可以采取这种方式 关闭防火墙 [root@localhost ~]# service iptables stop 关闭开机自启动防火墙 [root@localhost ~]# chkconfig iptables off [root@localhost ~]# chkconfig --list|grep ipt 下面是防火墙的其他操作命令 方法二将开启的端口加入防火墙白名单中,这种方式较安全但性能也相对较差 编辑防火墙白名单 [root@localhost ~]# vim /etc/sysconfig/iptables 增加下面一行代码 -A INPUT -p tcp -m state -- state NEW -m tcp --dport 80 -j ACCEPT 保存退出,重启防火墙 [root@localhost ~]# service iptables restart Linux配置完毕了,使用另一台电脑而非安装nginx的电脑,我是用的windows系统,配置一下host在“C:WindowsSystem32driversetc”下的hosts中配置一下域名重定向 10.11.13.22 nginx.test.com nginx.test1.com nginx.test2.com 然后cmd再ping一下这个域名是否正确指向了这个IP上 正确指向后在telnet一下80端口看一下是否可以与端口通信(如果telnet提示没有此命令是没有安装客户端,在启用或禁用windows功能处安装后再操作即可) 得到以下界面及代表通信成功 打开这台Windows系统内的浏览器,输入nginx.test.com会得到以下结果,就说明外网访问成功 如果防火墙你依然启用,只是设置了启用端口,那我们访问81那个端口会发现无法访问,因为我并没有加入白名单 到此Nginx服务器雏形部署完成。 6、Nginx负载均衡配置 Nginx集反向代理和负载均衡于一身,在配置文件中修改配就可以实现 首先我们打开配置文件 [root@localhost nginx]# vim conf/nginx.conf 每一个server就是一个虚拟主机,我们有一个当作web服务器来使用 listen 80;代表监听80端口 server_name xxx.com;代表外网访问的域名 location / {};代表一个过滤器,/匹配所有请求,我们还可以根据自己的情况定义不同的过滤,比如对静态文件js、css、image制定专属过滤 root html;代表站点根目录 index index.html;代表默认主页 这样配置完毕我们输入域名就可以访问到该站点了。 负载均衡功能往往在接收到某个请求后分配到后端的多台服务器上,那我们就需要upstream{}块来配合使用 upstream xxx{};upstream模块是命名一个后端服务器组,组名必须为后端服务器站点域名,内部可以写多台服务器ip和port,还可以设置跳转规则及权重等等 ip_hash;代表使用ip地址方式分配跳转后端服务器,同一ip请求每次都会访问同一台后端服务器 server;代表后端服务器地址 server{};server模块依然是接收外部请求的部分 server_name;代表外网访问域名 location / {};同样代表过滤器,用于制定不同请求的不同操作 proxy_pass;代表后端服务器组名,此组名必须为后端服务器站点域名 server_name和upstream{}的组名可以不一致,server_name是外网访问接收请求的域名,upstream{}的组名是跳转后端服务器时站点访问的域名 配置一下Windows的host将我们要访问的域名aaa.test.com指向Linux 因为硬件有限,我是将Windows中的IIS作为Nginx的后端服务器,所以配置一下IIS的站点域名 打开cmd再ping一下aaa.test.com确实指向Linux系统了,再打开浏览器输入aaa.test.com会显示bbb这个站点就代表负载成功了。 Nginx的负载功能就配置完成了,这只是简单设置了一下,生产环境中还有很多详细的调整,后续再逐渐增加,本人水平有限,如有不对之处还望指导谢谢。

优秀的个人博客,低调大师

Oracle 11g on ECS 测试实践--安装案例

参考文档:MOS Doc ID 472408.1基于 AMERICAN_AMERICA.US7ASCII 字符集 [oracle@orcl1 schema]$ cd /u01/app/oracle/product/11.2.0/db_1/demo/schema/ [oracle@orcl1 schema]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.4.0 Production on Thu Jul 25 15:54:50 2019 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> @mkplug.sql specify password for SYS as parameter 1: Enter value for 1: oracle specify password for HR as parameter 2: Enter value for 2: oracle specify password for OE as parameter 3: Enter value for 3: oracle specify password for PM as parameter 4: Enter value for 4: oracle specify password for IX as parameter 5: Enter value for 5: oracle specify password for SH as parameter 6: Enter value for 6: oracle specify password for BI as parameter 7: Enter value for 7: oracle specify INPUT metadata import file as parameter 8: Enter value for 8: /u01/app/oracle/product/11.2.0/db_1/assistants/dbca/templates/example.dmp specify INPUT database backup file for tablespace EXAMPLE as parameter 9: Enter value for 9: /u01/app/oracle/product/11.2.0/db_1/assistants/dbca/templates/example01.dfb specify OUTPUT database file for tablespace EXAMPLE as parameter 10: Enter value for 10: /oradata/ORCL/example01.dbf specify OUTPUT log directory as parameter 11: Enter value for 11: /home/oracle/log.txt specify OUTPUT dump file directory as parameter 12: Enter value for 12: /home/oracle/ Sample Schemas are being plugged in ... Connected. TO_CHAR(SYSTIMEST ----------------- 20190725 04:01:07 1 row selected. old 1: CREATE USER hr IDENTIFIED BY &&password_hr new 1: CREATE USER hr IDENTIFIED BY oracle User created. old 1: CREATE USER oe IDENTIFIED BY &&password_oe new 1: CREATE USER oe IDENTIFIED BY oracle User created. old 1: CREATE USER ix IDENTIFIED BY &&password_ix new 1: CREATE USER ix IDENTIFIED BY oracle User created. old 1: CREATE USER sh IDENTIFIED BY &&password_sh new 1: CREATE USER sh IDENTIFIED BY oracle User created. old 1: CREATE USER pm IDENTIFIED BY &&password_pm new 1: CREATE USER pm IDENTIFIED BY oracle User created. old 1: CREATE USER bi IDENTIFIED BY &&password_bi new 1: CREATE USER bi IDENTIFIED BY oracle User created. SQL> SET FEEDBACK 1 SQL> SET NUMWIDTH 10 SQL> SET LINESIZE 80 SQL> SET TRIMSPOOL ON SQL> SET TAB OFF SQL> SET PAGESIZE 100 SQL> SQL> CREATE OR REPLACE DIRECTORY data_file_dir AS '/u01/app/oracle/product/11.2.0/db_1/demo/schema/sales_history/'; Directory created. SQL> CREATE OR REPLACE DIRECTORY log_file_dir AS '/u01/app/oracle/product/11.2.0/db_1/demo/schema/log/'; Directory created. SQL> CREATE OR REPLACE DIRECTORY media_dir AS '/u01/app/oracle/product/11.2.0/db_1/demo/schema/product_media/'; Directory created. SQL> SQL> GRANT READ ON DIRECTORY media_dir TO pm; Grant succeeded. SQL> GRANT READ ON DIRECTORY log_file_dir TO sh; Grant succeeded. SQL> GRANT READ ON DIRECTORY data_file_dir TO sh; Grant succeeded. SQL> GRANT WRITE ON DIRECTORY log_file_dir TO sh; Grant succeeded. SQL> EXECUTE DBMS_DATAPUMP_UTL.REPLACE_DEFAULT_DIR; PL/SQL procedure successfully completed. SQL> EXECUTE ORACLE_OCM.MGMT_CONFIG_UTL.create_replace_dir_obj; PL/SQL procedure successfully completed. SQL> SQL> GRANT CREATE SESSION TO hr; Grant succeeded. SQL> GRANT ALTER SESSION TO hr; Grant succeeded. SQL> GRANT CREATE DATABASE LINK TO hr; Grant succeeded. SQL> GRANT CREATE SEQUENCE TO hr; Grant succeeded. SQL> GRANT CREATE SYNONYM TO hr; Grant succeeded. SQL> GRANT CREATE VIEW TO hr; Grant succeeded. SQL> GRANT RESOURCE TO hr; Grant succeeded. SQL> GRANT execute ON sys.dbms_stats TO hr; Grant succeeded. SQL> SQL> GRANT CREATE SESSION TO oe; Grant succeeded. SQL> GRANT CREATE DATABASE LINK TO oe; Grant succeeded. SQL> GRANT CREATE SYNONYM TO oe; Grant succeeded. SQL> GRANT CREATE VIEW TO oe; Grant succeeded. SQL> GRANT RESOURCE TO oe; Grant succeeded. SQL> GRANT CREATE MATERIALIZED VIEW TO oe; Grant succeeded. SQL> GRANT QUERY REWRITE TO oe; Grant succeeded. SQL> GRANT execute ON sys.dbms_stats TO oe; Grant succeeded. SQL> SQL> GRANT CONNECT TO pm; Grant succeeded. SQL> GRANT RESOURCE TO pm; Grant succeeded. SQL> GRANT execute ON sys.dbms_stats TO pm; Grant succeeded. SQL> GRANT READ ON DIRECTORY media_dir TO pm; Grant succeeded. SQL> SQL> GRANT CONNECT TO ix; Grant succeeded. SQL> GRANT RESOURCE TO ix; Grant succeeded. SQL> SQL> GRANT aq_administrator_role TO ix; Grant succeeded. SQL> GRANT aq_user_role TO ix; Grant succeeded. SQL> SQL> GRANT ALTER SESSION TO ix; Grant succeeded. SQL> GRANT CREATE CLUSTER TO ix; Grant succeeded. SQL> GRANT CREATE DATABASE LINK TO ix; Grant succeeded. SQL> GRANT CREATE SEQUENCE TO ix; Grant succeeded. SQL> GRANT CREATE SESSION TO ix; Grant succeeded. SQL> GRANT CREATE SYNONYM TO ix; Grant succeeded. SQL> GRANT CREATE TABLE TO ix; Grant succeeded. SQL> GRANT CREATE VIEW TO ix; Grant succeeded. SQL> GRANT CREATE CLUSTER TO ix; Grant succeeded. SQL> GRANT CREATE INDEXTYPE TO ix; Grant succeeded. SQL> GRANT CREATE OPERATOR TO ix; Grant succeeded. SQL> GRANT CREATE PROCEDURE TO ix; Grant succeeded. SQL> GRANT CREATE SEQUENCE TO ix; Grant succeeded. SQL> GRANT CREATE TABLE TO ix; Grant succeeded. SQL> GRANT CREATE TRIGGER TO ix; Grant succeeded. SQL> GRANT CREATE TYPE TO ix; Grant succeeded. SQL> GRANT CREATE SESSION TO ix; Grant succeeded. SQL> SQL> GRANT CONNECT, RESOURCE, SELECT_CATALOG_ROLE TO ix; Grant succeeded. SQL> SQL> GRANT EXECUTE ON sys.dbms_stats TO ix; Grant succeeded. SQL> GRANT EXECUTE ON DBMS_AQ TO ix; Grant succeeded. SQL> GRANT EXECUTE ON DBMS_AQADM TO ix; Grant succeeded. SQL> GRANT EXECUTE ON DBMS_APPLY_ADM TO ix; Grant succeeded. SQL> GRANT EXECUTE ON DBMS_CAPTURE_ADM TO ix; Grant succeeded. SQL> GRANT EXECUTE ON DBMS_FLASHBACK TO ix; Grant succeeded. SQL> GRANT EXECUTE ON DBMS_PROPAGATION_ADM TO ix; Grant succeeded. SQL> GRANT EXECUTE ON DBMS_STREAMS_ADM TO ix; Grant succeeded. SQL> GRANT SELECT ANY DICTIONARY TO ix; Grant succeeded. SQL> SQL> EXECUTE DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE( - > privilege => DBMS_RULE_ADM.CREATE_RULE_SET_OBJ, - > grantee => 'ix', - > grant_option => FALSE); PL/SQL procedure successfully completed. SQL> SQL> EXECUTE DBMS_RULE_ADM.GRANT_SYSTEM_PRIVILEGE( - > privilege => DBMS_RULE_ADM.CREATE_RULE_OBJ, - > grantee => 'ix', - > grant_option => FALSE); PL/SQL procedure successfully completed. SQL> SQL> GRANT CREATE SESSION TO sh; Grant succeeded. SQL> GRANT CREATE TABLE TO sh; Grant succeeded. SQL> GRANT CREATE VIEW TO sh; Grant succeeded. SQL> GRANT CREATE CLUSTER TO sh; Grant succeeded. SQL> GRANT ALTER SESSION TO sh; Grant succeeded. SQL> GRANT CREATE SEQUENCE TO sh; Grant succeeded. SQL> GRANT CREATE SYNONYM TO sh; Grant succeeded. SQL> GRANT CREATE DATABASE LINK TO sh; Grant succeeded. SQL> GRANT CREATE DIMENSION TO sh; Grant succeeded. SQL> GRANT QUERY REWRITE TO sh; Grant succeeded. SQL> GRANT CREATE MATERIALIZED VIEW TO sh; Grant succeeded. SQL> GRANT CREATE VIEW TO sh; Grant succeeded. SQL> GRANT RESOURCE TO sh; Grant succeeded. SQL> GRANT select_catalog_role TO sh; Grant succeeded. SQL> GRANT cwm_user TO sh; Grant succeeded. SQL> GRANT execute ON sys.dbms_stats TO sh; Grant succeeded. SQL> rem ALTER USER sh GRANT CONNECT THROUGH olapsvr; SQL> SQL> GRANT CREATE SESSION TO bi; Grant succeeded. SQL> GRANT CREATE TABLE TO bi; Grant succeeded. SQL> GRANT CREATE VIEW TO bi; Grant succeeded. SQL> GRANT CREATE CLUSTER TO bi; Grant succeeded. SQL> GRANT ALTER SESSION TO bi; Grant succeeded. SQL> GRANT CREATE SEQUENCE TO bi; Grant succeeded. SQL> GRANT CREATE SYNONYM TO bi; Grant succeeded. SQL> GRANT CREATE DATABASE LINK TO bi; Grant succeeded. SQL> GRANT RESOURCE TO bi; Grant succeeded. SQL> SQL> -- SQL> -- Restoring database file backup SQL> -- (Using RMAN works in OMF, OCFS, raw devices and in normal file systems) SQL> -- SQL> SQL> SQL> set echo off; TO_CHAR(SYSTIMEST ----------------- 20190725 04:01:07 1 row selected. old 30: dbms_backup_restore.restoreDataFileTo(data_file_id,'&data_file_name'); new 30: dbms_backup_restore.restoreDataFileTo(data_file_id,'/oradata/ORCL/example01.dbf'); old 33: dbms_backup_restore.restoreBackupPiece('&dump_path'||'&data_file_backup', done); new 33: dbms_backup_restore.restoreBackupPiece('/home/oracle/'||'/u01/app/oracle/product/11.2.0/db_1/assistants/dbca/templates/example01.dfb', done); Allocating device.... Specifying datafiles... Specifing datafiles... Restoring ... declare * ERROR at line 1: ORA-19624: operation failed, retry possible ORA-19870: error while restoring backup piece /home/oracle/u01/app/oracle/product/11.2.0/db_1/assistants/dbca/templates/exampl e01.dfb ORA-19505: failed to identify file "/home/oracle/u01/app/oracle/product/11.2.0/db_1/assistants/dbca/templates/examp le01.dfb" ORA-27037: unable to obtain file status Linux-x86_64 Error: 2: No such file or directory Additional information: 3 ORA-06512: at "SYS.DBMS_BACKUP_RESTORE", line 5937 ORA-06512: at line 33 1 row selected. TO_CHAR(SYSTIMEST ----------------- 20190725 04:01:07 1 row selected. old 1: create or replace directory SS_IMPEXP_DIR as '&dump_path' new 1: create or replace directory SS_IMPEXP_DIR as '/home/oracle/' Directory created. Grant succeeded. old 1: create or replace directory SS_LOGPATH_DIR as '&log_path' new 1: create or replace directory SS_LOGPATH_DIR as '/home/oracle/log.txt' Directory created. Grant succeeded. LRM-00118: syntax error at '=' at the end of input Connected. TO_CHAR(SYSTIMEST ----------------- 20190725 04:01:08 1 row selected. ALTER TABLESPACE example READ WRITE * ERROR at line 1: ORA-00959: tablespace 'EXAMPLE' does not exist TABLESPACE_NAME FILE_NAME STATUS --------------- ---------------------------------------------- --------- SYSTEM /oradata/ORCL/system01.dbf AVAILABLE SYSAUX /oradata/ORCL/sysaux01.dbf AVAILABLE UNDOTBS1 /oradata/ORCL/undotbs01.dbf AVAILABLE USERS /oradata/ORCL/user01.dbf AVAILABLE 4 rows selected. Creating sequences, views, procedures and objects privileges for HR ... TO_CHAR(SYSTIMEST ----------------- 20190725 04:01:08 1 row selected. Connected. Sequence created. Sequence created. Sequence created. regions r * ERROR at line 41: ORA-00942: table or view does not exist Procedure created. BEFORE INSERT OR UPDATE OR DELETE ON employees * ERROR at line 2: ORA-00942: table or view does not exist ALTER TRIGGER secure_employees DISABLE * ERROR at line 1: ORA-04080: trigger 'SECURE_EMPLOYEES' does not exist Warning: Procedure created with compilation errors. AFTER UPDATE OF job_id, department_id ON employees * ERROR at line 2: ORA-00942: table or view does not exist Commit complete. GRANT REFERENCES, SELECT ON employees TO oe * ERROR at line 1: ORA-00942: table or view does not exist GRANT REFERENCES, SELECT ON countries TO oe * ERROR at line 1: ORA-00942: table or view does not exist GRANT REFERENCES, SELECT ON locations TO oe * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON jobs TO oe * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON job_history TO oe * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON departments TO oe * ERROR at line 1: ORA-00942: table or view does not exist Creating synonyms, sequences, views and functions for OE ... TO_CHAR(SYSTIMEST ----------------- 20190725 04:01:08 1 row selected. Connected. Synonym created. Synonym created. Synonym created. Synonym created. Synonym created. Synonym created. Sequence created. , product_descriptions d * ERROR at line 22: ORA-00942: table or view does not exist , products p * ERROR at line 8: ORA-00942: table or view does not exist , products p * ERROR at line 8: ORA-00942: table or view does not exist , products p * ERROR at line 8: ORA-00942: table or view does not exist FROM product_information * ERROR at line 7: ORA-00942: table or view does not exist FROM customers c, countries cr * ERROR at line 7: ORA-00980: synonym translation is no longer valid Warning: Function created with compilation errors. customers c * ERROR at line 30: ORA-00942: table or view does not exist FROM orders * ERROR at line 11: ORA-00942: table or view does not exist Creating XML schema, XML folders, OC subschema and objects privileges for OE ... TO_CHAR(SYSTIMEST ----------------- 20190725 04:01:08 1 row selected. specify password for OE as parameter 1: PROMPT password for SYS as parameter 2: Connected. Grant succeeded. Grant succeeded. Grant succeeded. Grant succeeded. 1* GRANT alter session TO oe Grant succeeded. View created. View created. Grant succeeded. Session altered. Package created. Warning: Package Body created with compilation errors. View created. Package altered. View altered. Grant succeeded. Trigger created. Synonym created. Grant succeeded. Call completed. Session altered. Session altered. Function created. no rows selected Synonym created. Grant succeeded. Package created. no rows selected Synonym created. Grant succeeded. Package created. no rows selected Package body created. no rows selected Synonym created. Grant succeeded. Package created. no rows selected Package body created. no rows selected Grant succeeded. Synonym created. Package created. no rows selected Package body created. no rows selected Synonym created. Grant succeeded. PL/SQL procedure successfully completed. Connected. DROP DIRECTORY SS_OE_XMLDIR * ERROR at line 1: ORA-04043: object SS_OE_XMLDIR does not exist Directory created. Commit complete. Connected. Revoke succeeded. Connected. Connected. Session altered. PL/SQL procedure successfully completed. PL/SQL procedure successfully completed. PL/SQL procedure successfully completed. Call completed. Call completed. PL/SQL procedure successfully completed. Connected. Revoke succeeded. Connected. Connected. Revoke succeeded. Revoke succeeded. Revoke succeeded. Package dropped. Package dropped. Package dropped. Package dropped. Package dropped. Trigger dropped. View dropped. Connected. Session altered. ...creating subschema OC in OE Type created. Type created. Type created. Type created. Type created. Type created. Type created. Type created. Type created. Warning: Type created with compilation errors. Type created. Type created. Type created. Warning: Type created with compilation errors. Type created. Type body created. Type created. Type body created. Type created. Type body created. Table created. FROM inventories i, warehouses w * ERROR at line 6: ORA-00942: table or view does not exist FROM product_information p * ERROR at line 10: ORA-00942: table or view does not exist FROM customers c * ERROR at line 20: ORA-00942: table or view does not exist FROM customers c * ERROR at line 20: ORA-00942: table or view does not exist FROM customers c * ERROR at line 20: ORA-00942: table or view does not exist FROM orders o * ERROR at line 9: ORA-00942: table or view does not exist ON oc_orders FOR EACH ROW * ERROR at line 2: ORA-00942: table or view does not exist TABLE order_item_list OF oc_orders FOR EACH ROW * ERROR at line 2: ORA-00942: table or view does not exist Commit complete. FROM oc_product_information o * ERROR at line 4: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 4: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 4: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 4: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 5: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 4: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 5: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 5: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 4: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 4: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 4: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 4: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 4: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 4: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 4: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 5: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 4: ORA-00942: table or view does not exist FROM oc_product_information o * ERROR at line 4: ORA-00942: table or view does not exist 1 row created. 1 row created. 1 row created. 1 row created. Type altered. 3 rows updated. 0 rows updated. 0 rows updated. 0 rows updated. Commit complete. Type body altered. Type body altered. Type body altered. GRANT SELECT ON bombay_inventory TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON customers TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON inventories TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON orders TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON order_items TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON products TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON product_descriptions TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON product_information TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON product_prices TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON promotions TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON sydney_inventory TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON toronto_inventory TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON warehouses TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT REFERENCES, SELECT ON product_information TO pm * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON order_items TO pm * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON orders TO pm * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON product_descriptions TO pm * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON inventories TO pm * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON customers TO pm * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON warehouses TO pm * ERROR at line 1: ORA-00942: table or view does not exist Creating dimensions, materialized views, external table and object privileges for SH ... TO_CHAR(SYSTIMEST ----------------- 20190725 04:01:14 1 row selected. Connected. CREATE DIMENSION customers_dim * ERROR at line 1: ORA-00942: table or view does not exist Commit complete. BEGIN dbms_olap.validate_dimension('customers_dim','sh',false,true); END; * ERROR at line 1: ORA-20000: cannot find the dimension ORA-06512: at "SYS.DBMS_DIMENSION", line 413 ORA-06512: at "SYS.DBMS_DIMENSION", line 435 ORA-06512: at "SYS.DBMS_SUMMARY", line 54 ORA-06512: at line 1 no rows selected CREATE DIMENSION products_dim * ERROR at line 1: ORA-00942: table or view does not exist BEGIN dbms_olap.validate_dimension('products_dim','sh',false,true); END; * ERROR at line 1: ORA-20000: cannot find the dimension ORA-06512: at "SYS.DBMS_DIMENSION", line 413 ORA-06512: at "SYS.DBMS_DIMENSION", line 435 ORA-06512: at "SYS.DBMS_SUMMARY", line 54 ORA-06512: at line 1 no rows selected CREATE DIMENSION times_dim * ERROR at line 1: ORA-00942: table or view does not exist BEGIN dbms_olap.validate_dimension('times_dim','sh',false,true); END; * ERROR at line 1: ORA-20000: cannot find the dimension ORA-06512: at "SYS.DBMS_DIMENSION", line 413 ORA-06512: at "SYS.DBMS_DIMENSION", line 435 ORA-06512: at "SYS.DBMS_SUMMARY", line 54 ORA-06512: at line 1 no rows selected CREATE DIMENSION channels_dim * ERROR at line 1: ORA-00942: table or view does not exist BEGIN dbms_olap.validate_dimension('channels_dim','sh',false,true); END; * ERROR at line 1: ORA-20000: cannot find the dimension ORA-06512: at "SYS.DBMS_DIMENSION", line 413 ORA-06512: at "SYS.DBMS_DIMENSION", line 435 ORA-06512: at "SYS.DBMS_SUMMARY", line 54 ORA-06512: at line 1 no rows selected CREATE DIMENSION promotions_dim * ERROR at line 1: ORA-00942: table or view does not exist BEGIN dbms_olap.validate_dimension('promotions_dim','sh',false,true); END; * ERROR at line 1: ORA-20000: cannot find the dimension ORA-06512: at "SYS.DBMS_DIMENSION", line 413 ORA-06512: at "SYS.DBMS_DIMENSION", line 435 ORA-06512: at "SYS.DBMS_SUMMARY", line 54 ORA-06512: at line 1 no rows selected TO_CHAR(SYSTIMEST ----------------- 20190725 04:01:14 1 row selected. FROM costs c, sales s * ERROR at line 13: ORA-00942: table or view does not exist , times t * ERROR at line 8: ORA-00942: table or view does not exist , products p * ERROR at line 12: ORA-00942: table or view does not exist Table created. Creating OLAP metadata ... <<<<< CREATE CWMLite Metadata for the Sales History Schema >>>>> - <<<<< CREATE CATALOG sh_cat for Sales History >>>>> No catalog to drop CWM Collect Garbage - <<<<< CREATE the Sales CUBE >>>>> Sales amount, Sales quantity <TIMES CHANNELS PRODUCTS CUSTOMERS PROMOTIONS > Drop SALES_CUBE prior to recreation No cube to drop Add dimensions - to SALES_CUBE and map the foreign keys ERROR:: dimension_not_found Object Type: DIMENSION Object Owner: SH Object Name: TIMES_DIM Secondary Name: Tertiary Name: User-Defined Exception ERROR: dimension_not_found declare * ERROR at line 1: ORA-06510: PL/SQL: unhandled user-defined exception ORA-06512: at "OLAPSYS.CWM$OLAP$DIMENSION", line 242 ORA-06510: PL/SQL: unhandled user-defined exception ORA-06512: at "OLAPSYS.CWM$UTIL", line 368 ORA-01403: no data found ORA-06512: at line 1691 Commit complete. GRANT SELECT ON channels TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON countries TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON times TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON costs TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON customers TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON products TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON promotions TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON sales TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON times TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON cal_month_sales_mv TO bi * ERROR at line 1: ORA-00942: table or view does not exist GRANT SELECT ON sh.fweek_pscat_sales_mv TO bi * ERROR at line 1: ORA-00942: table or view does not exist Creating views, synonyms for BI ... TO_CHAR(SYSTIMEST ----------------- 20190725 04:01:15 1 row selected. specify password for BI as parameter 1: Connected. Synonym created. Synonym created. Synonym created. Synonym created. Synonym created. Synonym created. Synonym created. Synonym created. Commit complete. Connected. PL/SQL procedure successfully completed. Connected. BEGIN dbms_aqadm_sys.validate_Queue('IX', 'AQ$_ORDERS_QUEUETABLE_E'); END; * ERROR at line 1: ORA-24010: QUEUE IX.AQ$_ORDERS_QUEUETABLE_E does not exist ORA-06512: at "SYS.DBMS_AQADM_SYSCALLS", line 312 ORA-06512: at "SYS.DBMS_AQADM_SYS", line 11383 ORA-06512: at line 1 BEGIN dbms_aqadm_sys.validate_Queue('IX', 'AQ$_STREAMS_QUEUE_TABLE_E'); END; * ERROR at line 1: ORA-24010: QUEUE IX.AQ$_STREAMS_QUEUE_TABLE_E does not exist ORA-06512: at "SYS.DBMS_AQADM_SYSCALLS", line 312 ORA-06512: at "SYS.DBMS_AQADM_SYS", line 11383 ORA-06512: at line 1 BEGIN dbms_aqadm_sys.validate_Queue('IX', 'ORDERS_QUEUE'); END; * ERROR at line 1: ORA-24010: QUEUE IX.ORDERS_QUEUE does not exist ORA-06512: at "SYS.DBMS_AQADM_SYSCALLS", line 312 ORA-06512: at "SYS.DBMS_AQADM_SYS", line 11383 ORA-06512: at line 1 BEGIN dbms_aqadm_sys.validate_Queue('IX', 'STREAMS_QUEUE'); END; * ERROR at line 1: ORA-24010: QUEUE IX.STREAMS_QUEUE does not exist ORA-06512: at "SYS.DBMS_AQADM_SYSCALLS", line 312 ORA-06512: at "SYS.DBMS_AQADM_SYS", line 11383 ORA-06512: at line 1 Directory dropped. Directory dropped. mkplug.sql DONE TO_CHAR(SYSTIMEST ----------------- 20190725 04:01:16 1 row selected. SQL>

优秀的个人博客,低调大师

案例篇-HBase 实战之 MOB 使用指南

1. 背景 HBase 可以很方便的将图片、文本等文件以二进制的方式进行存储。虽然 HBase 一般可以处理从 1 字节到 10MB 大小的二进制对象,但是 HBase 通常对于读写路径的优化主要是针对小于 100KB 的值。当 HBase 处理数据为 100KB~10MB 时, 由于分裂(split)和压缩(compaction)会引起写的放大,从而会降低 HBase 性 能。所以在 HBase2.0+引入了 MOB 特性,这样保持了 HBase 的高性能、强一致 性和低开销。 若要启用 MOB 功能,需要在每个 RegionServer 进行配置,并在建表或者修改表 时对指定列族启用 MOB 特性。在 HBase 尝鲜版中启用 MOB 功能,需要由 admin 用户设置定期进程,以重新优化 MOB 数据的分布。 2. 启用和配置 R

优秀的个人博客,低调大师

SpringBoot开发案例之邮件多实例发送

前言 最近在做邮件发送的服务,正常来说 SpringBoot 整合mail还是很方便的,然而来了新的需求:A请求使用邮箱C发送,B请求使用邮箱D发送,也就是说我们需要配置两套发送服务。 单实例 首先我们来看下单个服务的配置: spring.mail.host=smtp.mxhichina.com spring.mail.username=admin@52itstyle.com spring.mail.password=123456 spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true spring.mail.properties.mail.smtp.starttls.required=true 其他的不用管,我们只需要在用到的时候注入以下即可: @Autowired private JavaMailSender mailSender;//执行者 如果大家对如何加载配置以及初始化感兴趣,可以了解下 spring-boot-autoconfigure 的原理。 多实例 由于 mail 并没有像数据库那样提供多数据源,这里只能我们自己手动获取了: /** * 创建发送器 */ public class MailUtil { public static JavaMailSenderImpl createMailSender(){ JavaMailSenderImpl sender = new JavaMailSenderImpl(); sender.setHost("smtp.mxhichina.com"); sender.setPort(25); sender.setUsername("admin@52itstyle.com"); sender.setPassword("123456"); sender.setDefaultEncoding("Utf-8"); Properties p = new Properties(); p.setProperty("mail.smtp.timeout",1000+""); p.setProperty("mail.smtp.auth","true"); sender.setJavaMailProperties(p); return sender; } } 这里,顺便说一个小功能,在发送邮件的时候,如何自定义显示发件人名称: MimeMessageHelper helper = new MimeMessageHelper(message, true); helper.setFrom("345849402@qq.com","爪哇笔记"); 最后我们在使用的时候,只需要根据不同的请求使用不同的 sender 就可以了。 项目源码 码云:https://gitee.com/52itstyle/spring-boot-mail

优秀的个人博客,低调大师

django创建项目案例1详细介绍方法01

django版本1.8.2pip install django==1.8.2设计介绍本示例完成“图书-英雄”信息的维护,需要存储两种数据:图书、英雄图书表结构设计:表名:BookInfo图书名称:btitle图书发布时间:bpub_date英雄表结构设计:表名:HeroInfo英雄姓名:hname英雄性别:hgender英雄简介:hcontent所属图书:hbook图书-英雄的关系为一对多数据库配置在settings.py文件中,通过DATABASES项进行数据库设置django支持的数据库包括:sqlite、mysql等主流数据库Django默认使用SQLite数据库 命令django-admin startproject test1进入test1目录,目录结构如下图: 目录说明manage.py:一个命令行工具,可以使你用多种方式对Django项目进行交互内层的目录:项目的真正的Python包_init _.py:一个空文件,它告诉Python这个目录应该被看做一个Python包settings.py:项目的配置urls.py:项目的URL声明wsgi.py:项目与WSGI兼容的Web服务器入口 创建应用在一个项目中可以创建一到多个应用,每个应用进行一种业务处理创建应用的命令:python manage.py startapp booktest应用的目录结构如下图 定义模型类models.py 有一个数据表,就有一个模型类与之对应打开models.py文件,定义模型类引入包from django.db import models模型类继承自models.Model类说明:不需要定义主键列,在生成时会自动添加,并且值为自动增长当输出对象时,会调用对象的str方法 代码如下: from django.db import models # Create your models here. class BookInfo(models.Model): btitle=models.CharField(max_length=20) bpub_date=models.DateTimeField() def __str__(self): return self.btitle.encode('utf-8') class HeroInfo(models.Model): hname=models.CharField(max_length=10) hgender=models.BooleanField() hcontent=models.CharField(max_length=1000) hbook=models.ForeignKey(BookInfo) def __str__(self): return self.hname.encode('utf-8') 然后 (python2) linux@ubuntu:~/桌面/project/test1$ python manage.py runserver 8080 生成数据表 激活模型:编辑settings.py文件,将booktest应用加入到installed_apps中 INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'booktest' ) 生成迁移文件:根据模型类生成sql语句 python manage.py makemigrations (python2) linux@ubuntu:~/桌面/project/test1$ python manage.py makemigrations Migrations for 'booktest': 0001_initial.py: - Create model BookInfo - Create model HeroInfo /home/linux/.virtualenvs/python2/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py:302: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal return name == ":memory:" or "mode=memory" in force_text(name) (python2) linux@ubuntu:~/桌面/project/test1$ ^C 迁移文件被生成到应用的migrations目录 执行迁移:执行sql语句生成数据表 python manage.py migrate (python2) linux@ubuntu:~/桌面/project/test1$ python manage.py migrate Operations to perform: Synchronize unmigrated apps: staticfiles, messages Apply all migrations: admin, contenttypes, sessions, auth, booktest Synchronizing apps without migrations: Creating tables... Running deferred SQL... Installing custom SQL... /home/linux/.virtualenvs/python2/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py:302: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal return name == ":memory:" or "mode=memory" in force_text(name) Running migrations: Rendering model states... DONE Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying booktest.0001_initial... OK Applying sessions.0001_initial... OK (python2) linux@ubuntu:~/桌面/project/test1$ 测试数据操作 进入python shell,进行简单的模型API练习 python manage.py shell 进入shell后提示如下: (python2) linux@ubuntu:~/桌面/project/test1$ python manage.py shell Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from booktest.models import * >>> b=BookInfo() >>> b.btitle='abc' >>> from datetime import datetime >>> b.bpub_date=datetime(year=1990,month=1,day=12) >>> b.save() /home/linux/.virtualenvs/python2/lib/python2.7/site-packages/django/db/models/fields/__init__.py:1474: RuntimeWarning: DateTimeField BookInfo.bpub_date received a naive datetime (1990-01-12 00:00:00) while time zone support is active. RuntimeWarning) # 查询所有图书信息: >>> BookInfo.objects.all() [<BookInfo: abc>] >>> b=BookInfo.objects.get(pk=1) >>> b.btitle='123' >>> b.save() >>> BookInfo.objects.all() [<BookInfo: 123>] # 删除 >>> b.delete() >>> BookInfo.objects.all() [] 按Ctrl+d退出shell 使用django的管理 创建一个管理员用户 python manage.py createsuperuser,按提示输入用户名、邮箱、密码 启动服务器,通过“127.0.0.1:8000/admin”访问,输入上面创建的用户名、密码完成登录 进入管理站点,默认可以对groups、users进行管理 (python2) linux@ubuntu:~/桌面/project/test1$ python manage.py createsuperuser Username (leave blank to use 'linux'): abc Email address: abc@163.com Password: 123 Password (again): 123 Superuser created successfully. /home/linux/.virtualenvs/python2/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py:302: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal return name == ":memory:" or "mode=memory" in force_text(name) (python2) linux@ubuntu:~/桌面/project/test1$ python manage.py runserver Performing system checks... System check identified no issues (0 silenced). July 17, 2018 - 09:50:32 Django version 1.8.2, using settings 'test1.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. 在浏览器浏览(http://127.0.0.1:8000/admin/login/?next=/admin/) 管理界面本地化 编辑settings.py文件,设置编码、时区 LANGUAGE_CODE = 'zh-Hans' # 'en-us' TIME_ZONE = 'Asia/Shanghai' # 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True 向admin注册booktest的模型 打开booktest/admin.py文件,注册模型 from django.contrib import admin from models import * # Register your models here. admin.site.register(BookInfo) admin.site.register(HeroInfo) 刷新管理页面,可以对BookInfo的数据进行增删改查操作 问题:如果在str方法中返回中文,在修改和添加时会报ascii的错误 解决:在str()方法中,将字符串末尾添加“.encode('utf-8')” 自定义管理页面 Django提供了admin.ModelAdmin类 通过定义ModelAdmin的子类,来定义模型在Admin界面的显示方式 class QuestionAdmin(admin.ModelAdmin): ... admin.site.register(Question, QuestionAdmin) 列表页属性 list_display:显示字段,可以点击列头进行排序 list_display = ['pk', 'btitle', 'bpub_date'] list_filter:过滤字段,过滤框会出现在右侧 list_filter = ['btitle'] search_fields:搜索字段,搜索框会出现在上侧 search_fields = ['btitle'] list_per_page:分页,分页框会出现在下侧 list_per_page = 10 添加、修改页属性 fields:属性的先后顺序 fields = ['bpub_date', 'btitle'] fieldsets:属性分组 fieldsets = [ ('basic',{'fields': ['btitle']}), ('more', {'fields': ['bpub_date']}), ] 修改admin.py from django.contrib import admin from models import * # Register your models here. class BookInfoAdmin(admin.ModelAdmin): list_display = ['id','btitle','bpub_date'] list_filter = ['btitle'] search_fields = ['btitle'] list_per_page = 1 fieldsets = [ ('base',{'fields':['btitle']}), ('super',{'fields':['bpub_date']}) ] admin.site.register(BookInfo,BookInfoAdmin) admin.site.register(HeroInfo) 效果图

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码