笔记(一)
笔记 (一)
笔记 (一)
一、系统环境搭建
(一)开发测试的平台环境
- ubantu 18.04 desktop
- python 3.6
- django
- scrapy
- redis
- mongodb
- oracle-jdk-8
- mysql
- docker oracle databases 12.2
(二)ubuntu-18.04.2-desktop-amd64
下载页面
中国官网
(三)ubantu 18.04 网络配置
Desktop下有一个Network-manager的软件,这个软件如果上面设置了,那么默认会以上面的配置为准,Network-manager会失效,但是这个设置只有在重启电脑才会生效。
sudo service network-manager stop
(1)第一种 快速方法,临时使用
如果不重启时,那么需要停止这个服务再去设置
这种方式重启后会失效。
1、先停止Network-manager的服务
sudo service network-manager stop
2、设置IP和子网掩码
sudo ifconfig eth0 192.100.100.197 netmask 255.255.255.0
3、设置网关
sudo route add default gw 192.100.100.99
4、设置DNS
sudo su
echo "nameserver 192.168.199.1" >> /etc/resolv.conf
完成后,输入exit退出,上面的只是是即时生效的。但重启后会失效,持久方式使用第二种方法。
(2)第二种 永久方法
对于Ubuntu和CentOS 6配置都适用。
1、修改IP地址
打开/etc/network/interfaces
sudo vim /etc/network/interfaces
加入以下语句:
auto eth0 #要设置的网卡
iface eth0 inet static #设置静态IP;如果是使用自动IP用dhcp,后面的不用设置,一般少用
address 192.168.24.5 #IP地址
netmaskxxx.xxx.xxx.xxx #子网掩码
gatewayxxx.xxx.xxx.xxx #网关
auto eth0
iface eth0 inet static
address 192.168.24.3
netmask 255.255.255.240
gateway 192.168.24.1
sudo service networking restart
2、修改DNS
打开/etc/resolv.conf
sudo vim /etc/resolv.conf
注意:上面设置的文件重启后会覆盖,如果要持久的保存,需要修改:sudo vim /etc/resolvconf/resolv.conf.d/base
改为如下内容:
sudo vim /etc/resolvconf/resolv.conf.d/base
search localdomain #如果本Server为DNS服务器,可以加上这一句,如果不是,可以不加
nameserver 114.114.114.114
nameserver 222.246.129.81
(3)ssh service安装和lrzsz小工具
- ssh service安装
sudo apt-get install openssh-server
- lrzsz 文件传输
sudo apt install lrzsz
sz:将选定的文件发送(send)到本地机器
rz:运行该命令会弹出一个文件选择窗口,从本地选择文件上传到服务器(receive)
(四)ubantu 系统更新,python环境安装
(1)源更改
如果更新太慢可以使用国内源
a.备份源
cp /etc/apt/sources.list /etc/apt/sources.list.old
#系统原本文件 含有阿里源 #/etc/apt/sources.list deb http://cn.archive.ubuntu.com/ubuntu/ bionic main restricted deb http://cn.archive.ubuntu.com/ubuntu/ bionic-updates main restricted deb http://cn.archive.ubuntu.com/ubuntu/ bionic universe deb http://cn.archive.ubuntu.com/ubuntu/ bionic-updates universe deb http://cn.archive.ubuntu.com/ubuntu/ bionic multiverse deb http://cn.archive.ubuntu.com/ubuntu/ bionic-updates multiverse deb http://cn.archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse deb http://security.ubuntu.com/ubuntu bionic-security main restricted deb http://security.ubuntu.com/ubuntu bionic-security universe deb http://security.ubuntu.com/ubuntu bionic-security multiverse
b.更改源
#原文件修改全阿里的ubantu公司的源 #/etc/apt/sources.list deb http://cn.archive.ubuntu.com/ubuntu bionic main multiverse restricted universe deb http://cn.archive.ubuntu.com/ubuntu bionic-updates main multiverse restricted universe deb http://cn.archive.ubuntu.com/ubuntu bionic-security main multiverse restricted universe deb http://cn.archive.ubuntu.com/ubuntu bionic-proposed main multiverse restricted universe
c.或者
#或者使用阿里公司的源 #/etc/apt/sources.list deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
d.小知识:
#deb源格式: deb repos_path section1 section2
- 获取ubuntu 18.04的codename,根据Wiki可知ubuntu 18.04的代号为bionic
- deb后面跟着的其实有三大部分:deb repos_path section1 section2
- repos_path:源的路径,deb可支持http,ftp,以及本地文件cdrom等路径
- http://cn.archive.ubuntu.com/ubuntu/
- http://security.ubuntu.com/ubuntu
- http://mirrors.aliyun.com/ubuntu/
- 我们可以将bionic-*填入section1了,值得注意的是 一条deb源只能填入一个section1,如果想添加多个源就需要另一行重新书写新的deb源
- 根目录下,尤其是dists目录和pool目录里面找到多个bionic-*的目录名称,以版本代号开头
- 每个在bionic-* 的目录里面,可见有main/multiverse/restricted/universe几大属性包
- main/multiverse/restricted/universe 填入section2,可一个可多个
e.然后执行sudo apt-get update 或者 sudo apt -y update 即可完成ubuntu 18.04 源的修改
f.apt和apt-get命令之间的区别
虽然 apt 与 apt-get 有一些类似的命令选项,但它并不能完全向下兼容 apt-get 命令。也就是说,可以用 apt 替换部分 apt-get 系列命令,但不是全部。
apt 命令 |
取代的命令 |
命令的功能 |
apt install |
apt-get install |
安装软件包 |
apt remove |
apt-get remove |
移除软件包 |
apt purge |
apt-get purge |
移除软件包及配置文件 |
apt update |
apt-get update |
刷新存储库索引 |
apt upgrade |
apt-get upgrade |
升级所有可升级的软件包 |
apt autoremove |
apt-get autoremove |
自动删除不需要的包 |
apt full-upgrade |
apt-get dist-upgrade |
在升级软件包时自动处理依赖关系 |
apt search |
apt-cache search |
搜索应用程序 |
apt show |
apt-cache show |
显示安装细节 |
当然,apt 还有一些自己的命令:
新的apt命令 |
命令的功能 |
apt list |
列出包含条件的包(已安装,可升级等) |
apt edit-sources |
编辑源列表 |
(2)软件更新
# 软件更新 sudo apt -y update # 更新源,刷新存储库索引 sudo dpkg --configure -a # 配置包,--configure 源配置文件 ,-a configure的参数 sudo apt -y upgrade # 更新已安装的包 sudo apt -y dist-upgrade # 升级系统 # 注意以上安装过程中出现的安装选项,直接回车或者选择yes即可 sudo apt-get -y autoremove sudo apt -y autoclean
#如果安装出现 dpkg错误 sudo rm /var/lib/dpkg/updates/* sudo apt -y update # 更新源,刷新存储库索引 sudo dpkg --configure -a # 配置包,--configure 源配置文件 ,-a configure的参数 sudo apt -y upgrade # 更新已安装的包
(3)python2、python3、 redis、 mongodb、 virtualenv、 virtualenvwrapper软件安装
# 安装python2 sudo apt -y install python sudo mv /usr/bin/python /tmp sudo ln -s /usr/bin/python3 /usr/bin/python # 安装pip sudo apt install -y python3-pip sudo apt install -y python-pip # 安装虚拟环境对应的包 sudo pip3 install -i https://pypi.douban.com/simple virtualenv sudo pip3 install -i https://pypi.douban.com/simple virtualenvwrapper sudo pip2 install -i https://pypi.douban.com/simple virtualenvwrapper # 配置虚拟环境,在用户目录中建立虚拟编译器文件夹 envdir="$HOME/.virtualenvs" if [ ! -d "$envdir" ]; then mkdir "$envdir" else echo "$envdir 文件夹存在 is already exist !!!" fi grep -q "WORKON_HOME" ~/.bashrc if [ $? -ne 0 ]; then echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.bashrc echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc fi sh ~/.bashrc # 创建虚拟环境 . /usr/local/bin/virtualenvwrapper.sh mkvirtualenv -p /usr/bin/python3 py3env #创建python3虚拟环境并进入 mkvirtualenv -p /usr/bin/python2 envpy2 deactivate #退出虚拟环境 # 安装 Redis sudo apt -y install redis-server sudo sed -i 's/127.0.0.1/0.0.0.0/g' /etc/redis/redis.conf
二 安装mysql
1.建立mysqlconfig.py文件
mysqlconfig.py放$HOME目录,
# -*- coding:utf-8 -*- #文件名:mysqlconfig.py import pymysql conn = pymysql.connect( host='127.0.0.1', port=3306, user='root', passwd='qwe123', db='mysql')#连接 cursor = conn.cursor() #建立指针 try: cursor.execute("CREATE USER 'admin'@'%' IDENTIFIED BY 'Root110qwe'") #创建超级用户admin密码Root110qwe cursor.execute("GRANT ALL ON *.* TO 'admin'@'%'") #权限所有 cursor.execute("CREATE USER 'develop'@'%' IDENTIFIED BY 'QWEqwe123'") #开发用户develop 密码QWEqwe123 cursor.execute("GRANT SELECT,INSERT,UPDATE,DELETE ON *.* TO 'develop'@'%'") #权限增删改查 cursor.execute("FLUSH PRIVILEGES") #直接生效 conn.commit() #提交 except Exception as e: print(e) finally: cursor.close() #关闭指针 conn.close()#关闭连接 print('MySQL user add finish!!!')
2. b.sh脚本
由b.sh脚本执行一次即可
sudo dpkg -i mysql-apt-config_0.*.****_all.deb #选择mysql8.0 sudo apt-get update #命令2 #sudo apt-get install mysql-server #安装过程输入密码,选择mysql5.x加密方式 sudo apt install -y mysql-server #安装mysql sudo mysql_secure_installation $HOME/.virtualenvs/py3env/bin/pip install pymysql #安装python的管理引擎 $HOME/.virtualenvs/py3env/bin/python $HOME/mysqlconfig.py #建立mysql用户和创建密码 sudo /etc/init.d/mysql stop #停止mysql服务 sudo sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/mysql.conf.d/mysqld.cnf #更改服务器IP访问限制 grep -q 'default-character-set' /etc/mysql/mysql.conf.d/mysqld.cnf #字符编码集 if [ $? -ne 0 ]; then sudo sed -i "/nice/a\[client]\ndefault-character-set=utf8\n" /etc/mysql/mysql.conf.d/mysqld.cnf sudo sed -i "/server-key/a\character_set_server=utf8" /etc/mysql/mysql.conf.d/mysqld.cnf fi sudo /etc/init.d/mysql start #开启mysql服务 sudo /etc/init.d/mysql restart #重启mysql服务
3. b.sh 安装过程需要配置MySQL
在执行 sudo mysql_secure_installation时出现选择
配置项较多,如下所示:
#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (我的选项)
#2
Please set the password for root here...
New password: (输入密码)
Re-enter new password: (重复输入)
#3
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项)
#4
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y (我的选项)
#5
By default, MySQL comes with a database named 'test' that
anyone can access...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项)
#6
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的选项)
三 在Ubuntu 18.04中安装Oracle Java JDK 8:
1.首先之前先卸载open jdk
sudo apt-get purge openjdk*
Webupd8 Team维护一个PPA存储库,其中包含适用于所有当前Ubuntu版本的Oracle Java 8安装程序脚本。
2.打开终端并运行命令添加PPA:
sudo add-apt-repository ppa:webupd8team/java
输入密码(输入时不会显示星号),然后按Enter键继续。
3.然后运行命令安装Java 8安装程序并在提示时接受许可证:
sudo apt-get install oracle-java8-installer
安装完成后,Oracle Java 8应自动设置为默认值。 如果没有,运行命令:
sudo apt-get install oracle-java8-set-default
4.JDK环境配置
sudo vi /etc/profile
最后添加
#JAVA path export JAVA_HOME=/usr/lib/jvm/java-8-oracle/jre/bin/java export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$JAVA_HOME/bin:$PATH
更新当前终端配置
source /etc/profile
全局更新需要重启
四 docker容器
1.安装配置
#下载安装 sudo apt -get install docker.io #配置用户组 sudo usermod -aG docker $USER
2.下载镜像加速
打开 阿里云https://www.aliyun.com/ 登陆——>>控制台——>>产品与服务——>>容器镜像服务—— >>镜像加速器
加速器
使用加速器可以提升获取Docker官方镜像的速度
加速器地址 |
https://dfp0d5s9.mirror.aliyuncs.com |
您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://dfp0d5s9.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
3.常用命令
docker pull 下载镜像 docker run 启动容器 docker image ls 查看下载的镜像 docker ps 查看运行容器 docker image rm 删除镜像 docker rm 删除容器 docker exec -it
4.建立本项目docker
if [ ! -e "$HOME/oracledata" ];then mkdir $HOME/oracledata fi if [ ! -e "$HOME/docker" ];then mkdir $HOME/docker fi if [ ! -e "$HOME/docker/entrypoint.sh" ];then touch $HOME/docker/entrypoint.sh fi sudo tee $HOME/docker/Dockerfile <<-'EOF' FROM sath89/oracle-12c-base ### This image is a build from non automated image cause of no possibility of Oracle 12c instalation in Docker container ENV WEB_CONSOLE true ENV DBCA_TOTAL_MEMORY 2048 ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/u01/app/oracle/product/12.1.0/xe/bin ENV USE_UTF8_IF_CHARSET_EMPTY true ADD entrypoint.sh /entrypoint.sh RUN apt-get update && apt-get -y install curl && apt-get clean && rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/* EXPOSE 1521 EXPOSE 8080 VOLUME ["/docker-entrypoint-initdb.d"] ENTRYPOINT ["/entrypoint.sh"] CMD [""] EOF
cd $HOME/docker
docker build -t myoracle:v1 $HOME/docker
5.测试命令
docker run -d -p 8080:8080 -p 5500:5500 -p 1521:1521 -v /home/juejun/oracledata:/u01/app/oracle -e DBCA_TOTAL_MEMORY=1024 -e ORACLE_ALLOW_REMOTE=true --name oracle-base sath89/oracle-12c-base docker run -it -p 8080:8080 -p 5500:5500 -p 1521:1521 -v /home/juejun/oradata:/u01/app/oracle -e DBCA_TOTAL_MEMORY=1024 -e ORACLE_ALLOW_REMOTE=true --name oracle-base sath89/oracle-12c docker run -it -p 1234:22 -p 8080:8080 -p 5500:5500 -p 1521:1521 -v /home/juejun/oradata:/u01/app/oracle -e --name oracle-base sath89/oracle-12c 最终测试成功命令 docker pull sath89/oracle-12c docker run -d -p 1234:22 -p 8080:8080 -p 5500:5500 -p 1521:1521 -v /home/juejun/oradata:/u01/app/oracle --name oracl sath89/oracle-12c
6.oracle参数
Connect database with following setting:
hostname: localhost port: 1521 sid: xe service name: xe username: system password: oracle
To connect using sqlplus:
sqlplus system/oracle@//localhost:1521/xe
Password for SYS & SYSTEM:
oracle
Connect to Oracle Application Express web management console with following settings:
http://localhost:8080/apex workspace: INTERNAL user: ADMIN password: 0Racle$
Apex upgrade up to v 5.*
docker run -it --rm --volumes-from ${DB_CONTAINER_NAME} --link ${DB_CONTAINER_NAME}:oracle-database -e PASS=YourSYSPASS sath89/apex install
Details could be found here: https://github.com/MaksymBilenko/docker-oracle-apex
Connect to Oracle Enterprise Management console with following settings:
http://localhost:8080/em user: sys password: oracle connect as sysdba: true