前面咱們已安裝好了python服務器運行所須要的相關軟件,而最重要最繁瑣的就是參數配置,寫這篇就踩了好多坑,花了好多時間,遇到了各類各樣的問題。好了費話少說,直接進入本篇話題。html
PS:本人不是專業的運維,不少linux服務器的問題都是隻知其一;不知其二,只能根據本身的研究弄弄單機版的python web服務器,而對於多服務器自動化同步的部署、服務器的監控、Linux服務器的安全、服務器的調優(不少服務安裝不是重點,能將各類參數運用配置到洽到好處纔是難點),你們最好找專業的運維工程師小戴同窗問問,問個人話我也不必定能回答的出來。再一次感謝小戴同窗的用心指導,讓我學會了不少服務器運維方面的知識,纔有這篇文章。(想學python與自動化運維的能夠上他的博客http://www.linuxyw.com/)node
目錄:python
1、優化服務器網絡環境linux
2、讓你的python代碼跑起來nginx
3、使用supervisord來管理python進程
4、將nginx與supervisord關聯起來(使用代理方式,非uwsgi)
5、使用nginx+supervisord+uwsgi來管理python web服務
6、使用svn來管理python的自動化發佈
7、postgresql配置
8、Redis配置
9、設置各服務開機啓動功能web
1、優化服務器網絡環境redis
在開始配置服務器前,咱們須要先對服務器環境配置進行優化,提高服務器的訪問數和處理數sql
輸入命令:vi /etc/sysctl.conf數據庫
將裏面值替換爲下面參數windows
# sysctl settings are defined through files in # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/. # # Vendors settings live in /usr/lib/sysctl.d/. # To override a whole file, create a new file with the same in # /etc/sysctl.d/ and put new settings there. To override # only specific settings, add a file with a lexically later # name in /etc/sysctl.d/ and put new settings there. # # For more information, see sysctl.conf(5) and sysctl.d(5). net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1 vm.swappiness = 0 net.ipv4.neigh.default.gc_stale_time=120 # see details in https://help.aliyun.com/knowledge_detail/39428.html net.ipv4.conf.all.rp_filter=0 # net.ipv4.conf.default.rp_filter=0 net.ipv4.conf.default.arp_announce = 2 net.ipv4.conf.lo.arp_announce=2 net.ipv4.conf.all.arp_announce=2 # see details in https://help.aliyun.com/knowledge_detail/41334.html # net.ipv4.tcp_max_tw_buckets = 5000 # net.ipv4.tcp_syncookies = 1 # net.ipv4.tcp_max_syn_backlog = 1024 net.ipv4.tcp_synack_retries = 2 net.ipv4.ip_forward = 0 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0 kernel.core_uses_pid = 1 net.ipv4.tcp_syncookies = 1 kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 68719476736 kernel.shmall = 4294967296 net.ipv4.tcp_max_tw_buckets = 6000 net.ipv4.tcp_sack = 1 net.ipv4.tcp_window_scaling = 1 net.ipv4.tcp_rmem = 4096 87380 4194304 net.ipv4.tcp_wmem = 4096 16384 4194304 net.core.wmem_default = 8388608 net.core.rmem_default = 8388608 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.core.netdev_max_backlog = 262144 # net.core.somaxconn = 262144 net.core.somaxconn = 2048 net.ipv4.tcp_max_orphans = 3276800 net.ipv4.tcp_max_syn_backlog = 262144 net.ipv4.tcp_timestamps = 0 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_mem = 94500000 915000000 927000000 net.ipv4.tcp_fin_timeout = 1 net.ipv4.tcp_keepalive_time = 10 net.ipv4.tcp_keepalive_probes=5 net.ipv4.ip_local_port_range = 1024 65535
輸入命令讓配置生效:sysctl -p
輸入命令:echo "options sunrpc tcp_slot_table_entries=256" >> /etc/modprobe.d/sunrpc.conf
寫入配置:sysctl -w sunrpc.tcp_slot_table_entries=256
重啓服務器,再查看一下配置就能夠看到配置參數值已經改變了(有的服務器可能不存在這兩個文件,不運行問題也不大)
輸入命令:cat /proc/sys/sunrpc/tcp_slot_table_entries
輸入命令:cat /proc/sys/sunrpc/tcp_max_slot_table_entries
一個是256,一個是65536了
2、讓你的python代碼跑起來
既然咱們要配置的是python服務器,那首先咱們要作的第一步是,放上咱們的python代碼,看看可否運行並訪問
先上代碼,將下面代碼粘貼到記事本上並存儲爲main.py(這個文名能夠隨便起,我存儲的格式爲ANSI格式,即記事本默認的格式)
#!/usr/bin/evn python # coding=utf-8 from bottle import default_app, get, run from beaker.middleware import SessionMiddleware @get('/index/') def callback(): return 'Hello World!' if __name__ == '__main__': app_argv = SessionMiddleware(default_app()) run(app=app_argv, host='0.0.0.0', port=8088, debug=True, reloader=True) else: application = SessionMiddleware(default_app())
咱們爲了方便之後對服務器的管理,須要建立一個指定的文件夾(若是有掛載新硬盤的,能夠將這個文件夾綁定到該目錄),將日誌、數據庫、web站、後臺服務、svn等內容統一放到指定文件夾下面
首先在根目錄下建立一個data文件夾(後面的各類日誌、web站點等全都放在這裏統一管理,之後咱們要查找時就很方便了)
輸入命令:mkdir /data
建立python web存儲目錄:mkdir /data/www
建立測試目錄:mkdir /data/www/test
而後使用SSH的上傳工具,上傳剛剛建立好的main.py文件到www目錄下的test文件夾
後面的上傳用這個上傳工具處理(也能夠直接使用vi進行編輯)再也不截圖
而後咱們運行:python /data/www/test/main.py (或進入test目錄運行:python main.py)
運行後會顯示ImportError: No module named bottle錯誤,這是由於咱們的程序調用了bottle包,而咱們未安裝這個依賴包,須要安裝後程序才能正常運行,之後在使用python中碰到這種狀況,直接輸入pip install xxx便可
安裝bottle包:pip3 install bottle
安裝beaker包:pip3 install beaker
而後再次輸入:python main.py
就會發現python web服務運行起來了
而後關閉防火牆:systemctl stop firewalld (若是瀏覽器訪問不了,能夠運行這個命令來關閉防火牆)
打開瀏覽器輸入:http://192.168.0.128:8088/index/ 就能夠看到Hello World!了
爲了方便後面的測試,咱們按Ctrl+C,關閉剛纔python啓動的main.py服務
3、使用supervisord來管理python進程
supervisord默認配置文件存放路徑是/etc/目錄下面,安裝完成後配置文件是不存在的,須要使用命令生成或咱們本身放一個進去,咱們先配置一個簡單的不使用uwsgi的配置文件
文件名稱:supervisord.conf (我存儲的格式爲ANSI格式,即記事本默認的格式)
[unix_http_server] file=/tmp/supervisor.sock ; (the path to the socket file) [supervisord] logfile=/data/logs/supervisord/supervisord.log ; (main log file;default $CWD/supervisord.log) logfile_maxbytes=10MB ; (max main logfile bytes b4 rotation;default 50MB) logfile_backups=2 ; (num of main logfile rotation backups;default 10) loglevel=info ; (log level;default info; others: debug,warn,trace) pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid) nodaemon=false ; (start in foreground if true;default false) minfds=1024 ; (min. avail startup file descriptors;default 1024) minprocs=200 ; (min. avail process descriptors;default 200) [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket [program:test] command=python /data/www/test/main.py ; supervisord將要執行的運行python服務的命令 directory=/data/www/test stdout_logfile=/data/logs/supervisord/test_supervisord.log ; supervisord當前這個test服務運行產生的日誌存儲路徑,方便咱們查看運行狀況 socket-timeout=3 autostart=true autorestart=true redirect_stderr=true stopsignal=QUIT
使用上傳工具上傳到/etc/supervisord.conf
爲了規範日誌管理,咱們在data文件夾下繼續建立對應的日誌文件夾,之後查找supervisord日誌就能夠在下面建立的文件夾中查看了
輸入命令:mkdir /data/logs
輸入命令:mkdir /data/logs/supervisord
因爲supervisord目前只支持python2,因此運行時須要用python2來啓動
啓動supervisord服務:/usr/bin/python2.7 /usr/bin/supervisord
咱們繼續在瀏覽器中輸入http://192.168.0.128:8088/index/ 能夠發現仍是能夠正常訪問,看到Hello World!(前面執行python /data/www/test/main.py後,按Ctrl+C就直接退出了,用瀏覽器是沒法正常訪問的,如今的訪問是supervisord啓動的)
使用supervisord啓動的python進程能夠發現,咱們用kill xxx命令來直接關閉python進程,關閉後supervisord會從新啓動新的進程,也就是說不kill掉supervisord進程,是沒法殺死supervisord啓動的python進程的
PS:因爲python2.7.5與python3.5.4並存,在對supervisord配置進行修改之後,使用命令:/usr/bin/supervisord -v執行時,會出現 ImportError: No module named 'supervisor' 這個錯誤,雖然咱們前面用的是python2.7.5來啓動supervisord服務的,但生成執行命令時,默認仍是用python這個連接,因此咱們須要對/usr/bin/supervisord和/usr/bin/supervisorctl進行修改
執行命令:vi /usr/bin/supervisord
將第一行的#!/usr/bin/python 改成 #!/usr/bin/python2.7.5
執行命令:vi /usr/bin/supervisorctl
將第一行的#!/usr/bin/python 改成 #!/usr/bin/python2.7.5
咱們再執行:/usr/bin/supervisord -v時就正常了
4、將nginx與supervisord關聯起來(使用代理方式,非uwsgi)
首先咱們要爲nginx建立對應的訪問帳號
輸入命令:/usr/sbin/groupadd -f www
輸入命令:/usr/sbin/useradd -g www www
爲nginx建立對應的日誌管理文件夾
輸入命令:mkdir /data/logs/nginx
由於nginx的配置默認所有是在nginx.conf裏設置的,網站多時管理不方便,因此咱們須要建立一個文件夾,將每一個獨立的網站配置放在裏面
建立nginx配置統一管理文件夾:mkdir /usr/local/nginx/conf/vhost
修改/usr/local/nginx/conf/nginx.conf配置文件內容,替換成下面參數
user www www; worker_processes 1; worker_rlimit_nofile 10240; error_log /data/logs/nginx/error.log error; events { use epoll; worker_connections 10240; } http { log_format main '[$time_local] $remote_addr $upstream_addr $status $body_bytes_sent [$request_time] ' '"$request" "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; include mime.types; default_type application/octet-stream; sendfile on; tcp_nopush on; tcp_nodelay on; server_tokens off; include vhost/*.conf; }
建立test.conf文件(內容見下面代碼)並上傳到剛建立的/usr/local/nginx/conf/vhost/目錄下,具體內容以下(使用80端口訪問,將代理地址指定前面配置的8088端口):
server { listen 80; charset utf-8; root /data/www/test; server_name 192.168.0.128; location / { proxy_pass http://127.0.0.1:8088; } access_log /data/logs/nginx/test_access.log main; }
PS:在使用以前,咱們須要從新一次服務器,否則可能會出現端口被佔用訪問出現404的問題,重啓後就正常
啓動nginx服務: /usr/local/nginx/sbin/nginx
啓動supervisord服務:/usr/bin/python2.7 /usr/bin/supervisord
若是修改了nginx配置內容,須要從新啓動nginx才能生效,重啓命令: /usr/local/nginx/sbin/nginx
若是啓動後沒有出現錯誤信息,就表示啓動成功了,可使用命令來查詢啓動狀況:ps -ef | grep nginx
咱們在瀏覽器中輸入http://192.168.0.128/index/能夠發現Hello World!訪問正常(PS:能夠發現,咱們直接訪問80端口徹底沒有問題)
5、使用nginx+supervisord+uwsgi來管理python web服務
首先,咱們讓uwsgi運行起來
根據官網(https://uwsgi-docs.readthedocs.io/en/latest/)說明,咱們還須要安裝python-devel插件
輸入命令:yum install python-devel
第一個Hello World!例子:
輸入命令:vi /tmp/foobar.py
而後點擊鍵盤 i 進入編輯模式,將下面的代碼粘貼進vi編輯器,而後按Esc鍵,按Shift+:,輸入wq+回車鍵,保存foobar.py文件
def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello World"]
將這個例子運行起來:/usr/bin/uwsgi --http :9090 --wsgi-file /tmp/foobar.py
咱們在瀏覽器中輸入網址:http://192.168.0.128:9090/ 就能夠看到Hello World了
咱們按Ctrl+C,關閉剛纔用uwsgi啓動的main.py服務
爲了方便uwsgi配置的管理,咱們須要在etc目錄下建立uwsgi文件夾,用來存儲配置文件
輸入命令:mkdir /etc/uwsgi
建立uwsgi日誌文件夾:mkdir /data/logs/uwsgi
建立配置文件,並將它上傳到/etc/uwsgi目錄下,配置文件名:test.xml,內容以下:
<uwsgi> <plugins>python35</plugins> <socket>127.0.0.1:8088</socket> <chdir>/data/www/test</chdir> <listen>2048</listen> <limit-as>512</limit-as> <reload-on-as>128</reload-on-as> <reload-on-rss>96</reload-on-rss> <processes>8</processes> <max-requests>2000</max-requests> <socket-timeout>6</socket-timeout> <harakiri>6</harakiri> <idle>20</idle> <pythonpath>/data/www/test</pythonpath> <logto>/data/logs/uwsgi/test_uwsgi.log</logto> <master/> <reaper/> <no-orphans/> <vacuum/> <disable-logging/> </uwsgi>
修改/etc/supervisord.conf配置文件內容,將command=python /data/www/test/main.py修改成command=/usr/local/bin/uwsgi /etc/uwsgi/test.xml
[unix_http_server] file=/tmp/supervisor.sock ; (the path to the socket file) [supervisord] logfile=/data/logs/supervisord/supervisord.log ; (main log file;default $CWD/supervisord.log) logfile_maxbytes=10MB ; (max main logfile bytes b4 rotation;default 50MB) logfile_backups=2 ; (num of main logfile rotation backups;default 10) loglevel=info ; (log level;default info; others: debug,warn,trace) pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid) nodaemon=false ; (start in foreground if true;default false) minfds=1024 ; (min. avail startup file descriptors;default 1024) minprocs=200 ; (min. avail process descriptors;default 200) [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket [program:test] command=/usr/bin/uwsgi /etc/uwsgi/test.xml directory=/data/www/test stdout_logfile=/data/logs/supervisord/test_supervisord.log socket-timeout=3 autostart=true autorestart=true redirect_stderr=true stopsignal=QUIT
修改nginx的配置文件/usr/local/nginx/conf/vhost/test.conf
server { listen 80; charset utf-8; root /data/www/test; server_name 192.168.0.128; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 2; proxy_send_timeout 60; proxy_read_timeout 60; include uwsgi_params; uwsgi_param UWSGI_PYHOME /data/www/test; uwsgi_param UWSGI_CHDIR /data/www/test; uwsgi_param UWSGI_SCRIPT main; uwsgi_pass 127.0.0.1:8088; } access_log /data/logs/nginx/test_access.log main; }
重啓服務命令:/usr/local/nginx/sbin/nginx -s reload(若是nginx服務沒有啓動,就使用這個命令:/usr/local/nginx/sbin/nginx )
另外,若是咱們修改了supervisord的配置文件,則須要運行下面命令重啓服務(若是你又重啓了服務器,則須要從新啓動supervisord服務:/usr/bin/python2.7 /usr/bin/supervisord,不然不用執行這個命令)
載入剛剛修改過的配置信息:/usr/bin/supervisorctl reread (運行後才能夠載入內存)
重啓所有supervisord服務:/usr/bin/supervisorctl reload (運行這個將會重啓所有服務,會比較慢)
PS:其餘supervisord命令說明
啓動或重啓配置修改項對應的服務:/usr/bin/supervisorctl update (有時可能會啓動失敗,須要須要其餘方式啓動)
咱們更新了python文件,若是沒有重啓對應的服務修改是不生效的,即訪問時仍是舊的代碼功能,須要重啓對應的服務才行,好比如今咱們的supervisord服務名稱叫作test,那麼可使用下面命令來重啓對應的uwsgi服務
重啓test的uwsgi服務:/usr/bin/supervisorctl restart test (啓動服務命令:/usr/bin/supervisorctl start test)
咱們在瀏覽器中輸入網址:http://192.168.0.128/index/ 就能夠看到使用nginx+supervisord+uwsgi+python(bottle框架)運行的Hello World了
----------------------------------------2017-3-30 16:06修改更新---------------------------------------------------
ps:以前使用/usr/bin/supervisorctl update重啓supervisord,可能瀏覽器訪問時出現502 Bad Gateway,這時咱們須要查看supervisord和uwsgi日誌,看看日誌裏有什麼錯誤提示。通常會有下面日誌:
日誌路徑能夠查看前面/etc/supervisord.conf 和 /etc/uwsgi/test.xml 配置文件裏設置的路徑,若是是nginx的日誌則查看 /usr/local/nginx/conf/vhost/ 下面各個conf配置文件裏設置的路徑,用cat命令就能夠查看到日誌內容了,若是日誌內容很是多,可使用tail -f xxx.log命令來實時查看。
*** Starting uWSGI 2.0.14 (64bit) on [Thu Mar 30 03:44:31 2017] *** compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-11) on 29 March 2017 23:46:25 os: Linux-3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 nodename: localhost.localdomain machine: x86_64 clock source: unix pcre jit disabled detected number of CPU cores: 16 current working directory: /data/www/test detected binary path: /usr/local/bin/uwsgi uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** chdir() to /data/www/test/ your processes number limit is 62479 limiting address space of processes... your process address space limit is 536870912 bytes (512 MB) your memory page size is 4096 bytes detected max file descriptor number: 1024 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) probably another instance of uWSGI is running on the same address (127.0.0.1:8088). bind(): Address already in use [core/socket.c line 769]
咱們能夠輸入命令:ps -ef | grep uwsgi,查看一下uwsgi有沒有運行,若是沒有運行的話,可執行:/usr/bin/supervisorctl reload,再使用ps命令檢查一下uwsgi啓動了沒有,啓動了就表示正常了
6、使用svn來管理python的自動化發佈
建立svn管理目錄:mkdir /data/svn
進入svn管理目錄:cd /data/svn
建立svn項:svnadmin create test
修改/data/svn/test/conf文件夾下的配置文件
能夠將這三個文件下載下來進行修改,也能夠用vi進行編輯
將authz文件替換成下面內容:
[test:/]
admin = rw
allempty = rw
test是svn當前倉庫項的模塊名稱,每一個svn的這個名稱都是惟一的,否則可能沒法登陸使用
添加添加了兩個帳號,admin用於服務器端自動同步svn的代碼到對應的web或服務使用,和我的帳號區別出來,方便管理和保護帳號安全,而allempty是我本身添加用於svn更新最新代碼的帳號
將password文件替換成下面內容:
[users] admin = 123456 allempty = 123456
這裏設置帳號對應的密碼
將svnserve.conf文件替換成下面內容:
[general] anon-access = none auth-access = write password-db = passwd authz-db = authz
在/data/svn/test/hooks/目錄下建立post-commit勾子文件(post-commit文件沒有擴展名),用於svn更新成功之後,自動同步到對應的代碼目錄
#!/bin/sh export LANG=en_US.UTF-8 /usr/bin/svn up /data/www/test /usr/bin/supervisorctl restart test
/usr/bin/svn up /data/www/test 這個命令是運行更新指令,本地代碼經過svn更新到服務器之後,勾子會運行它來同步到指定的/data/www/test目錄
/usr/bin/supervisorctl restart test 由於咱們用的是supervisord來管理python web服務的,代碼更新完成之後並未生效,須要從新服務才行,這個命令是用來重啓指定的supervisord進程的,它們幫咱們將對應的uwsgi進程進行重啓操做
運行命令,將給予勾子post-commit可執行權限:chmod +x /data/svn/test/hooks/post-commit
啓動svn服務:/usr/bin/svnserve -d -r /data/svn
配置test項目服務器端svn同步設置
輸入命令:svn checkout svn://localhost/test /data/www/test (在服務器端對test項進行svn檢出操做)
PS:出現Password for 'root': 直接回車就能夠了,Username:輸入前面authz裏設置的帳戶名稱,Password for 'admin': 輸入對應的密碼
操做到這裏,svn的自動化發佈就完成了,咱們只須要在本地檢出svn項,而後更新代碼後,服務器端就會自動將代碼同步到/data/www/test目錄下面,並重啓對應的supervisord服務了
本地操做截圖:(能夠下載TortoiseSVN-1.9.4.27285-x64-svn-1.9.4.msi進行使用)
7、postgresql配置
在data下建立pg文件夾,用於放置pg相關的全部東西
輸入命令:mkdir /data/pg
在pg文件夾下咱們再建立存放數據庫的文件夾
輸入命令:mkdir /data/pg/data
爲新建立的pg文件夾分配數據庫服務的操做權限
輸入命令:chown postgres:postgres /data/pg
爲存放數據庫的文件夾分配權限
輸入命令:chown postgres:postgres /data/pg/data
設置postgresql相關環境變量
修改profile文件
輸入命令:vi /etc/profile
在尾部添加下面代碼:
PGDATA=/data/pg/data PGHOST=127.0.0.1 PGDATABASE=postgres PGUSER=postgres PGPORT=5432 PATH=/usr/pgsql-9.6/bin:$PATH export PATH export PGDATA PGHOST PGDATABASE PGUSER PGPORT export TMOUT=1000
重啓一下虛擬機(reboot)或者輸入命令: source /etc/profile從新載入配置,而後輸入命令:export 就能夠看到剛纔添加的變量了
初始化postgresql數據庫:
使用postgres登陸:su postgres
而後執行初始化數據庫命令,並指定數據庫存儲路徑:initdb -D /data/pg/data
退出postgres用戶,使用原root帳號登陸,可輸入命令:su root,而後輸入密碼就能夠切換回去
咱們再次進入/data/pg/data路徑,就能夠看到多了不少數據庫文件夾和配置文件了
打開/data/pg/data/pg_hba.conf配置文件,找到# IPv4 local connections: 在它的下面添加一行host all all 0.0.0.0/0 md5
添加之後,咱們連接數據庫都必需要用輸入密碼
打開/data/pg/data/postgresql.conf配置文件
找到#listen_addresses = 'localhost',將前面的#刪掉,參數localhost表示只容許當前服務器能連接數據庫,若是想指定地址能夠訪問,能夠輸入ip地址,多個地址時用逗號分隔,若是開放全部地址能夠訪問,由使用*
找到#port = 5432,將前面的#刪掉,這裏能夠指定訪問數據庫的端口
啓動postgresql數據庫:su postgres -c "/usr/pgsql-9.6/bin/pg_ctl start -D /data/pg/data"
使用postgres用戶登陸:su postgres
鏈接數據庫:psql -U postgres
修改postgres用戶密碼:Alter user postgres with password '123456';
退出數據庫鏈接:\q
咱們能夠在本地的windows系統裏安裝postgresql9.6(官方下載地址:https://www.postgresql.org/download/windows/),而後使用pgAdmin4鏈接上服務器的數據庫,用圖形界面來管理數據庫了
八、Redis配置
redis以前安裝沒有指定安裝路徑,從新作了修改,你們能夠查看http://www.cnblogs.com/EmptyFS/p/6558800.html 檢查安裝
修改redis配置信息(能夠下載/usr/local/redis/redis.conf或直接用vi /usr/local/redis/redis.conf進行編輯)
主要修改內容有:
bind 127.0.0.1 redis服務訪問限制設置。使用127.0.0.1表示只能本機訪問;若是用的是服務器在局域網裏的ip:192.168.1.128,即表示局域網內的ip均可以訪問;若是使用0.0.0.0由表示全部地址均可以訪問。須要綁定多個時,能夠添加多個bind xxx.xxx.xxx.xxx
daemonize no 這個修改成daemonize yes 開啓守護進程
dir ./ 這裏須要修改成dir /usr/local/redis/data 否則redis數據會存儲到root文件夾下面
隨便找個位置增長requirepass xxxxx,能夠增長訪問redis訪問密碼,若是你的redis對外網開放,這個密碼同樣要足夠長足夠複製,否則以redis的訪問速度,比較容易被人破解
能夠增長maxmemory 1024M來限制redis佔用內容大小,也能夠不限制
修改完成後,建立redis數據存儲文件夾:mkdir /usr/local/redis/data
修改完成,運行redis啓動命令:/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
redis服務就啓動了,可使用RedisDesktopManager這種第三方可視化工具來訪問redis,查看裏面的存儲數據
9、設置各服務開機啓動功能
以上衆多的服務,有的朋友喜歡將它們設置成service方式自動啓動,也有喜歡用命令方式來啓動它們,爲了操做簡單,咱們將它們都統一設置爲命令啓動方式。
輸入命令: vi /etc/rc.local ,在內容後面添加下面命令項,而後保存退出
ulimit -SHn 102400 /usr/bin/python2.7 /usr/bin/supervisord /usr/local/nginx/sbin/nginx /usr/bin/svnserve -d -r /data/svn su postgres -c "/usr/pgsql-9.6/bin/pg_ctl start -D /data/pg/data" /usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
給予rc.local可執行權限:chmod +x /etc/rc.d/rc.local
而後重啓服務器,咱們使用ps -ef就能夠查看到各服務正在運行中了
版權聲明:
本文由AllEmpty原創併發佈於博客園,版權與博客園共同全部,歡迎轉載,未經本人贊成必須保留此段聲明,且在文章頁面明顯位置給出原文連接,不然保留追究法律責任的權利。若有問題,能夠經過1654937@qq.com 聯繫我,很是感謝。
發表本編內容,主要是爲了和你們共同窗習共同進步,有興趣的朋友能夠加加Q羣:669058475(本羣已滿)、733466321(能夠加2羣),你們一塊兒探討。
更多內容,敬請觀注博客:http://www.cnblogs.com/EmptyFS/